Amazon SDE I · AUTA APJ · Job 10454435 · Round 4 only

Prev: 5. Projects · Next: 7. GenAI & CS

6. Coding if it appears

This is rehearsal for Adarsh Vishwakarma. R1 was 13 Aug 2026. R2 was 18 Aug 2026. R3 is done. This folder is leftover Round 4 only. OA is not a round. Live Code is Java. Job 10454435 still has no public write-up that names a live-round question. Families below are other candidates’ later slots. They show what an editor can look like. They are not a list for this Job ID. Unnamed stays unnamed.

How to use this chapter

Each family is one card. Restate input and output. Name brute, then the invariant, then type Java. A Fluency-labeled hour can still be a tree. Recruiter “LP-only” mail still opened an editor in other loops. If the algorithm under a card is what is unclear (BFS vs DFS, Kahn, monotonic stack), open the DSA Notes booklet first — two examples and two Java versions — then come back here or to chapter 05.

What they might ask

IE-asked as shape from other loops. Resume-derived later-slot coding prompts: none in the research for this topic. Pattern names are Standard CS families, not a claim this Job ID will ask them.

What you say

I will restate constraints, name a brute that is too slow for this hour, then type Java. If a tree is on the screen, I draw the tree and write the walk before a GenAI sentence.

They might ask next

If they askYou answer
They stay on storiesStay on stories. Chapter 3. Do not force an editor.
They paste code after an LP-only inviteWrite Java. Other loops were told LP-only and still got DSA (LC 7406809, 6806195). Shape evidence, not a forecast.
The hour is labeled FluencyIf a tree is pasted, write the tree first. One Fluency sentence later, only if they still ask. Chapter 7.

Keep straight

Tighten

If the editor opens, code first. GenAI sentence later. Stop after TC/SC unless they name an edge. Do not announce “this is the Bar Raiser.”

Shared Java types

Write these once at the top of Live Code, then the problem.

What they might ask

Standard CS scaffolding for this chapter.

What you say

class TreeNode {
  int val;
  TreeNode left, right;
  TreeNode(int v) { val = v; }
}
class ListNode {
  int val;
  ListNode next;
  ListNode(int v) { val = v; }
}

They might ask next

If they askYou answer
Parent pointer already on TreeNodeUse it. The Distance K card assumed no parent map because that write-up forbade one.
Values unique?Ask before treating node identity as value identity.

Keep straight

Tighten

Type the class, then the method they named. Do not lecture OOP.

Invite said LP-only — still write Java

Other AUTA loops were told three LPs, or the mail had no Live Code link, and the room still opened an editor. One Reddit leftover was LP-only as promised. Prepare Java; speak stories if they never paste code.

What they might ask

IE-asked LC 7406809, LC 6806195, Reddit 1qj304z. Other loops, not a forecast for Job 10454435.

What you say

If they paste an editor: I restate input, output, and constraints, name brute then the invariant, then type Java. I do not start a Leadership Principle while the tree is on the screen.

They might ask next

If they askYou answer
They never paste codeStay on stories. Reddit 1qj304z is permission to stay behavioral when they stay behavioral.
They paste after a STARFinish one sentence, then the editor. Do not finish a second STAR first.

Keep straight

Tighten

Do the hour in front of you. If the editor is empty, you are in chapter 3. If it has a tree, you are on this page.

Count Number of Nice Subarrays

Exactly k odd numbers in a contiguous subarray. Evens are free inside the window. Odds are a 0/1 budget. Exactly k is atMost(k) minus atMost(k−1).

What they might ask

IE-asked LC 6806195 — BR as third live, AUTA Bengaluru 2024, OA-as-R1 N. Candidate linked the slug /problems/count-number-of-nice-subarrays/. Numeric id was not typed. Same hour: LP on feedback / critical issues / went beyond task. Other loop, not a forecast for Job 10454435.

In plain words

Exactly k is not monotone: adding an odd can jump from k to k+1, so you cannot only shrink for “exactly.” atMost(k) is monotone. atMost(3) − atMost(2) leaves windows with exactly 3 odds. On the example that difference is 2.

What you say

Brute, and why it fails. Every L,R pair is O(n²). This Live Code hour also had ~30 min of LP left.

Optimal idea. For a right end r, the leftmost l such that odds in [l,r] ≤ k is monotone; every window [l′..r] with l′ ≥ l is also ≤ k, so you add r−l+1. Prefix-map of odd-count also works; two windows are O(1) extra.

public int numberOfSubarrays(int[] a, int k) {
  return atMostOdd(a, k) - atMostOdd(a, k - 1);
}
private int atMostOdd(int[] a, int k) {
  if (k < 0) return 0;
  int l = 0, odd = 0, ans = 0;
  for (int r = 0; r < a.length; r++) {
    odd += a[r] & 1;
    while (odd > k) odd -= a[l++] & 1;
    ans += r - l + 1;
  }
  return ans;
}

TC / SC. O(n) / O(1) two-pointer. Prefix HashMap<Integer,Integer> is O(n) / O(n).

They might ask next

If they askYou answer
k = 0 / all-even / emptyatMost(−1) returns 0. All-even with k=0: every subarray is nice. Empty array: 0.
Two-pass vs one mapTwo atMost windows is O(1) extra. Prefix odd-count map is O(n) extra, same time.
Exact sum with negativesPrefix + map. This 0/1 odd window is not that problem.

Keep straight

Tighten

Say exactly-k = atMost difference, type the two methods, state O(n)/O(1), stop.

