Skip to content

Commit 09307a3

Browse files
🔢 Day 6
1 parent c36ce4f commit 09307a3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
3. [Consecutive Characters](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/564/week-1-november-1st-november-7th/3518/) ➡️ [CPP Solution](Week1/maxPower.cpp)
1111
4. [Minimum Height Trees](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/564/week-1-november-1st-november-7th/3519/) ➡️ [CPP Solution](Week1/findMinHeightTrees.cpp)
1212
5. [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/564/week-1-november-1st-november-7th/3519/) ➡️ [CPP Solution](Week1/minCostToMoveChips.cpp)
13+
6. [Find the Smallest Divisor Given a Threshold](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/564/week-1-november-1st-november-7th/3520/) ➡️ [CPP Solution](Week1/smallestDivisor.cpp)
1314

1415
## Week 2 🚧
1516
Coming soon...

Week1/smallestDivisor.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
int smallestDivisor(vector<int>& nums, int threshold) {
4+
int left = 1, right = 1e6;
5+
int sum = 0;
6+
int mid, ans;
7+
8+
while(left <= right) {
9+
mid = left + (right - left) / 2;
10+
sum = 0;
11+
12+
for(int num: nums)
13+
sum += ceil((float)(num) / (float)(mid));
14+
15+
if(sum <= threshold) {
16+
ans = mid;
17+
right = mid - 1;
18+
} else {
19+
left = mid + 1;
20+
}
21+
}
22+
23+
return ans;
24+
}
25+
};

0 commit comments

Comments
 (0)