TCS Digital Engineer — String Brute Force to One Pass
- Field
- Engineering
- Company
- Tata Consultancy Services
- Role
- Digital Software Engineer Trainee
- Duration
- 20 min
- Difficulty
- Medium
- Completions
- New
- Updated
- 2026-06-11
How to prepare
What this round tests, what strong and weak answers sound like, and the traps to sidestep.
What this round is about
- Topic focus. Two string problems, an anagram check and longest palindromic substring, drawn from the family TCS reuses across NQT and Digital coding.
- Conversation dynamic. You are asked to state the obvious brute force and its complexity before writing anything, then pushed toward a one-pass frequency array or two pointers.
- What gets tested. Whether you can justify a time and space complexity by counting the work, and whether you handle edge cases like empty strings, mixed case, and character set.
- Round format. One spoken twenty-minute section with on-canvas problem cards and a diagram space for tracing index and pointer movement.
What strong answers look like
- Brute force stated first. You open with the obvious approach and its cost, for example sort both strings and compare is order n log n, before proposing anything faster.
- One-pass optimisation. You reach a fixed-size count array, increment for one string and decrement for the other, and call it order n time with constant space for a fixed alphabet.
- Edge cases unprompted. You name the empty string, single character, and unequal-length cases, and you ask whether comparison is case sensitive.
- Honest complexity on palindrome. You correctly say expand around centre is order n squared and name a linear alternative rather than bluffing.
What weak answers look like (and how to avoid them)
- Typing before thinking. Jumping into code without stating the brute force; fix it by saying the approach and complexity in one sentence first.
- Unjustified order n. Claiming an approach is linear without saying n of what; always state what you are counting.
- Ignoring the character set. Assuming lowercase English letters; ask whether the input is ASCII or Unicode before sizing a count array.
- Calling expand around centre linear. It is quadratic; if unsure, reason about centres times expansion rather than guessing.
Pre-interview checklist (2 minutes before you start)
- Recall the count-array trick. Be ready to size a frequency array and explain increment-decrement for anagrams in one pass.
- Have the two-pointer pattern ready. Know the converging-from-both-ends scan for palindrome validation in constant space.
- Think of the edge cases. Empty string, single character, unequal lengths, mixed case, spaces and punctuation.
- Identify your character-set question. Decide how you will ask whether it is ASCII or Unicode before sizing any array.
- Re-read the palindrome complexity. Be able to say why expand around centre is order n squared and what Manacher reuses to reach linear.
How the AI behaves
- Probes every claim. Asks you to justify each complexity by counting the work, not just stating a Big-O letter.
- No mid-interview praise. It will not say great answer; it acknowledges the specific thing you said and pushes deeper.
- Interrupts on abstraction. If you stay vague it asks what happens on the empty string or a single character right then.
- Never hands you the answer. It nudges with the smallest hint and never lists the correct solution for you.
Common traps in this type of round
- Length blindness. Forgetting that unequal lengths means not anagrams, a free early exit you should mention.
- Case and punctuation slip. Validating a palindrome without stripping case and non-alphanumeric characters.
- Unicode oversight. Sizing a count array at twenty six when the input could contain digits, spaces, or non-ASCII code points.
- Quadratic mislabel. Asserting expand around centre is linear when each centre can expand across the whole string.
- Complexity without counting. Saying order n while describing two nested scans of the text.
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.
- 1Check Whether Two Strings Are Anagrams
Given two strings, determine whether they are anagrams of each other, meaning one is a rearrangement of the other using the same characters with the same counts. State the most obvious brute force first along with its time complexity, then optimise toward a single pass. Be ready to discuss case sensitivity and whether the alphabet is ASCII or Unicode.
Example inputs1 = "listen", s2 = "silent"Example outputtrue- Strings may be empty or a single character.
- Compare characters as lowercase English letters unless you ask otherwise.
- 1 <= length of each string <= 100000.
- On the whiteboard, trace a fixed-size count array: increment for each character of s1, decrement for each character of s2, then check all counts are zero.
- 2Longest Palindromic Substring
Given a string, find the longest contiguous substring that reads the same forwards and backwards. State a brute force that checks substrings with its complexity, then describe expand around centre. Be ready to explain why expand around centre is order n squared and what a linear method would need to reuse.
Example inputs = "babad"Example output"bab" ("aba" is also a valid answer)- The string may be empty or a single character, which is itself a palindrome.
- Consider both odd-length and even-length centres.
- 1 <= length of string <= 1000.
- On the whiteboard, mark a centre index and two pointers expanding outward while characters match, tracking the longest span seen.
The full breakdown
How you're scored, the questions candidates ask most, and the research this interview is built on. Skim it — or just start the interview.
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.
- Brute Force Articulation20%
- Complexity Reasoning Rigor22%
- One Pass Optimisation Movement20%
- Edge Case And Character Set Coverage20%
- Palindrome Complexity Followup13%
- Communication And Dry Run Clarity5%
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 NQT Preparation Sheet 2026: Aptitude, Verbal and Coding Questions - GeeksforGeeksgeeksforgeeks.org
- TCS NQT Coding Questions and Answers 2026 - PrepInstaprepinsta.com
- TCS NQT Coding Questions and How Coding Task Evaluated in TCS NQT - GeeksforGeeksgeeksforgeeks.org
- Longest Palindromic Substring - GeeksforGeeksgeeksforgeeks.org
- TCS Digital Coding Questions with Answers 2026 - PrepInstaprepinsta.com