Tree path src→target printed A/B/C

Shortest path as letters: A = left child, B = right child, C = parent. Extra space refused on that write-up; LCA + DFS on the recursion stack.

What they might ask

IE-asked LC 7406809 — BR as third, AUTA, OA-as-R1 N. Problem UNNAMED. Recruiter had said 3 LP; DSA anyway. Same IE’s Distance K with no parent map was their R2, not this leftover. Other loop, not a forecast for Job 10454435.

In plain words

Root-path to 1 and to 4 share prefix through 2. Cancel the common prefix: up from 1 to 2 is C; down 2 to 4 is B. Src equals target → empty string.

What you say

Brute, and why it fails. Enumerating all root-to-leaf strings, or a parent HashMap after they refused extra space.

Optimal idea. Path src→target = reverse of src→LCA as Cs, then LCA→target as A/B. Common prefix of the two root-paths is the LCA. Recursion stack of height is the allowed extra. A/B/C is their alphabet.

public String pathABC(TreeNode root, TreeNode src, TreeNode target) {
  List<TreeNode> toSrc = new ArrayList<>();
  List<TreeNode> toTgt = new ArrayList<>();
  if (!dfs(root, src, toSrc) || !dfs(root, target, toTgt)) return "";
  int i = 0, lim = Math.min(toSrc.size(), toTgt.size());
  while (i < lim && toSrc.get(i) == toTgt.get(i)) i++;
  int lca = i - 1;
  StringBuilder sb = new StringBuilder();
  for (int j = toSrc.size() - 1; j > lca; j--) sb.append('C');
  for (int j = lca; j < toTgt.size() - 1; j++) {
    TreeNode cur = toTgt.get(j), nxt = toTgt.get(j + 1);
    sb.append(cur.left == nxt ? 'A' : 'B');
  }
  return sb.toString();
}
private boolean dfs(TreeNode n, TreeNode goal, List<TreeNode> path) {
  if (n == null) return false;
  path.add(n);
  if (n == goal) return true;
  if (dfs(n.left, goal, path) || dfs(n.right, goal, path)) return true;
  path.remove(path.size() - 1);
  return false;
}

If they truly refuse the path lists: find LCA by recursion, then encode src→LCA as C count (depth difference) and LCA→target by walking children. Recursion stack is O(h).

TC / SC. O(n) / O(h) (lists O(h) on a path; worst O(n) skew).

They might ask next

If they askYou answer
Unique values? Shortest vs any?Ask. Missing node → empty or error, ask. Parent pointer already on TreeNode vs reconstruct.
They paste a tree anywayDraw it first, then letters.

Keep straight

Tighten

Ask unique values and extra-space rule, type LCA splice, state O(n)/O(h), stop.

Unique Paths–like maximum points (right/down only)

Grid path aggregation, not path count. Start and end may not be corners. Robot may move Right or Down only.

What they might ask

IE-asked LC 7035289 — BR as third, AUTA, OA-as-R1 N. Candidate said similar to Unique Paths. UNNAMED. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Right/down recursion is exponential overlapping subproblems.

Optimal idea. Because only right and down, every cell’s best is grid[i][j] + max(best from above, best from left) inside the start→end rectangle. No need for Dijkstra. Use long if sums can overflow int. Ask blocked cells.

public long maxPoints(int[][] g, int sr, int sc, int er, int ec) {
  int m = g.length, n = g[0].length;
  long NEG = Long.MIN_VALUE / 4;
  long[][] dp = new long[m][n];
  for (int i = 0; i < m; i++) Arrays.fill(dp[i], NEG);
  dp[sr][sc] = g[sr][sc];
  for (int i = sr; i <= er; i++) {
    for (int j = sc; j <= ec; j++) {
      if (i == sr && j == sc) continue;
      long up = i > sr ? dp[i - 1][j] : NEG;
      long left = j > sc ? dp[i][j - 1] : NEG;
      dp[i][j] = g[i][j] + Math.max(up, left);
    }
  }
  return dp[er][ec];
}

TC / SC. O(mn) / O(mn), or O(n) rolling array.

They might ask next

If they askYou answer
Start/end not cornersFill only the rectangle [sr..er] × [sc..ec]. Unreachable → sentinel.
Blocked cells / points on edgesAsk. Skip blocked. Edge weights are a different DP.

Keep straight

Tighten

Confirm only right/down, type the rectangle DP, state O(mn), stop.

Distance K, O(n), no parent mapping — Fluency-labeled

Invite said Gen AI Fluency. The hour was a tree walk. Write the tree first. Parent HashMap forbidden. After code, one GenAI sentence only if they still ask.

What they might ask

IE-asked LC 7623949 — labeled Gen AI Fluency = third live after two onsites; candidate: “essentially a DSA round.” BR after = fourth, LP-only. Sibling later: Dist-K family on “GenAI Essential + Coding” (LC 7584467). Sibling fourth: Dist-K + LCA titles UNNAMED (LC 6461439). Intern Fluency LC 7643209 unnamed min-heap is not this. AUTA Dist-K on 7406809 Round 2 is not leftover. Other loop, not a forecast for Job 10454435.

In plain words

        3
       / \
      5   1
     / \ / \
    6  2 0  8
      / \
     7   4

find(5) returns 0 and collects down k=2 (7, 4). find(3) sees left distance 0; does not add 3 (1 ≠ 2); collects sibling 1 at remaining 0. Draw their tree first if they drew a different one.

