Bit Tricks Over Loops round·Engineering·Hard·20 min

TCS Digital Software Engineer Interview — Bit Tricks Over Loops

20 min · 1 credit · scorecard at the end
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.

  1. 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 input13
    Example 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.
  2. 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.
Reference

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.

Bit Trick Justification
Whether you explain why a bit operation works on a concrete example, not just that it produces the right answer.
24%
Complexity Reasoning
How precisely you state and compare time and space cost for the brute-force and optimised approaches, with actual iteration counts.
20%
Number System Fluency
How cleanly you convert between decimal, binary and hex and handle carry in binary addition without slips.
18%
Edge Case Coverage
Whether you surface zero, negatives, signed shifts and overflow rather than assuming the happy path.
14%
Whiteboard Bit Reasoning
How well your drawn bit patterns match your spoken reasoning and make the changing bit visible.
14%
Thinking Out Loud
Whether you keep narrating your reasoning so each step is followable instead of going silent under pressure.
10%

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

What does the TCS Digital bit manipulation coding round actually test?
It tests whether you can move past the obvious loop to a bit-level trick and explain why it works. You get two short problems: one bit-trick problem such as counting set bits, checking a power of two, or finding the single non-repeating number with XOR, and one number-system problem such as converting between decimal, binary and hexadecimal or adding binary strings. The interviewer first asks for the brute-force approach and its time complexity, then pushes you to optimise with bit operations. A strong showing means stating complexity for both approaches and justifying the trick, not just reciting it.
How should I structure my answer when asked to optimise a loop?
State the brute-force approach first and give its time and space complexity out loud, because the interviewer expects that before any optimisation. Then narrate the bit-level idea before coding: for set bits, say that n and n minus 1 removes the lowest set bit so the loop runs once per set bit. Draw the bit pattern on the whiteboard so your reasoning is visible. Only then write the code. Finish by restating the new complexity and naming one edge case such as zero or a negative input.
What are the most common mistakes candidates make in this round?
The biggest one is reciting a trick like n and n minus 1 without being able to explain why it clears the lowest set bit. Another is jumping into typing before reading the problem and producing the wrong output format, which scores zero on the TCS judge since it grades only on output. Going silent when asked to optimise also hurts, because the interviewer cannot follow your thinking. Finally, many candidates cannot state the complexity of either approach, or they freeze on edge cases like zero, negatives, and signed versus unsigned shifts.
How is this AI interviewer different from a real TCS interviewer?
It behaves like a real TCS Digital technical interviewer: it asks one question at a time, always probes at least once before moving on, and never praises your answer mid-round. The difference is that it is available any time and gives you a transcript-backed scorecard afterwards naming the exact step you could not justify. It will not coach you during the round or name the algorithm for you, just as a real interviewer would not. It references what you draw on the whiteboard and pushes on loose complexity claims.
How is the scoring done in this practice round?
Your transcript is scored against role-specific dimensions: how clearly you reason about bit-level operations, whether you state and justify time and space complexity, how cleanly you handle number-system conversions and carry, your edge-case coverage on zero and negatives, and whether you keep narrating your thinking. The whiteboard is also scored by a vision pass, so your drawn bit patterns and the complexity you label matter. You see live progress markers tick off during the round, and the final report quotes specific moments rather than giving a single number.
What should I do in the first two minutes before I start?
Recall the core identity that n and n minus 1 clears the lowest set bit, and that a number XORed with itself is zero so duplicates cancel. Have your conversion steps ready: repeated division by two for decimal to binary, and grouping bits into nibbles of four for hexadecimal. Re-read the problem statement carefully before typing, since the judge grades only on the printed output format. Decide on a language with a strict compiler such as C, C plus plus, or Java. Plan to state complexity before optimising.
How do I handle the follow-up on signed versus unsigned shifts?
Explain that negatives are stored in two complement, where the most significant bit is the sign and the value is the ones complement plus one. A right shift on a signed negative number is arithmetic and copies the sign bit inward, while on an unsigned number it is logical and fills with zeros. That is why using a right shift to divide by two can give a surprising result on a negative number. If you are unsure, say what you do know about the sign bit and reason from there rather than guessing silently.
What does a strong answer sound like in this round?
A strong answer states the brute-force complexity, then says something like: instead of checking all thirty-two bits, I use that n and n minus 1 drops the lowest set bit, so the loop runs once per set bit, giving order of the number of set bits. For the single-number problem it explains that XOR of equal values is zero and XOR with zero leaves the value, so all pairs cancel and the lone element survives. It names an edge case, draws the bit pattern, and keeps talking the whole time so the interviewer can follow each step.
Why does the interviewer keep asking me to state time complexity?
Because at the Digital tier, knowing a trick is worth little if you cannot quantify what it buys you. The interviewer wants you to compare the brute-force loop, which is order of the number of bits, against the optimised version, which for Brian Kernighan is order of the number of set bits. Stating both shows you understand the actual gain rather than waving your hands. A loose claim like order one without justification gets pushed on. Practise saying the numerator of the work, not just the label, for both approaches.
Do I need to write fully working code or just explain the idea?
Both matter, but reasoning leads. The interviewer first wants you to talk through the approach and its complexity, then translate it into clean code on the canvas. On the real TCS judge your code is validated against test cases and you get partial marks per case cleared, so correctness and exact output format count. In this practice round, you are pushed to explain why each line is correct, for example why the mask is one shifted left by i to isolate the i-th bit, rather than producing code you cannot defend.

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.