Linked List and Stack Pointer Drill round·Engineering·Hard·20 min

TCS Digital Software Engineer — Linked List and Stack Pointer Drill

20 min · 1 credit · scorecard at the end
Field
Engineering
Company
Tata Consultancy Services
Role
Digital Software Engineer Trainee
Duration
20 min
Difficulty
Hard
Completions
New
Updated
2026-06-09

What this round is about

  • Topic focus. Two linear-structure problems: a singly linked-list reversal you trace pointer by pointer, then a stack-based check for balanced parentheses.
  • Conversation dynamic. A senior Digital panellist makes you draw and walk a small example on the whiteboard before you write any code, then pushes on edge cases and complexity.
  • What gets tested. Pointer discipline, correct handling of the empty and single-node cases, big-O reasoning, and your justification for choosing one structure over another.
  • Round format. Twenty minutes, voice plus a shared diagram canvas, calibrated to the higher TCS Digital tier rather than the base coding round.

What strong answers look like

  • Trace before code. You draw the list and say what each pointer does, for example: I save next, point current back to prev, then advance both.
  • Pointer integrity. You never lose the tail of the list because you save the next node before rewiring the current node.
  • Edge cases named unprompted. You state that an empty list returns null and a single-node list returns itself before anyone asks.
  • Complexity stated plainly. You close with O(n) time and O(1) space for the iterative reversal and explain why the recursive version costs O(n) space.

What weak answers look like (and how to avoid them)

  • Code-first guessing. Jumping into syntax without a trace; avoid it by drawing the starting list first and walking one input by hand.
  • Lost-tail bug. Overwriting the next pointer before saving it, which orphans the rest of the list; save next into a temporary first.
  • Frozen on empties. Crashing on the empty or single-node case; decide their return value before writing the loop.
  • Name without trace. Saying Floyd's algorithm or stack without showing the steps; always demonstrate the movement on the board.

Pre-interview checklist (2 minutes before you start)

  • Recall the three pointers. Have prev, current, and next clear in your head for the iterative reversal.
  • Have the dummy-node trick ready. Remember it removes the special case when the node to remove is the head.
  • Think of the two orderings. Be ready to say why last-in-first-out fits nested brackets and first-in-first-out does not.
  • Identify the empty and single-node returns. Know what each problem returns on those inputs before you code.
  • Pull up the whiteboard early. Plan to draw the starting structure in your first turn, not the syntax.
  • Re-read the complexity claim. Be ready to defend why iterative reversal is O(1) space and recursion is not.

How the AI behaves

  • Pushes you to the board. Redirects you to sketch within the first two turns if you start narrating without drawing.
  • Probes every claim. Asks for the complexity and the edge-case behaviour, not just the headline approach.
  • No mid-interview praise. Will not say great answer or validate; it acknowledges the specific move and pushes deeper.
  • Interrupts on hand-waving. Stops you when you say and then I reverse it and asks for the exact pointer steps.

Common traps in this type of round

  • Overwriting next too early. Losing the remainder of the list during reversal because the next node was not saved.
  • Single-node blind spot. Forgetting that a one-node list and an empty list need explicit handling.
  • Complexity guess. Stating a big-O figure that does not match the code just written on the board.
  • Wrong structure justification. Claiming a queue validates brackets, or being unable to say why a stack does.
  • Recursion without limits. Proposing recursive reversal without acknowledging the stack-overflow risk on a very long list.
  • Algorithm name as a shield. Citing Floyd's tortoise and hare without tracing the slow and fast pointers on an example.

Sample problems you'll face

The 2 problems below are the same ones you'll work through in the live session — no surprises. Read the constraints carefully; the AI persona will refer you to the on-canvas card by problem number.

  1. 1Reverse a Singly Linked List

    Given the head of a singly linked list, reverse the list by changing the next pointers of each node, and return the new head. Do it iteratively, then describe the recursive version. Trace the three pointers on a small example before coding and state the time and space complexity of each approach.

    Example inputhead = 1 -> 2 -> 3 -> 4 -> null
    Example output4 -> 3 -> 2 -> 1 -> null
    • The list may be empty (head is null) or contain a single node; both must be handled cleanly.
    • Iterative solution must use O(1) extra space; save the next node before rewiring the current node's pointer.
    • State the time complexity (O(n)) and explain why the recursive version uses O(n) space on the call stack.
    • Draw the three-pointer state (prev, current, next) on the canvas after each step of the reversal.
  2. 2Valid Parentheses (Balanced Brackets)

    Given a string containing the characters round, square and curly brackets, determine whether the brackets are balanced and correctly nested. Choose a data structure, justify it in terms of last-in-first-out ordering, and handle the case where brackets are left unclosed at the end.

    Example inputs = "([]{})" and s = "([)]"
    Example outputtrue for "([]{})", false for "([)]"
    • Use a stack: push each opening bracket and pop to match each closing bracket against its expected opener.
    • After the final character, the stack must be empty; an unclosed opening bracket makes the string invalid.
    • State the time complexity (O(n)) and the worst-case space (O(n)) when all characters are opening brackets.
    • Draw the stack contents on the canvas as you process the input ([)] and mark the exact character where the mismatch is detected.

Interview framework

You will be scored on these 5 dimensions. The full rubric with definitions is below.