What you say

Brute, and why it fails. Parent map is forbidden; BFS-from-every-node is O(n²).

Optimal idea. If target is in the left subtree at distance L, this node is at L+1 from target; the right subtree is collected at remaining k−L−2 (one step up, one step down into the sibling). Adj-list + one BFS is also O(n) and is still not a parent map: undirected edges, parent passed as a call argument while building.

public List<Integer> distanceK(TreeNode root, TreeNode target, int k) {
  List<Integer> ans = new ArrayList<>();
  find(root, target, k, ans);
  return ans;
}
/** distance from node down to target, or -1 */
private int find(TreeNode node, TreeNode target, int k, List<Integer> ans) {
  if (node == null) return -1;
  if (node == target) {
    collectDown(node, k, ans);
    return 0;
  }
  int L = find(node.left, target, k, ans);
  if (L >= 0) {
    if (L + 1 == k) ans.add(node.val);
    collectDown(node.right, k - L - 2, ans);
    return L + 1;
  }
  int R = find(node.right, target, k, ans);
  if (R >= 0) {
    if (R + 1 == k) ans.add(node.val);
    collectDown(node.left, k - R - 2, ans);
    return R + 1;
  }
  return -1;
}
private void collectDown(TreeNode node, int dist, List<Integer> ans) {
  if (node == null || dist < 0) return;
  if (dist == 0) { ans.add(node.val); return; }
  collectDown(node.left, dist - 1, ans);
  collectDown(node.right, dist - 1, ans);
}

TC / SC. O(n) / O(n) worst (skew or adj) or O(h) extra if pure recursion on a balanced tree.

They might ask next

If they askYou answer
Target as node vs value; k = 0k = 0 → [target]. Unique values — ask. Distance through parent is the sibling collect.
They still want Fluency after JavaOne sentence: I would not put an LLM on this walk. Chapter 7 if they keep going.

Keep straight

Tighten

Draw the tree. Type find + collectDown. State O(n). GenAI sentence later, only if they still ask.

Next Greater Element

For every index, first value to its right that is strictly greater. Monotonic stack. Same HM hour as LLM talk — code is the named technical.

What they might ask

IE-asked LC 7724048 — HM Gen-AI as third; BR = fourth LP-only, no DSA. Title spoken; UNNAMED id. Next Permutation on Reddit 1u0yzoq was a GenAI third, not this HM. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Nested j > i scan is O(n²) under a mixed GenAI+code hour.

Optimal idea. Scan right-to-left. Stack holds a decreasing sequence of candidates still waiting to the right. Each index is pushed and popped once. Next-greater-same-digits is next permutation, not this.

public int[] nextGreater(int[] a) {
  int n = a.length;
  int[] ans = new int[n];
  Arrays.fill(ans, -1);
  Deque<Integer> st = new ArrayDeque<>();
  for (int i = n - 1; i >= 0; i--) {
    while (!st.isEmpty() && st.peek() <= a[i]) st.pop();
    if (!st.isEmpty()) ans[i] = st.peek();
    st.push(a[i]);
  }
  return ans;
}

TC / SC. O(n) / O(n). Java DS: ArrayDeque<Integer> (indices if you need positions).

They might ask next

If they askYou answer
Equals / no greaterStrictly greater; empty stack → sentinel −1. Previous greater: scan left-to-right.
Circular?Ask before writing a doubled-array loop. Indices on the stack if they want positions.

Keep straight

Tighten

Confirm not circular, type the stack, dry-run the example, state O(n), stop. LLM talk after code if they still want it.

Dynamic k-th largest (k changes)

Insert plus find k-th largest. k restates between queries. A min-heap sized to a fixed k breaks unless you rebuild.

What they might ask

IE-asked LC 7850431 ≡ IE.in 85 — GenAI+Technical as third; Round 4 behavioural = fourth, LP-only. UNNAMED. They timed out after BST talk on that IE. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Sort the list per find is O(n log n) per query. Static two-heap “fixed k” is the structure that dies when k restates.

Optimal idea. TreeMap of counts, or a BST with subtree sizes, keeps insert near log n for any k. The k-th largest is the k-th value walking the ordered multiset from the high end. Duplicates occupy consecutive ranks via counts.

class KthTracker {
  private final TreeMap<Integer, Integer> freq = new TreeMap<>();
  private int size = 0;
  void insert(int x) {
    freq.merge(x, 1, Integer::sum);
    size++;
  }
  int kthLargest(int k) {
    if (k < 1 || k > size) throw new IllegalArgumentException("k");
    int seen = 0;
    for (int v : freq.descendingKeySet()) {
      seen += freq.get(v);
      if (seen >= k) return v;
    }
    throw new IllegalStateException();
  }
}

TC / SC. Insert O(log n). Find O(n) naive walk of keys, or O(log n) with Fenwick / policy BST subtree counts if they want faster find. Space O(n).

They might ask next

If they askYou answer
Duplicates / k > size / k shrinksCounts handle duplicates. k > size is invalid. After more inserts, the same k is a new rank.
Faster than walking keysSubtree sizes on a BST, or Fenwick on compressed values.

Keep straight

Tighten

Name why two heaps break, type TreeMap, dry-run their example, stop.

Maximum Sum Linked List from two sorted lists

Two sorted lists that share some common nodes. Commons are join points. Between two commons, keep the heavier segment. Sibling wording returns the sum; another wording constructs the list.

What they might ask

