Tip 1: Solve a sufficient number of DSA questions.
Tip 2: Brush up on everything you already know.
Tip 3: Practice all concepts thoroughly.
Tip 1: Should be organized and not messy.
Tip 2: Convey clearly what you know.
It was a primarily coding-based round.



Input: ‘n’ = 4, ‘a’ = [3, 6, 2, 8] , ‘h’ = 7
Output: 3
Explanation: If ‘m’ = 3, then
The time taken to empty the 1st pile is 1 hour.
The time taken to empty the 2nd pile is 2 hour.
The time taken to empty the 3rd pile is 1 hour.
The time taken to empty the 4th pile is 3 hour.
Therefore a total of 7 hours is taken. It can be shown that if the rate of eating bananas is reduced, they can’t be eaten in 7 hours.
class Solution {
public int minEatingSpeed(int[] piles, int h) {
int max = 0;
for (int pile : piles) {
if (pile > max) {
max = pile;
}
}
int left = 1;
int right = max;
while (left < right) {
int mid = left + (right - left) / 2;
int hours = 0;
for (int pile : piles) {
hours += (pile + mid - 1) / mid; // ceiling division
}
if (hours <= h) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
}
}


I first sort the product quantities in descending order to prioritize distributing larger quantities. Then, I use binary search to determine the smallest possible value of the maximum number of products per store (x) such that all products can be distributed among the given number of stores, n. For each candidate value of x during the binary search, I calculate how many stores are required by dividing each product’s quantity by x and summing the total number of stores needed. Based on whether the required number of stores is less than or equal to n, I adjust the binary search bounds accordingly to find the optimal value of x.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is the purpose of the return keyword?