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.

  1. what it is

    A judge runs your program once per test: input file → stdin → your code → stdout → checker. It only sees what you print.

  2. use it when

    Stdin mode with 10⁵+ tokens → BufferedReader + StringTokenizer in, StringBuilder or PrintWriter out. Small input → Scanner is fine.

  3. template

    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); … out.println(ans); out.flush();

  4. cost

    Rule of thumb: ~10⁸ simple steps per second. n = 10⁵: O(n²) = 10¹⁰ → TLE. O(n log n) ≈ 1.7 × 10⁶ → fine.

  5. trap

    PrintWriter without flush() prints nothing → WA. nextInt() then nextLine() returns "". Debug prints on stdout → WA.

  6. pro tip

    Verdicts are diagnoses: WA = output, TLE = complexity or slow I/O, RE = an exception, MLE = memory, CE = compile.

  7. trap

    AIOOBE = bad index · NPE = null · NumberFormat = bad parse · Arithmetic = / by zero · CME = edit in for-each · StackOverflow = deep recursion.

  8. 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.