IE-asked LC 6881058 heading Round 4 BR; prior lives href LC 6800853. FLAG OA-as-R1: chronological lives after dropping OA = third. Leftover later-slot shape. Sibling LC 6369243: BR as third, OA-as-R1 N; return maximum sum; no convert to array; follow-up K lists → heap. Numeric ids 962/210 sit on 6369243’s Round 1, not this BR item. Other loop, not a forecast for Job 10454435.

In plain words

1 vs 2: take the smaller pointer forward. At common 5, max(seg A=1, seg B=2+4)=6 plus 5. Then 8 vs 12 until common 12: max(8, 0)+12. Total 31. Lists increase, so the next equal value is the only legal switch.

What you say

Brute, and why it fails. Convert-to-array (explicitly refused on 6369243); exponential path enumeration at every common.

Optimal idea. Two pointers, greedy segment. Because both lists increase, you never want a node after a common that belongs to a skipped earlier segment. Greedy max of the two current segments is optimal. Use long for the sum.

public long maxSum(ListNode a, ListNode b) {
  long ans = 0, sa = 0, sb = 0;
  ListNode p = a, q = b;
  while (p != null && q != null) {
    if (p.val < q.val) { sa += p.val; p = p.next; }
    else if (q.val < p.val) { sb += q.val; q = q.next; }
    else {
      ans += Math.max(sa, sb) + p.val;
      sa = sb = 0;
      p = p.next;
      q = q.next;
    }
  }
  while (p != null) { sa += p.val; p = p.next; }
  while (q != null) { sb += q.val; q = q.next; }
  return ans + Math.max(sa, sb);
}

Construct-list variant: same merge, append the heavier segment’s nodes (copy or relink) then the common once.

TC / SC. O(n+m) / O(1) extra.

They might ask next

If they askYou answer
Lists not sorted? Commons not by value?This greedy needs sorted join-by-value. Ask if commons are pointer identity.
One list empty / commons at head or tailDrain the other list after the loop. Head common: segments start at 0.
K listsSibling follow-up: heap of heads, still greedy on matching values — ask before coding k-way.

Keep straight

Tighten

Ask sum vs construct-list. Type two pointers. State O(n+m)/O(1). Stop.

Combine Garlands (ropes; long) — HM, not BR

Minimum cost to combine lengths. Same idea as connect sticks: always merge the two smallest. Cost is the sum of pairwise merges, not the final length. Use long.

What they might ask

IE-asked LC 8362604 — HM as third (15 Apr 2026), not BR. AUTA APAC India 2026. BR 30 May = fourth LP-only, no DSA. Rate-limiting / geofencing on that BR = story follow-ups, not Rate Limiter LLD. Same HM as Anagrams variation. Same IE’s R2 Connect Ropes is already-done analogue, not this card. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Trying merge orders is factorial. int overflow was that IE’s messy-code fail mode.

Optimal idea. Huffman: the next merge cost is minimized by always taking the two currently shortest; the new length re-enters the set. n=1 → 0.

public long combineGarlands(int[] len) {
  PriorityQueue<Long> pq = new PriorityQueue<>();
  for (int x : len) pq.offer((long) x);
  long cost = 0;
  while (pq.size() > 1) {
    long a = pq.poll(), b = pq.poll();
    cost += a + b;
    pq.offer(a + b);
  }
  return cost;
}

TC / SC. O(n log n) / O(n).

They might ask next

If they askYou answer
Already sorted / equal lengthsHeap still. Equals are fine. Adjacent-only merge on a line is a different prompt — ask.

Keep straight

Tighten

Say Huffman, type PriorityQueue<Long>, state O(n log n), stop.

Anagrams variation — HM

Same AUTA 2026 HM as garlands. Variation unknown — ask the twist before coding. Classic family is a frequency window of length |p|.

What they might ask

IE-asked LC 8362604 — HM as third, not BR. BR fourth no DSA. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Permute/check every window. I will not invent their variation.

Optimal idea (classic). Anagram of p = same 26-counts in a window of length |p|. Slide one char: add right, drop left. After they name the twist I still expect an O(n) frequency window.

public List<Integer> findAnagrams(String s, String p) {
  int[] need = new int[26], have = new int[26];
  for (int i = 0; i < p.length(); i++) need[p.charAt(i) - 'a']++;
  List<Integer> ans = new ArrayList<>();
  int m = p.length();
  if (s.length() < m) return ans;
  for (int i = 0; i < s.length(); i++) {
    have[s.charAt(i) - 'a']++;
    if (i >= m) have[s.charAt(i - m) - 'a']--;
    if (i >= m - 1 && Arrays.equals(need, have)) ans.add(i - m + 1);
  }
  return ans;
}

TC / SC. Typical O(n) / O(1) alphabet. Java DS: int[26] or HashMap<Character,Integer>.

They might ask next

If they askYou answer
Empty s/p; case; unicodeAsk. Group-anagrams of whole words is a map-of-keys problem, not this window.

Keep straight

Tighten

Ask the twist in one sentence, then type the window they confirmed.

Word Ladder family CAT → MEN

One letter per iteration; intermediates must be dictionary words. Unweighted shortest transformation is BFS. Recursion finds a path, not necessarily the shortest.

What they might ask

IE-asked GFG sde-1-17 — F2F4 = fourth. Same IE as Validate sudoku on F2F3. AUTA N. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Branching on 26×wordLen without a visited set; recursion without BFS when they want min steps.

