DriveReady

Q4 — CODING: EVERY QUESTION TYPE

What it looks like · the move · the trap

2 problems · 90 minutes · partial marks per test case passed. Q1 runs easy (I/O, strings, simple arrays). Q2 runs medium.

Read this before any algorithm

More candidates fail on input handling than on logic. A 2026 candidate, verbatim: "Focus on input handling. In hard-level coding problems the logic will be easier — the twist is kept in the input getting."

And because marks are per test case, a working brute force beats an unfinished optimal solution. Never submit nothing.


0 · INPUT HANDLING — not a topic, but the actual gatekeeper

Type 1 — Space-separated on one line

5
1 2 3 4 5

The move: sc.nextInt() in a loop. Handles newline-separated identically.

Type 2 — Comma-separated

1,2,3,4,5

The move: ⭐ Read the whole line, split on ,, trim each piece, then parse.

String[] parts = sc.nextLine().trim().split(",");
for (int i = 0; i < parts.length; i++) a[i] = Integer.parseInt(parts[i].trim());

Type 3 — No n given, just a line of values

Looks like: "Input: -29,-24,4,2,1,9.9,24,43,5,6,7" — a real 19 July question. The move: Read the line, split, use parts.length as the count.

That question also required detecting a float and printing "Invalid Input". The candidate's verdict: "the question was very easy, but the input handling makes it hard."

Type 4 — Format unclear or mixed

The move: ⭐ The universal reader — read everything, regex out every integer.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder(); String line;
while ((line = br.readLine()) != null) sb.append(line).append(" ");
Matcher m = Pattern.compile("-?\\d+").matcher(sb.toString());
List<Integer> nums = new ArrayList<>();
while (m.find()) nums.add(Integer.parseInt(m.group()));

Verified against space, newline, comma, mixed-with-negatives and command-line input.

⚠️ The three compiler facts that cost real marks in 2026

  1. Scanner.nextInt() may fail. "In my shift the input was a String. Many people used nextInt() and could not solve it." → read the line as a String and parse.
  2. The Java class name must match. "It will be mentioned at the end — name the class MyClass. If nothing is mentioned, use Main."
  3. The trailing space. System.out.print(x + " ") in a loop leaves one at the end and failed a whole slot on 28 June. Build with a separator before each item, or trim.

1 · MATH — 12 questions (the largest coding topic)

Type 5 — Digit peel (the backbone of half of TCS math questions)

Looks like: sum of digits · product of digits · reverse a number · count digits The move:

while (n > 0) { int d = n % 10;  /* use d */  n /= 10; }

Trap: ⭐ n = 0 — the loop never runs. Handle it explicitly.

Type 6 — Digital root

Looks like: "Add the digits repeatedly until one digit remains." The move: Loop it, or the closed form 1 + (n−1) % 9. O(1), no loop. Trap: n = 0 must be special-cased in the formula.

Type 7 — GCD / LCM

The move: Euclid: while (b != 0) { int t = b; b = a % b; a = t; } Trap: ⭐ LCM as a / gcd * b, never a * b / gcd — the second overflows.

Type 8 — Armstrong number

The move: Count the digits first, then raise each digit to that power. Trap: ⭐ Do not hardcode power 3 — TCS tests 4-digit cases like 1634. Avoid Math.pow (returns a double, rounds wrong).

This lesson is part of full access

One payment of ₹250 opens every lesson, practice set and mock for all five companies. No subscription, no expiry.

What is inside

  • Read this before any algorithm