0 like 0 dislike
598 views
| 598 views

0 like 0 dislike
1.)Largest Possible Square For Cut Sticks:
Given two Integers, cut them so that they form 4 sticks of same length(i.e. a square) and length of the side is maximized.(we can have leftovers).
Ex:
Input: A = 13, B = 11
Output: function will return 5 because we can cut two sticks of length 5 from each of the given sticks.
2.) Minimum operations to make all array elements equal by doing given two operations:
i) increment an element by 1
ii)choose two elements and increase the left one and decrease the right one.
ex:
Arr=[1,2,2,4]
we can make all elements equal to 3 by selecting 2,4 and and making them 3,3 by 2nd operaion.
and we can do first opeartion on remaining element.
3.)I do not remember exact problem statement,but it was a variation of Merge Overlapping Intervals with checking if given interval fully lies in any of the merged intervals.

by Expert (46,090 points)
0 like 0 dislike

Question 1) Binary search

``````    int[] nums = {13,11};
int range = 0;

for(int num : nums){
range += num;
}
int lo = 1;
int hi = range/4;
int ans = 0;

while(lo <= hi){
int mid = lo + (hi-lo)/2;
if(check(nums,mid,4)){
ans = mid;
lo = mid+1;
}
else {
hi = mid-1;
}
}
System.out.println(ans);
}

public static boolean check(int[] nums ,int mid, int side){
int count = 0;
for(int a : nums){
count += a/mid;
}
return count >= side;
} ``````
by Expert (46,090 points)