Optimal idea. First time you reach MEN, the layer index is the shortest hop count. I will not rebuild the dictionary API. Ask whether begin must sit in the dict and whether they want the path or the hop count.

public int ladderLength(String begin, String end, Set<String> dict) {
  if (begin.equals(end)) return 0;
  Queue<String> q = new ArrayDeque<>();
  Set<String> seen = new HashSet<>();
  q.add(begin);
  seen.add(begin);
  int steps = 0;
  while (!q.isEmpty()) {
    int sz = q.size();
    steps++;
    for (int s = 0; s < sz; s++) {
      char[] a = q.poll().toCharArray();
      for (int i = 0; i < a.length; i++) {
        char old = a[i];
        for (char c = 'A'; c <= 'Z'; c++) {
          a[i] = c;
          String nxt = new String(a);
          if (nxt.equals(end)) return steps;
          if (dict.contains(nxt) && seen.add(nxt)) q.add(nxt);
        }
        a[i] = old;
      }
    }
  }
  return -1;
}

TC / SC. Classic BFS ~ O(N · L · 26) with word length L. Java DS: ArrayDeque<String>; HashSet dict + visited.

They might ask next

If they askYou answer
Begin not in dict / no pathBegin can start outside. No path → −1 or empty list. Ask length vs steps vs the path itself.
Case of CAT/MENMatch their alphabet. One-letter vs generic edit — ask.

Keep straight

Tighten

Say BFS not DFS, type the layer loop, state complexity, stop.

Most frequent 3-page sequence

Consecutive triples per user, then a global map. Not a cartesian of pages across users. Leftover 10–15 min after LP on that write-up.

What they might ask

IE-asked LC 6573582 — BR as third, Bangalore SDE-1, AUTA N. UNNAMED. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Cross-user cartesian of pages; counting non-consecutive triples.

Optimal idea. A sequence counts once per occurrence of three consecutive visits in one user’s list (ask: twice in one user = 2?). Wrap-around is not in the write-up. Ties unspecified — ask.

public String mostFrequentTriple(Map<String, List<String>> userPages) {
  Map<String, Integer> cnt = new HashMap<>();
  String best = null;
  int bestC = 0;
  for (List<String> pages : userPages.values()) {
    for (int i = 0; i + 2 < pages.size(); i++) {
      String key = pages.get(i) + "-" + pages.get(i + 1) + "-" + pages.get(i + 2);
      int c = cnt.merge(key, 1, Integer::sum);
      if (c > bestC) { bestC = c; best = key; }
    }
  }
  return best;
}

TC / SC. O(total pages) / O(distinct triples).

They might ask next

If they askYou answer
Pages < 3; same triple twice; tie-breakSkip users with fewer than 3 pages. Ask whether one user can increment the same triple twice. Ask tie policy.

Keep straight

Tighten

Say consecutive per user, type the map, stop. This card fits a leftover 10–15 min.

Reverse linked list in groups of k

Dummy head; count k; reverse pointers in place. Ask leftover-tail policy: reverse the remainder vs leave it.

What they might ask

IE-asked Uday LinkedIn — BR as third (OA separate; R1 DSA; R2 Amazon Locker SD = not later). AUTA N. LP collaboration / ownership UNNAMED same BR. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Materializing all nodes then rebuilding; off-by-one on the last group. Extra ArrayList is the “optimization” they will ask you to drop.

Optimal idea. After reversing a k-block, the old head of that block is the tail and becomes prev for the next block.

public ListNode reverseKGroup(ListNode head, int k) {
  if (k <= 1 || head == null) return head;
  ListNode dummy = new ListNode(0);
  dummy.next = head;
  ListNode prev = dummy;
  while (true) {
    ListNode node = prev;
    for (int i = 0; i < k && node != null; i++) node = node.next;
    if (node == null) break;
    ListNode cur = prev.next;
    for (int i = 1; i < k; i++) {
      ListNode nxt = cur.next;
      cur.next = nxt.next;
      nxt.next = prev.next;
      prev.next = nxt;
    }
    prev = cur;
  }
  return dummy.next;
}

TC / SC. O(n) / O(1) extra.

They might ask next

If they askYou answer
k≤0; k=1; n not multiple of k; emptyk≤1 returns head. Incomplete last group left as-is in this sketch. Empty is null.

Keep straight

Tighten

Ask leftover policy, type dummy + in-place reverse, state O(n)/O(1), stop.

Validate sudoku (not Solver)

Constraint check: rows, cols, 3×3 boxes. Empty cells valid. Writing a backtracking solver is the wrong prompt.

What they might ask

IE-asked GFG sde-1-17 — F2F3 = third. AUTA N. LP extra-for-customers / client POV / conflict same F2F. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. A solver (backtracking) when they asked validate.

Optimal idea. Each of 9 rows, 9 cols, 9 boxes may contain each digit 1–9 at most once. Empties skip. Digit d at (i,j) is illegal if already seen in row i, column j, or box (i/3)*3 + j/3.

public boolean isValidSudoku(char[][] b) {
  boolean[][] row = new boolean[9][9];
  boolean[][] col = new boolean[9][9];
  boolean[][] box = new boolean[9][9];
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      if (b[i][j] == '.') continue;
      int d = b[i][j] - '1';
      if (d < 0 || d > 8) return false;
      int k = (i / 3) * 3 + j / 3;
      if (row[i][d] || col[j][d] || box[k][d]) return false;
      row[i][d] = col[j][d] = box[k][d] = true;
    }
  }
  return true;
}