Pointer Trace Discipline
How fully you draw and walk the node-and-pointer state on a concrete example before and while you code, rather than narrating in the abstract.
24%
Pointer Integrity Under Rewiring
Whether your reversal saves the forward link before flipping it so the remainder of the list is never orphaned.
20%
Edge Case Coverage
Whether you name and correctly handle the empty list and single-node inputs without being prompted.
20%
Complexity Reasoning
Whether you state time and space complexity that matches the code on the board, including the recursion call-stack cost.
18%
Structure Choice Justification
Whether you justify a stack over a queue for nested brackets in terms of last-in-first-out ordering, not just naming it.
18%

What we evaluate

Your final scorecard breaks down across these dimensions. The full rubric and tier criteria are revealed inside the interview itself.

  • Pointer Trace Discipline20%
  • Pointer Integrity Under Rewiring18%
  • Linear Structure Edge Case Coverage18%
  • Asymptotic Complexity Reasoning16%
  • Data Structure Choice Justification16%
  • Explain Before Code Clarity12%

Common questions

What does the TCS Digital coding round actually test?
It tests whether you can manipulate pointers correctly and reason about linear data structures under time pressure, not whether you have memorised solutions. Expect a linked-list problem such as reversing a list iteratively and recursively or detecting a cycle, and a stack-or-queue problem such as validating balanced parentheses or building a queue from two stacks. The panellist wants you to trace the structure on a small example first, handle the empty and single-node cases, and state the time and space complexity of your approach before and after you code.
How should I structure my answer in this round?
Lead with the whiteboard, not the keyboard. Draw the nodes and pointers, walk one small input through your approach by hand, and say out loud what each pointer does at each step. Only then write the code. Close every problem by stating its time and space complexity and by naming the empty-list and single-node behaviour. This mirrors what selected TCS Digital candidates report doing and it is the single biggest separator between an offer and a rejection.
What are the most common mistakes candidates make here?
The classic failure is jumping straight to code without tracing an example, then losing the rest of the list because the next pointer was overwritten before it was saved. Others freeze on the empty or single-node case and produce a null-pointer crash, cannot state the complexity of their own code, or cannot say why a stack beats a queue for nested brackets. Reciting an algorithm name like Floyd's without tracing it on the board also reads as memorisation, not understanding.
How is this AI interviewer different from a real TCS panellist?
It behaves like a real senior developer on the Digital panel: it interrupts, pushes back, and refuses to let you narrate a design without drawing it. The difference is that it never tires, never gives away the answer, and produces a precise transcript-backed scorecard afterwards naming the exact pointer rewire or edge case you could not justify. A real panel gives you a yes or no days later; this gives you the specific gap immediately.
How is the session scored?
You are scored on observable behaviours: whether you traced the structure before coding, whether your pointer rewiring kept the list intact, whether you covered the empty and single-node cases, whether you stated correct big-O complexity, and whether you justified your choice of structure. Each dimension produces a graded line in the report with concrete moments from your transcript, so you can see precisely where the reasoning held and where it slipped.
What should I do in the first two minutes?
Restate the problem in your own words, confirm the input shape with one clarifying question if needed, and then pull up the whiteboard and draw the starting list. Do not start coding. In the first two minutes the panellist is deciding whether you are a tracer or a guesser, and the candidates who draw first earn the benefit of the doubt for the rest of the round.
How do I handle the empty list and single-node cases?
Name them before you are asked. For a reversal, an empty list returns null and a single-node list returns itself unchanged, so your loop or recursion must terminate cleanly on both. For the two-pointer Nth-from-end walk, a dummy node in front of the head removes the special case of deleting the first node. Saying this unprompted signals real understanding and is exactly the behaviour that separates selected candidates from rejected ones.
Why does the interviewer keep asking about complexity and recursion?
Because a candidate who cannot state the time and space complexity of their own code does not fully understand it. Reversal and bracket validation are O(n) time; the iterative reversal is O(1) space while the recursive version is O(n) space because of the call stack. The panellist will ask what happens when the recursive reversal runs on a list of a million nodes, and the answer they want is a stack overflow, which is why iterative is often preferred in production.
When does a stack beat a queue, and will I be asked?
Yes, the why-this-structure follow-up is standard. A stack is last-in-first-out, which is exactly what nested brackets need: the most recently opened bracket must close first, so you push openers and pop to match each closer. A queue is first-in-first-out and cannot express that nesting. You may also be asked to build a queue out of two stacks, which tests whether you understand both orderings well enough to convert one into the other.
What does a strong answer sound like in this round?
It sounds like narration tied to a drawing: I set prev to null, current to head, and at each step I save next, point current back to prev, then advance prev and current. It names the invariant, predicts the end state, covers the empty and single-node cases, and ends with O(n) time and O(1) space. For the stack problem it explains the last-in-first-out match and the empty-stack-at-end check. Confidence plus a correct trace, not speed, is what lands.
Is this round the same as the TCS NQT coding test?
It is related but harder. The NQT and base-cadre coding rounds lean on arrays, strings, and basic problem-solving, while the Digital tier sets a moderate-to-advanced bar that rewards pointer-traced reasoning and complexity literacy. This drill is pitched at the Digital altitude, so expect deeper follow-ups on edge cases, recursion limits, and structure choice than a standard NQT problem would carry.

Sources this interview is built on

Real candidate-report URLs (Glassdoor / AmbitionBox / PrepInsta / GeeksforGeeks / Medium) reviewed when authoring the questions, persona, and rubric. Verify the realism yourself.