synopsis · Java for DSA · chapter 4
Fast I/O, Judges & Debugging
8 cards, about a minute. Read them the night before an interview, or right after the chapter to lock it in.
- what it is
A judge runs your program once per test: input file → stdin → your code → stdout → checker. It only sees what you print.
- use it when
Stdin mode with 10⁵+ tokens → BufferedReader + StringTokenizer in, StringBuilder or PrintWriter out. Small input → Scanner is fine.
- template
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));…out.println(ans); out.flush(); - cost
Rule of thumb: ~10⁸ simple steps per second. n = 10⁵: O(n²) = 10¹⁰ → TLE. O(n log n) ≈ 1.7 × 10⁶ → fine.
- trap
PrintWriter without
flush()prints nothing → WA.nextInt()thennextLine()returns "". Debug prints on stdout → WA. - pro tip
Verdicts are diagnoses: WA = output, TLE = complexity or slow I/O, RE = an exception, MLE = memory, CE = compile.
- trap
AIOOBE = bad index · NPE = null · NumberFormat = bad parse · Arithmetic = / by zero · CME = edit in for-each · StackOverflow = deep recursion.
- pro tip
Stuck on WA? Samples → edge cases → stress test vs brute force → shrink the failing input → dry-run it.
Shaky on a card? Open the chapter or flip its recall cards.