-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 2.9 MB (8…
…0.82%)
- Loading branch information
1 parent
063bd8c
commit 15d52b2
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
3331-minimum-operations-to-exceed-threshold-value-i/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> | ||
|
||
<p>In one operation, you can remove one occurrence of the smallest element of <code>nums</code>.</p> | ||
|
||
<p>Return <em>the <strong>minimum</strong> number of operations needed so that all elements of the array are greater than or equal to</em> <code>k</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [2,11,10,1,3], k = 10 | ||
<strong>Output:</strong> 3 | ||
<strong>Explanation:</strong> After one operation, nums becomes equal to [2, 11, 10, 3]. | ||
After two operations, nums becomes equal to [11, 10, 3]. | ||
After three operations, nums becomes equal to [11, 10]. | ||
At this stage, all the elements of nums are greater than or equal to 10 so we can stop. | ||
It can be shown that 3 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10. | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,1,2,4,9], k = 1 | ||
<strong>Output:</strong> 0 | ||
<strong>Explanation:</strong> All elements of the array are greater than or equal to 1 so we do not need to apply any operations on nums.</pre> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,1,2,4,9], k = 9 | ||
<strong>Output:</strong> 4 | ||
<strong>Explanation:</strong> only a single element of nums is greater than or equal to 9 so we need to apply the operations 4 times on nums. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 50</code></li> | ||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> | ||
<li><code>1 <= k <= 10<sup>9</sup></code></li> | ||
<li>The input is generated such that there is at least one index <code>i</code> such that <code>nums[i] >= k</code>.</li> | ||
</ul> |
11 changes: 11 additions & 0 deletions
11
3331-minimum-operations-to-exceed-threshold-value-i/solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
func minOperations(nums []int, k int) int { | ||
res := 0 | ||
|
||
for _, n := range nums { | ||
if n < k { | ||
res++ | ||
} | ||
} | ||
|
||
return res | ||
} |