Give it an input and say what you think comes back. It compiles and runs for real, so a wrong guess still shows you the answer — probe as much as you like. Only correct predictions count.
Locked until you have predicted 5 outputs correctly.
| 1 | int solution(const vector<int>& nums, int h) { |
| 2 | int lo = 1; |
| 3 | int hi = *max_element(nums.begin(), nums.end()); |
| 4 | while (lo < hi) { |
| 5 | int mid = lo + (hi - lo) / 2; |
| 6 | long long hours = 0; |
| 7 | for (int x : nums) { |
| 8 | hours += (x + mid - 1) / mid; |
| 9 | } |
| 10 | if (hours <= h) hi = mid; |
| 11 | else lo = mid + 1; |
| 12 | } |
| 13 | return lo; |
| 14 | } |
Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.