Skip to content

Commit 4300da2

Browse files
solves #3065: Minimum Operations to Exceed Threshold Value I in java
1 parent 87a907e commit 4300da2

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# LeetCode Algorithms
22

33
![problems-solved](https://img.shields.io/badge/Problems%20Solved-682/2813-1f425f.svg)
4-
![problems-solved-java](https://img.shields.io/badge/Java-674/2813-1abc9c.svg)
5-
![problems-solved-python](https://img.shields.io/badge/Python-205/2813-1abc9c.svg)
6-
![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/2813-1abc9c.svg)
4+
![problems-solved-java](https://img.shields.io/badge/Java-752/3215-1abc9c.svg)
5+
![problems-solved-python](https://img.shields.io/badge/Python-204/3215-1abc9c.svg)
6+
![problems-solved-javascript](https://img.shields.io/badge/JavaScript-4/3215-1abc9c.svg)
77
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
88
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
99

@@ -894,7 +894,7 @@
894894
| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array) | [![Java](assets/java.png)](src/SplitTheArray.java) | |
895895
| 3062 | 🔒 [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game) | | |
896896
| 3063 | 🔒 [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency) | | |
897-
| 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | | |
897+
| 3065 | [Minimum Operations to Exceed Threshold Value I](https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i) | [![Java](assets/java.png)](src/MinimumOperationsToExceedThresholdValueI.java) | |
898898
| 3069 | [Distribute Elements Into Two Arrays I](https://leetcode.com/problems/distribute-elements-into-two-arrays-i) | | |
899899
| 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes) | | |
900900
| 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | | |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-i
2+
// T: O(N log(N))
3+
// S: O(log(N))
4+
5+
import java.util.Arrays;
6+
7+
public class MinimumOperationsToExceedThresholdValueI {
8+
public int minOperations(int[] array, int k) {
9+
Arrays.sort(array);
10+
return binarySearch(array, k);
11+
}
12+
13+
// binary search with left drag
14+
private static int binarySearch(int[] array, int element) {
15+
int left = 0, right = array.length - 1, middle;
16+
while (left <= right) {
17+
middle = left + (right - left) / 2;
18+
if (array[middle] == element) right = middle - 1;
19+
else if (array[middle] <= element) left = middle + 1;
20+
else right = middle - 1;
21+
}
22+
return left;
23+
}
24+
}

0 commit comments

Comments
 (0)