The Leaderboard Shuffle — Java Bug Hunt
Inspired by the leaderboard-flicker tickets every game studio collects: players with equal scores swap places on every refresh.
- Language: Java
- Layer: Frontend
- Difficulty: Medium
- Concepts: Sorting, Stability
- Modelled on: Live-ops games
- Visible tests: ties keep arrival order; scores still dominate
- Reward: 50 XP for a complete fix
Briefing
Inspired by the leaderboard-flicker tickets every game studio collects: players with equal scores swap places on every refresh. Ties must preserve the order they arrived in (stable sort) — but someone "helpfully" added an alphabetical tiebreak.
Leaderboard.java sorts by score, descending, stable.
Bug report
BUG-FLICKER · Reported by: live-ops
sortByScore(names, scores) -> names sorted by score DESC:
- equal scores keep their ORIGINAL relative order (arrival order)
- no other tiebreak, alphabetical or otherwise
Observed: "zoe" reached 50 points before "amy", but every refresh shows amy above zoe — the tiebreak reorders them.
Logs
[board] tie at 50: zoe (first) rendered below amyThe code as shipped
Leaderboard.java (editable)
import java.util.*;
class Leaderboard {
static String[] sortByScore(String[] names, int[] scores) {
Integer[] idx = new Integer[names.length];
for (int i = 0; i < idx.length; i++) idx[i] = i;
Arrays.sort(idx, new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
if (scores[b] != scores[a]) return scores[b] - scores[a];
return names[a].compareTo(names[b]);
}
});
String[] out = new String[names.length];
for (int i = 0; i < out.length; i++) out[i] = names[idx[i]];
return out;
}
}Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Java bug hunts.