Arrays, Strings and Patterns round·Engineering·Medium·20 min

Tata Consultancy Services Ninja Coding Drill — Arrays, Strings and Patterns

20 min · 1 credit · scorecard at the end
Field
Engineering
Company
Tata Consultancy Services
Role
Assistant System Engineer Trainee (Ninja)
Duration
20 min
Difficulty
Medium
Completions
New
Updated
2026-06-09

What this round is about

This is a 20-minute live coding drill that mirrors the easy-to-medium band of the TCS NQT coding section and the live write-this-program ask inside the Ninja technical interview. You will work through two problems on screen: a pattern printing problem and an array manipulation problem. The interviewer will ask you to trace each problem on the whiteboard before you code, explain your logic after, and handle boundary inputs including cases not in the sample. One follow-up will ask you to improve your first working solution.

What strong answers look like

Strong candidates read the full problem statement before writing any code. They trace through a small example on the whiteboard — writing out variable states row by row or element by element — before touching the keyboard. They code the solution cleanly, then immediately name the complexity without being asked. When asked about boundary inputs they think through the limits systematically rather than guessing. On the improvement follow-up they make a genuine attempt: they identify what is redundant in their first solution and propose a change, even if incomplete. They explain every line of their code when asked to walk through it.

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

Weak candidates jump straight to coding before tracing. Their code produces the right output on the provided numbers but breaks on an all-identical list or a one-element list because they never considered those states. They say their solution is one-pass but quietly called sort() at line one. They cannot say how fast the code runs and say it is efficient without a number. On the improvement ask they give up immediately rather than attempting even a partial change. The fix for all of these is the same: read the full statement, trace before you code, and think out loud throughout.

Pre-interview checklist (2 minutes before you start)

  • Open the canvas card for Problem 1 and read the full statement including the output format before saying anything.
  • Choose the programming language you are most comfortable with — do not try a new language in this session.
  • Have a plan for describing how fast your code runs: know linear time, quadratic time, and log-linear time as phrases you can say out loud.
  • Remind yourself: trace on the whiteboard first, then code. Not the other way around.

How the AI behaves

The AI is Arvind Nair, a Senior Technical Panelist at TCS Pune running your TR+MR round. He will not coach you or tell you what performance he is looking for. He will interrupt if you try to code without tracing first. He will probe boundary inputs and will ask one improvement follow-up. He stays in character throughout and will not tell you if you got the answer right mid-session.

Common traps in this type of round

  • Calling sort() inside a solution you claim is one-pass — the interviewer will catch this and it signals a gap in performance awareness.
  • Tracing only the provided example and never considering what happens for n equals 0 or an array with a single element.
  • Giving up on the improvement ask without attempting anything — even a partial improvement attempt scores better than silence.
  • Writing code you cannot explain — if you cannot walk through it line by line, the interviewer assumes you copied or guessed.

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. 1Floyd's Triangle Pattern

    Print Floyd's triangle for n rows: row i holds i consecutive integers continuing from where the previous row stopped (row 1 = 1; row 2 = 2 3; row 3 = 4 5 6; ...). Read n and print the triangle.

    Example inputn = 4
    Example output1 2 3 4 5 6 7 8 9 10
    • 1 <= n <= 50
    • Use nested loops with a running counter carried across rows
    • State the time complexity in terms of the total numbers printed
    • Dry-run n = 3 on the whiteboard before you write code
    • Use the on-canvas card to read the prompt; sketch or write code on the whiteboard. The AI sees what you draw.
  2. 2Second Largest Element (Single Pass)

    Given an array of integers, return the second-largest DISTINCT value in a single pass, without fully sorting the array. If no valid second-largest exists, say so.

    Example input[12, 35, 1, 10, 35, 1]
    Example output12 (35 is largest; 12 is the second-largest distinct value)
    • 2 <= array length <= 10^5
    • Single pass — track largest and secondLargest as you scan
    • Handle duplicates of the maximum and arrays with fewer than 2 distinct values
    • State time O(n) and space O(1)
    • Use the on-canvas card to read the prompt; sketch or write code on the whiteboard. The AI sees what you draw.

Interview framework

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