TC / SC. O(81) / O(1). Bitmasks int[9] also fine.

They might ask next

If they askYou answer
'.' empties; malformed size; out-of-range digitSkip dots. Wrong size or digit outside 1–9 → false.

Keep straight

Tighten

Say check not search, type three boolean arrays, stop.

Union-Find / Disjoint Set — AUTA BR

Structure named, instance not given. Ask which API: connectivity, merge accounts, equations. Path compression + union by rank.

What they might ask

IE-asked LC 6866029 — BR as third, AUTA, OA-as-R1 N. Problem statement beyond “DSU logic” not given. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Rebuild components per query O(n²). DFS from every query without persisting unions.

Optimal idea. find(x)==find(y) iff x and y are in the same component after the unions so far. Path compression + rank keeps find nearly O(α(n)). I need the actual union/query API and 0 vs 1-based ids.

class DSU {
  final int[] p, r;
  DSU(int n) {
    p = new int[n];
    r = new int[n];
    for (int i = 0; i < n; i++) p[i] = i;
  }
  int find(int x) { return p[x] == x ? x : (p[x] = find(p[x])); }
  boolean union(int a, int b) {
    a = find(a); b = find(b);
    if (a == b) return false;
    if (r[a] < r[b]) { int t = a; a = b; b = t; }
    p[b] = a;
    if (r[a] == r[b]) r[a]++;
    return true;
  }
}

TC / SC. ~ O(n + q α(n)) / O(n).

They might ask next

If they askYou answer
Disconnected; union by rank vs size; 1-basedFind on a never-united node is itself. Rank or size both work. Ask indexing before allocating n+1.

Keep straight

Tighten

Ask the API, type DSU, then apply it to their queries. Stop.

Celebrity variant — AUTA BR

A variant of the Celebrity Problem. Exact variant UNNAMED. Ask before coding classic elimination. Skipping verify after picking a candidate is the classic fail.

What they might ask

IE-asked Reddit 1u0yzoq (No-Huckleberry-5969). BR as fourth after two offline DSA + GenAI third (Next Permutation in that GenAI hour). AUTA; ~1.5 YOE frontend; rejected. Job 10454435 N. One IE, not two. GFG off-campus-10 Celebrity R1 is the wrong slot. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. O(n²) full matrix without elimination; skipping verify.

Optimal idea (classic only, after they confirm). If A knows B, A is not celebrity; else B is not. One candidate left; verify in O(n). I will not assume exactly one celebrity.

public int findCelebrity(int n) {
  int cand = 0;
  for (int i = 1; i < n; i++) {
    if (knows(cand, i)) cand = i;
  }
  for (int i = 0; i < n; i++) {
    if (i == cand) continue;
    if (knows(cand, i) || !knows(i, cand)) return -1;
  }
  return cand;
}
boolean knows(int a, int b) { return false; /* interviewer oracle */ }

TC / SC. Classic family O(n) queries + O(n) verify / O(1) extra — only if the variant is classic; unknown here.

They might ask next

If they askYou answer
The variant firstAsk before this Java. GenAI was the previous hour on that IE, not this BR.

Keep straight

Tighten

One clarifying question on the variant, then elimination plus verify, or their graph if it is not classic.

Srenitha — sliding window UNNAMED

Coding similar to “maximum consecutive numbers.” Candidate: classic sliding window; follow-ups why this approach, how the window works, dry run. Exact constraint unnamed. Similar is not a proof of longest consecutive sequence.

What they might ask

IE-asked Srenitha Medium — BR as third after two UTA lives. UTA named SDE-I; selected Feb 2026. R2 pizza OOD = already-done analogue, not this card. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. O(n²) subarray checks. Jumping to a HashSet set-length is the wrong pattern if they wanted a window.

Optimal idea (typical SW). Right pointer only moves forward; left catches up so the window always satisfies the constraint; each index enters/leaves once. Deque only if the hidden twist is max-in-window — wait for the twist.

public int longestValidWindow(int[] a /* ask the predicate */) {
  int l = 0, best = 0;
  // maintain window invariant here — after they lock k-flips, ones-count, or value-run
  for (int r = 0; r < a.length; r++) {
    // add a[r]
    while (/* window invalid */) l++;
    best = Math.max(best, r - l + 1);
  }
  return best;
}

TC / SC. Typical SW O(n) / O(1).

They might ask next

If they askYou answer
Why this approach / dry runDo that on their example. Empty; all distinct — after the predicate exists.

Keep straight

Tighten

Lock the constraint in one question, dry-run their array, type two pointers, stop.

Reverse alternate levels of a binary tree (not perfect)

Their tree was not a perfect binary tree. Perfect-tree sibling-pointer trick dies. Level-order collect nodes on alternate levels, reverse values pairwise.

What they might ask

IE-asked Sarvesh Medium — BR as third after two lives. India SDE-1; rejected. AUTA N. Candidate linked similar to Reverse Odd Levels. LiveCode no compile/execution. Same BR: conflicting opinions; project idea; tech why; challenges. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Assuming complete/perfect; mutating structure instead of values if they wanted values.

Optimal idea. Nodes on one BFS level, left to right; reverse values pairwise. Missing children just mean a shorter list. Tree in Live Code: still draw it first.

