TCS Digital Software Engineer Interview — Bit Tricks Over Loops
- Field
- Engineering
- Company
- Tata Consultancy Services
- Role
- Digital Software Engineer Trainee
- Duration
- 20 min
- Difficulty
- Hard
- 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 short problems, one bit-trick (count set bits, power of two, or single number via XOR) and one number-system problem (decimal-binary-hex conversion or adding binary strings).
- Conversation dynamic. You give the obvious loop and its complexity first, then the interviewer asks whether you can do it with bit operations and pushes you to explain why the trick works.
- What gets tested. Whether you can justify a bit trick rather than recite it, state time and space complexity for both approaches, and handle edge cases like zero and negatives.
- Round format. A live voice conversation with a shared whiteboard for drawing bit patterns and on-screen problem cards, around twenty minutes.
What strong answers look like
- Justified bit reasoning. You say n and n minus 1 removes the lowest set bit so the loop runs once per set bit, not just that it works.
- Complexity stated both ways. You compare the brute-force loop over all bits against the optimised cost, for example order of the number of set bits for Brian Kernighan.
- XOR understanding. You explain that a value XORed with itself is zero and with zero is itself, so duplicate pairs cancel and the lone element survives.
- Visible thinking. You draw the bit pattern on the whiteboard and keep narrating, so each step is followable.
What weak answers look like (and how to avoid them)
- Recited trick. Saying n and n minus 1 without explaining why it clears the lowest bit. Fix it by walking the binary of one example such as ten and nine.
- Silent optimisation. Going quiet when asked to optimise. Narrate the idea before you write any code.
- Loose complexity. Claiming order one with no justification. State how many times the loop actually runs.
- Wrong output format. Typing before reading the problem and printing the wrong thing. Re-read the exact expected output first.
Pre-interview checklist (2 minutes before you start)
- Recall the set-bit identity. n and n minus 1 drops the lowest set bit, so the loop count equals the number of set bits.
- Have the XOR property ready. Equal values XOR to zero and zero XOR a value is the value, which is why pairs cancel.
- Recall conversion steps. Repeated division by two for decimal to binary, grouping into nibbles of four for hexadecimal.
- Think of the masking move. Isolate the i-th bit by ANDing with one shifted left by i.
- Identify the edge cases. Be ready to discuss zero, negative numbers, and signed versus unsigned right shifts.
- Re-read the output format. Plan to read the problem fully before typing, since grading is on output.
How the AI behaves
- Probes every claim. Asks you to justify why a trick works and how many times the loop runs, not just the headline label.
- No mid-interview praise. It will not say great answer; it acknowledges the specific thing you said and pushes deeper.
- Interrupts on a wrong invariant. If you narrate a wrong reason for a trick, it stops you and asks you to recheck on an example.
- References your drawing. Names the bits and arrows you draw rather than speaking in abstractions.
Common traps in this type of round
- Trick without reason. Reciting n and n minus 1 but unable to explain why it clears the lowest set bit.
- XOR hand-waving. Using XOR for the single number without explaining why duplicates cancel to zero.
- Complexity label only. Saying order one or order n without stating the actual work done.
- Carry mistakes. Adding binary strings without correctly propagating the carry across positions.
- Signed-shift surprise. Assuming a right shift on a negative number fills with zeros, ignoring two complement and arithmetic shift.
- Format slip. Producing the right logic but the wrong printed output, which scores zero on the TCS judge.
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.
- 1Count Set Bits
Given a single non-negative integer n, count how many bits are set to one in its binary representation. First describe the obvious approach and its time complexity, then optimise it with a bit operation and explain why your optimisation is correct.
Example input13Example output3- 0 <= n <= 2^31 - 1
- State the time complexity of both the brute-force and the optimised approach
- Aim to make the loop run once per set bit rather than once per bit position
- On the whiteboard, draw the binary of n and mark the bit that disappears each time you apply your operation.
- 2Hex Conversion and Binary String Addition
Part A: given a non-negative decimal integer, print its hexadecimal representation. Part B: given two binary strings a and b, return their sum as a binary string. Talk through both, justifying the nibble grouping for hex and the carry handling for the addition.
Example inputPart A: 254 Part B: a = "1011", b = "0110"Example outputPart A: fe Part B: 10001- Decimal input fits in a 32-bit unsigned integer; binary strings may be up to 200 characters
- Explain why four binary bits map to exactly one hexadecimal digit
- Propagate the carry correctly, including the carry out of the most significant bit
- On the whiteboard, group the binary into nibbles of four and write the matching hex digit under each group.
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 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.
- Bit Trick Justification Depth22%
- Complexity Statement Rigor20%
- Number System Conversion Accuracy18%
- Edge Case and Signed Shift Reasoning16%
- Whiteboard Bit Pattern Alignment14%
- Reasoning Narration Continuity10%
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.
- Count set bits in an integer - GeeksforGeeksgeeksforgeeks.org
- TCS NQT Coding Questions & How Coding Task Evaluated in TCS NQT - GeeksforGeeksgeeksforgeeks.org
- Top Coding Interview Questions on Bit Manipulation - GeeksforGeeksgeeksforgeeks.org
- Two's Complement - GeeksforGeeksgeeksforgeeks.org
- Number System and Base Conversions - GeeksforGeeksgeeksforgeeks.org