Tata Consultancy Services Prime Coding Drill — Graphs, DP and Backtracking
- Field
- Engineering
- Company
- Tata Consultancy Services
- Role
- Prime Software Engineer
- Duration
- 20 min
- Difficulty
- Hard
- Completions
- New
- Updated
- 2026-06-09
What this round is about
This is a simulation of the TCS Prime technical interview — the coding drill that gates the Rs 9-11.5 LPA Prime offer and separates Prime candidates from the Digital band. You will face two hard DSA problems: Number of Islands (graph and grid traversal) and Coin Change (dynamic programming). The AI interviewer plays a senior TCS architect who probes the way real Prime interviewers do: constraint clarification first, then approach justification, then code, then tight Big-O, then one curveball follow-up. The whiteboard is live — use it to sketch the grid, the BFS queue state, and the DP table. The interviewer can see what you draw.
What strong answers look like
A strong candidate starts every problem by asking at least one constraint question (grid size? diagonal adjacency? coin denominations bounded?). They then name the algorithm and justify it over the alternative before writing a single line of code. For graph problems, they trace the BFS or DFS traversal on the example grid, naming what goes into the queue at each step. For DP problems, they derive the recurrence independently — dp[a] = min(dp[a], 1 + dp[a-c]) — by reasoning from the definition of dp[a], not by reciting a memorized formula. They give two complexity answers: one for time, one for space, with the dominant operation identified. When the curveball comes (space optimization, weighted graph, diagonal adjacency), they adapt calmly and reason through the change rather than freezing.
What weak answers look like (and how to avoid them)
The most common rejection pattern is jumping straight into code without asking a single constraint question. The interviewer will interrupt you and it signals poor engineering judgment. The second most common is stating a complexity without justifying it. Greedy for coin change is another trap: if you pick the largest coin each time for coins like 1, 3, 4 with amount 6, you get the wrong answer. Finally, writing BFS or DFS that only starts from one cell and misses disconnected components is a silent bug that kills your output on half the test cases.
Pre-interview checklist (2 minutes before you start)
- Open the whiteboard panel — you will need it for the grid trace and the DP table.
- Remind yourself: clarify constraints before coding, always.
- Know the BFS recurrence: mark cell visited, add unvisited neighbors to queue. Know the DP recurrence: dp[0] = 0, dp[a] = min(1 + dp[a-c]) for each coin c.
- Have ready: a counterexample where greedy fails for coin change (coins = [1,3,4], amount = 6 — greedy gives 4+1+1=3, optimal is 3+3=2).
- Know why BFS space can be O(min(rows,cols)) while DFS space can be O(rows*cols).
How the AI behaves
The AI plays Vikram Iyer, a senior TCS architect with 14 years of experience running Prime screening panels. He will interrupt you if you start coding without clarifying constraints. He will ask you to trace through the example input on the whiteboard. He will push back if your complexity analysis is wrong or insufficiently justified. He will give one curveball follow-up per problem. He does not soften corrections and he does not say great job to an average answer. Treat this exactly as you would treat a real Prime technical round.
Common traps in this type of round
Starting to code before clarifying: the interviewer will interrupt you and it is a mark against you. Giving the complexity without the justification: O(rows*cols) is incomplete without explaining why each cell is visited at most once. Missing the outer loop for disconnected components: your BFS starting from row 0 col 0 finds the first island but misses islands in other rows. Using greedy for coin change without testing a counterexample. Freezing on the curveball: the weighted graph follow-up or space-optimization question is not meant to trick you — reason aloud about what changes.
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.
- 1Number of Islands (Graph / Grid Traversal)
Given a 2D grid of '1' (land) and '0' (water), count the number of islands. An island is formed by connecting adjacent land cells horizontally or vertically. Solve with BFS or DFS and give the complexity.
Example inputgrid = [[1,1,0,0],[1,0,0,1],[0,0,1,1]]Example output2- 1 <= rows, cols <= 300
- Mark visited cells (flip to '0' or use a visited set) to avoid recounting
- State time O(rows*cols) and the worst-case space for the BFS queue or DFS recursion
- Be ready to discuss what changes if diagonal adjacency also counts
- Use the on-canvas card to read the prompt; sketch the grid and the traversal on the whiteboard. The AI sees what you draw.
- 2Coin Change — Minimum Coins (Dynamic Programming)
Given coin denominations and a target amount, return the minimum number of coins needed to make the amount, or -1 if it cannot be formed. Derive the DP recurrence before coding. Be ready to extend to a recursion-with-memo or backtracking explanation if asked.
Example inputcoins = [1, 2, 5], amount = 11Example output3 (5 + 5 + 1)- 1 <= coins.length <= 12; amount up to 10^4
- Define dp[a] = min coins to form amount a; dp[0] = 0; build bottom-up
- State time O(amount * coins) and space O(amount)
- Contrast the greedy approach and give a coin set where greedy fails
- Use the on-canvas card to read the prompt; sketch the DP table on the whiteboard. The AI sees what you draw.
Interview framework
You will be scored on these 5 dimensions. The full rubric with definitions is below.
What we evaluate
Your final scorecard breaks down across these dimensions. The full rubric and tier criteria are revealed inside the interview itself.
- Constraint Clarification Discipline20%
- Algorithm Approach Verbalization20%
- Recurrence and Traversal Derivation25%
- Complexity Analysis Precision20%
- Curveball Adaptability10%
- Implementation Correctness5%
Common questions
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.
- TCS Prime Interview Experience (2026 oncampus) - GeeksforGeeksgeeksforgeeks.org
- Shocking TCS Prime Interview Experience 2026 - Code Bridgecodebridg.in
- TCS Prime Sample Interview Questions and Answers 2026placementpreparation.io
- TCS NQT Prime | PrepInstaprepinsta.com
- TCS Prime Package and Salary Breakdown | PrepInstaprepinsta.com
- TCS NQT Coding Sheet - TCS Coding Questions - Tutorialtakeuforward.org
- My TCS Prime Interview Experience – 9 LPA Offer - GeeksforGeeksgeeksforgeeks.org