public void reverseAlternate(TreeNode root) {
  if (root == null) return;
  Queue<TreeNode> q = new ArrayDeque<>();
  q.add(root);
  int level = 0;
  while (!q.isEmpty()) {
    int sz = q.size();
    List<TreeNode> row = new ArrayList<>();
    for (int i = 0; i < sz; i++) {
      TreeNode n = q.poll();
      if ((level & 1) == 1) row.add(n); // ask odd vs even
      if (n.left != null) q.add(n.left);
      if (n.right != null) q.add(n.right);
    }
    int i = 0, j = row.size() - 1;
    while (i < j) {
      int t = row.get(i).val;
      row.get(i).val = row.get(j).val;
      row.get(j).val = t;
      i++; j--;
    }
    level++;
  }
}

TC / SC. O(n) / O(n) (widest level).

They might ask next

If they askYou answer
Skewed tree; reverse links; 0-index vs 1-indexBFS still. Reverse links is a different mutation — ask. Confirm which levels.

Keep straight

Tighten

Draw their tree, confirm odd/even, type BFS reverse-values, stop.

n processes → k machines (i % k)

Assign each process starting at machine i % k; if busy try (i+1)%k …; return the machine handling the maximum number of processes. Duration / busy model unnamed — ask.

What they might ask

IE-asked IE.in 4-rounds (gated body). HM as third after two lives. IE.in labeled SDE I. AUTA N. Their R4 = LP names only. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Unclear “busy” without a duration model. Wrapping wrong. Mixing this with OS exam Bankers, or with the process-scheduler LLD on a different IE.

Optimal idea. Circular next-fit: start at i%k, walk k slots max, pick first free. Occupancy array + argmax. Scanning all k per process is O(nk), which may be fine.

public int busiestMachine(int n, int k) {
  int[] count = new int[k];
  boolean[] busy = new boolean[k]; // ASK: when does busy clear?
  for (int i = 0; i < n; i++) {
    int chosen = -1;
    for (int t = 0; t < k; t++) {
      int m = (i % k + t) % k;
      if (!busy[m]) { chosen = m; break; }
    }
    if (chosen < 0) {
      // ASK: wait, drop, or overwrite?
      continue;
    }
    busy[chosen] = true;
    count[chosen]++;
    // ASK: busy[chosen] = false after duration[i]
  }
  int best = 0, who = 0;
  for (int m = 0; m < k; m++) if (count[m] > best) { best = count[m]; who = m; }
  return who;
}

TC / SC. Simulation O(n k) worst / O(k) extra unless they give ranges that force better. Java DS: int[] count / int[] freeAt if each process has time.

They might ask next

If they askYou answer
Process index 0 vs 1; all busy; tie on maxAsk. Different from the scheduler LLD card later on this page.

Keep straight

Tighten

Ask busy/duration in one sentence, then type next-fit + argmax.

Bookstore word-count OOD

LLD, not DSA. Multiple books; count of a particular word in a specific book. Each book owns its vocabulary.

What they might ask

IE-asked Shiwangi — UTA R3 OOD = true third (16 Dec 2024). Same IE R4 = work deep-dive + medium Sliding Window UNNAMED (DSA leftover, not this LLD). AUTA N / UTA Y. TUF 6-22ec = reprint (OA-as-R1 numbering). Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Scan full text every query; one global bag mixing books.

Optimal idea. Book / Catalog / per-book counts. API count(bookId, word). Ingest once → per-book Map<word, count>. Concurrent catalog only if they ask.

class Book {
  final String id;
  final Map<String, Integer> wordCount = new HashMap<>();
  Book(String id, String text) {
    this.id = id;
    for (String w : text.toLowerCase().split("[^a-z0-9]+")) {
      if (w.isEmpty()) continue;
      wordCount.merge(w, 1, Integer::sum);
    }
  }
  int count(String word) {
    return wordCount.getOrDefault(word.toLowerCase(), 0);
  }
}
class Catalog {
  private final Map<String, Book> books = new HashMap<>();
  void add(Book b) { books.put(b.id, b); }
  int count(String bookId, String word) {
    Book b = books.get(bookId);
    if (b == null) return 0; // ASK missing
    return b.count(word);
  }
}

TC / SC. Preprocess O(tokens) / O(vocab); query O(1) hash.

They might ask next

If they askYou answer
Missing book; case; punctuationAsk 0 vs exception. Lowercase + split is a sketch. Same IE’s R4 unnamed sliding window is a different leftover (index-only table).

Keep straight

Tighten

Two classes, one API, ingest-once counts. Stop. Projects if they pivot.

Login layers (Controller / Facade / Service / Repository)

Another loop asked a login feature in those four layers, then how to replace a pile of if-else in the facade. This is layered structure in Live Code. It is not Login Tracker.

What they might ask

IE-asked Bhavya LinkedIn — Interview 3 HM = third. Hyd onsite May 2026. BR 3 Jun = LP only, no LLD. AUTA N. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Giant if in Facade; stuffing auth into Controller.

Optimal idea. Controller talks HTTP. Facade orchestrates. Service owns auth rules. Repository owns persistence. Each validation is a replaceable object, not a new branch. Password hash lives in Repository/Service, not Controller. Fail-fast or collect errors — ask.

interface Validator { void validate(LoginRequest req); }
class Facade {
  private final List<Validator> validators;
  private final AuthService auth;
  LoginResponse login(LoginRequest req) {
    for (Validator v : validators) v.validate(req);
    return auth.authenticate(req);
  }
}
// Controller -> Facade -> AuthService -> UserRepository

