could I get a bit of help for #3 I think it\'s just trying to find the closest g
ID: 3714688 • Letter: C
Question
could I get a bit of help for #3 I think it's just trying to find the closest gap between two players. but mainly need help on #4, would if be more efficient if we were to sort the array first let's say by merge sort?
thanks!
Explanation / Answer
Q3. We are finding the minimum difference between any two players
Q4. Yes, We can inprove the efficiency.
a) First Sort the array usign merger Sort: O(nlogn) time
b) traverse the array and keep the minimum difference
closest = abs(points[1] - points[0]);
for(int i=2; i<n ; i++) {
if(closest > abs(points[i] - points[i-1])) {
closest = abs(points[i] - points[i-1]);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.