Dry-run Process Discipline
22%
Coding Correctness Under Observation
22%
Complexity Articulation
18%
Edge Case Coverage
18%
Optimisation Attempt Quality
12%
Code Walkthrough Accuracy
8%

What we evaluate

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

  • Dry-Run Process Discipline22%
  • Coding Correctness Under Observation22%
  • Complexity Articulation18%
  • Edge Case Coverage18%
  • Optimisation Attempt Quality12%
  • Code Walkthrough Accuracy8%

Common questions

What coding questions are asked in TCS Ninja technical interview 2026?
TCS Ninja TR+MR coding questions typically include a pattern printing problem such as Floyd's triangle and an array or string manipulation problem such as finding the second-largest element without sorting. Candidates must dry-run on a whiteboard, state time and space complexity, and handle edge cases.
How difficult is the TCS Ninja coding round compared to the NQT?
The TR+MR coding drill is at the same easy-to-medium difficulty as the NQT coding section. The difference is that a human interviewer watches you code and asks you to explain your logic, trace through a sample input, and handle boundary cases — the auto-evaluator in the NQT does not do any of this.
What is Floyd's triangle and how do I print it in Java or Python?
Floyd's triangle is a number pattern where row i contains i consecutive integers continuing from where the previous row stopped. Row 1 is 1, row 2 is 2 3, row 3 is 4 5 6. Use a nested loop with a running counter initialised to 1 before the outer loop. The outer loop runs n times and the inner loop runs i times, printing counter++ each iteration.
How do I find the second-largest element in an array without sorting in a single pass?
Maintain two variables: largest and secondLargest, both initialised to negative infinity. Scan the array once. If the current element is greater than largest, update secondLargest to the old largest and update largest. If the current element is less than largest but greater than secondLargest, update secondLargest. This gives O of n time and O of 1 space.
Why does TCS ask candidates to state time complexity in the Ninja interview?
TCS interviewers use complexity awareness as a gate. A candidate who cannot say O of n versus O of n log n is unlikely to recognise performance issues when working on large-scale client systems. Ninja hires are expected to understand why a single-pass O of n solution is superior to a sort-then-index O of n log n approach for array problems.
What are the most common reasons candidates fail the TCS Ninja technical round?
The most common rejection patterns are: writing code you cannot explain step by step, ignoring edge cases like empty array or all-duplicate elements, claiming single-pass but calling sort(), jumping to code without reading the full problem statement, and refusing to attempt the optimisation follow-up.
How many rounds are there in TCS campus placement for Ninja batch 2026?
There are three rounds: Round 1 is the NQT online test with Verbal, Numerical, Logical, and Advanced Coding sections. Round 2 is TR+MR which is Technical and Managerial combined on MS Teams. Round 3 is the HR interview for those who pass TR+MR.
Is the TCS Ninja interview conducted online or offline in 2026?
The TCS TR+MR round for Ninja candidates is conducted on Microsoft Teams. The whiteboard component uses screen-sharing and drawing tools, or the interviewer may ask the candidate to use a virtual whiteboard to trace their algorithm.
What is the difference between TCS Ninja and TCS Digital bands?
Ninja is the top scoring band in TCS campus hiring, earned by scoring above the Ninja threshold in the NQT Advanced Coding section. Digital is the second-highest band. Both are above the regular ASE track. Ninja hires command a higher starting salary and are assigned to more technically demanding initial projects in the ILP.
What edge cases should I handle for the second-largest element problem in TCS Ninja interview?
Handle three cases: first, array with all identical elements — there is no valid second-largest, state this explicitly. Second, array with only one element — no second-largest exists. Third, array where the maximum appears multiple times — the second-largest is the largest value strictly less than the maximum, not the second occurrence.
How should I prepare for TCS NQT Ninja coding section in 2 weeks?
Practice the TCS NQT coding sheet on GeeksforGeeks and PrepInsta daily. Focus on pattern printing, array problems, and string problems. For each problem, practise stating the time and space complexity and identifying the empty-array and single-element edge cases before looking at the solution.
Can I use Python for TCS NQT coding section and Ninja interview?
Yes. TCS NQT supports C, C++, Java, Python, and Perl. Python is acceptable in the TR+MR live coding session as well. Use the language you are most comfortable with and have practised enough problems in — switching languages under interview pressure is a common mistake.

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.