TC / SC. Structure. Validation O(#rules) per login.

They might ask next

If they askYou answer
Where the hash lives / session storeHash in repository/service. Session store only if they name it.

Keep straight

Tighten

Four boxes, validator list instead of if-else, stop. No LRU/DLL unless they pivot (they did not).

Process scheduler (LLD)

Process states plus a ready queue plus a policy. Same HM also had GenAI usage, verify GenAI code, and LCA (slug linked). If they paste a tree, write the tree first. Different prompt from n-processes → k-machines.

What they might ask

IE-asked LC 8014509 — HM Gen-AI as third (onsite 6 Apr 2026 same day as R1/R2). BR 14 Apr = fourth LP-only, no technical. Internals UNNAMED. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Single sleep loop with no queue; mixing scheduler LLD with LCA code without asking which they want first. Thread.sleep is not a scheduler.

Optimal idea. Only READY processes sit in the queue. Pick next is O(log n) on a heap policy, O(1) on a FIFO deque. Ask preemption. Priority inversion is unnamed unless they ask.

enum State { NEW, READY, RUNNING, WAITING, TERMINATED }
class Process {
  int pid, priority;
  State state = State.NEW;
}
class Scheduler {
  private final Queue<Process> ready =
      new PriorityQueue<>((a, b) -> Integer.compare(b.priority, a.priority));
  void submit(Process p) { p.state = State.READY; ready.offer(p); }
  Process pick() {
    Process p = ready.poll();
    if (p != null) p.state = State.RUNNING;
    return p;
  }
}

TC / SC. submit O(log n) if heap; pick O(log n).

They might ask next

If they askYou answer
They paste LCA in the same hourWrite the tree first, then return to this LLD. Ask which they want on the screen.
Preemption / waitingAsk. WAITING leaves the ready heap; running may return to READY if they want preemption.

Keep straight

Tighten

States + one queue + one pick. Stop unless they name preemption.

Light system design UNNAMED

Toward the end, a very basic system design prompt — title not given. Wait for their nouns. Entities, 2–3 APIs, in-memory map. No HLD boxes.

What they might ask

IE-asked Naina — UTA R3 = true third (2 Jul 2025). Offer after three lives. AUTA N / UTA Y. Rudraksh BR “common scenario from SDE-1 prep sets” is a different unnamed LLD. Other loop, not a forecast for Job 10454435.

What you say

Brute, and why it fails. Guessing a famous LLD from a prep list before they name the product.

Optimal idea. Clarify actors, the one write path, and the one read path, then sketch Java classes.

// wait for their nouns
// class X { Map<String, Y> store; void write(...); Z read(...); }

TC / SC. Unknown until the prompt exists.

They might ask next

If they askYou answer
They name entitiesClasses + methods. In-memory map. Stop. No Kafka lecture. Internships used Python, TypeScript, and ROS2; Live Code is Java.

Keep straight

Tighten

Wait. Two APIs. Stop.

Rate Limiter — independent count = 1, not UTA-default Round 4

Asked in a different loop, not leftover UTA two-DSA. Independent SDE I live-round count = 1. OA+3 system design. Not a fourth live. Not Adarsh Round 4 warmup. If they still paste it, solve what is on the screen.

What they might ask

IE-asked IE.in 2025-grad / TUF 21-5773 reprint (same report, not count 2). Not two-DSA UTA. Rudraksh prep list only is not a second ask. LC 8362604 “rate limiting decisions” / geofencing = BR stories. SDE II Rate Limiter = wrong level. Other loop, not a forecast for Job 10454435.

What you say

If they actually paste “design a rate limiter”: I still solve what is on the screen — allow N events per window, then ask in-process vs distributed. I will not say “I shipped this at Ylogx.” Ylogx Redis is cache-aside on the bot path (−35% bot DB latency), not a limiter I interned.

They might ask next

If they askYou answer
N, window, in-process vs distributedAsk those three. Label what is not on the resume.

Keep straight

Tighten

Do not drill token-bucket Java as required Live Code for this leftover hour. If they paste it anyway, N per window, then stop.

Also later-slot (index only — not warmup cards)

Survived remap. Not in the must-cover set above. Unnamed stays unnamed. No guessed ids. Recognition only.

What they might ask

IE-asked other loops. Not a Job 10454435 list.

What you say

I will restate their wording, name brute then the pattern, type Java. I will not attach an id they did not type.

They might ask next

WordingSlotFlag
Medium Sliding Window UNNAMED (after ~40 min work)fourth UTAShiwangi R4
LC Hard sliding window UNNAMED + 2–3 AI UNNAMEDHM/Gen-AI third; BR fourth LPReddit 1ueybmg AUTA
Longest Substring Without Repeating (title spoken)HM third; BR fourth no DSAAnsuman
maps + heaps UNNAMEDlater HM (BR first, then HM)Taanya
parent-only distance between nodesBR thirdLC 6475219
LCA (slug linked)HM thirdLC 8014509 (same hour as scheduler)
similar to Median of Two Sorted ArraysHM thirdLC 8029194
BS solved using PQ; “think dynamically”thirdLC 7981646
array/greedy medium 2-pass UNNAMEDBR third AUTADivanshu
DP + min-max heaps UNNAMEDFluency-labeled thirdAditya C.
Longest substring all distinctthird, not BRLC 6653463 UTA

Keep straight

Tighten

Use this table to recognize a family. Drill the named cards above, not this list as a second bible.

Companion: 7. GenAI & CS if the hour stays on verify / Fluency after the editor. Older 25-chapter notebook: interview_notebook home · research bible · study book.