TCS Digital Software Engineer — Make It Faster Than O(n squared)
- 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 coding problems, one solved with a hash map and one with two pointers or a sliding window, the three patterns that turn an O(n squared) brute force into O(n).
- Conversation dynamic. You state the obvious brute force and its complexity first, then the interviewer pushes you to make it faster and to justify why the faster version is correct.
- What gets tested. Whether you can reason about time and space complexity out loud, not just whether your code runs.
- Round format. A twenty minute technical round with problem cards in front of you and a whiteboard for tracing pointer and window movement.
What strong answers look like
- Brute force stated first. You describe the nested-loop approach and say its complexity is O(n squared) before writing the optimal one.
- Named trade-off on the pivot. When asked to go faster you say something like, I will use a hash map for extra space to get constant-time lookups and bring this to O(n).
- Correctness defended. You explain why the window stays valid as the left pointer advances, or how the hash map handles collisions and why lookups are constant on average.
- Whiteboard trace. You trace a short example, showing the left and right pointers or the running sum changing across the array.
What weak answers look like (and how to avoid them)
- Memorised optimal, no brute force. Jumping straight to the trick with no complexity stated hides whether you understand it, so always lead with the brute force.
- Wrong complexity claim. Calling a nested-loop solution linear loses trust fast, so count your loops before you name a big-O.
- Hash map with no collision story. Using a map but going blank on collisions reads as rote learning, so be ready with one clear sentence.
- Silent when stuck. Staring instead of tracing an example stalls the round, so draw a tiny case and reason from it.
Pre-interview checklist (2 minutes before you start)
- Recall the three patterns. Have hashing, two pointers, and sliding window ready as your go-to ways to remove a nested loop.
- Have a brute force reflex. For any array or string problem, be ready to state the nested-loop version and its O(n squared) cost first.
- Identify the sortedness cue. Notice when an array is sorted, because that is the signal for opposite-ends two pointers.
- Pull up your collision sentence. Be able to say in one line how a hash map handles collisions and why average lookups are constant.
- Think of a window-validity line. Be ready to explain why a sliding window does not skip a valid answer when the left pointer moves.
How the AI behaves
- Probes every complexity claim. It asks you to justify any big-O you state and checks it against the loops you wrote.
- No mid-interview praise. It will not say great answer; it acknowledges the specific thing you said and pushes on.
- Interrupts on a memorised jump. If you skip to the optimal solution it pulls you back to state the brute force and its cost first.
- Asks one thing at a time. It waits for your full response before following up, the way a real panel engineer does.
Common traps in this type of round
- Linear claim on quadratic code. Saying O(n) while running nested loops over the array.
- Trade-off left unspoken. Reaching the hash-map solution but never saying you are spending space to save time.
- Collision blank. Relying on a hash map but having nothing to say about how collisions are handled.
- Window asserted, not justified. Writing a sliding window but unable to say why it stays valid as it slides.
- Coding before clarifying. Writing code before restating the problem and confirming the example input and output.
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.
- 1Two Sum in an Unsorted Array (hashing)
Given an unsorted array of integers and a target value, return the indices of the two numbers that add up to the target. Start by describing the brute-force approach and its time complexity, then optimise when asked. The optimal solution uses a hash map to remember values you have already seen, trading O(n) extra space for O(n) time instead of the O(n squared) nested-loop scan.
Example inputnums = [2, 7, 11, 15], target = 9Example output[0, 1] (because nums[0] + nums[1] = 2 + 7 = 9)- Array is not sorted, so opposite-ends two pointers do not directly apply without sorting first.
- Exactly one valid pair exists; you may not reuse the same index twice.
- Be ready to explain how the hash map handles collisions and why average lookup is treated as constant time.
- On the whiteboard, write the array out and mark each value as you insert it into the hash map, showing the lookup that finds the complement.
- 2Longest Substring Without Repeating Characters (sliding window)
Given a string, find the length of the longest substring that contains no repeating characters. State the brute-force approach of checking every substring and its complexity first, then optimise. The optimal solution is a variable sliding window with a hash set: the right pointer adds the incoming character, and when a duplicate appears the left pointer advances until the window is valid again, giving O(n) time.
Example inputs = "abcabcbb"Example output3 (the longest substring without repeating characters is "abc")- The brute force checks every substring for uniqueness and is O(n squared) or worse; the window must beat it.
- Be ready to explain why advancing the left pointer past a duplicate never skips a longer valid substring.
- If asked the sorted-array variant instead, explain which pointer moves when the running sum is too small versus too large.
- On the whiteboard, trace the left and right pointers across the string, showing the window contents and the running best length at each step.
Interview framework
You will be scored on these 6 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 Articulation15%
- Optimisation Pivot Recognition25%
- Complexity-Claim Accuracy20%
- Correctness Justification20%
- Whiteboard Trace Fidelity12%
- Pattern Self-Awareness8%
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.
- Array Questions at TCS: What to Expect | CodeJeetcodejeet.com
- Two Pointers Technique - GeeksforGeeksgeeksforgeeks.org
- Short Notes on Two Pointer and Sliding Window - GeeksforGeeksgeeksforgeeks.org
- TCS Interview Experience for Digital Role (2026 graduate on campus) - GeeksforGeeksgeeksforgeeks.org
- TCS All India NQT Hiring Batch of 2024, 2025 and 2026 | TCS Careerstcs.com