Diagnosis Pair
Challenge on lesson: Checkpoint: Algorithms
CHALLENGE
Difficulty: intermediate+25 XP
Two independent problems in Solution:
1. static int lowerBound(int[] sorted, int target) โ first index with
sorted[i] >= target via the half-open binary search; returning
sorted.length means none. (Not indexOf: duplicates must find the
FIRST.)
2. static boolean hasMajority(int[] xs) โ true when some value occurs
more than n/2 times, via one frequency-map pass (no sorting).
[1,2,2,2,3], lowerBound(2) โ 1 (not 2 โ the first).
[2,2,1,1], hasMajority โ false: 1 appears twice, n/2 = 2, needs MORE
than 2 โ false. [1,1,1,2] โ true: 3 of 4.
Press Submit to check your solution.
Back to lesson: Checkpoint: Algorithms