Blog/Pseudo Code Questions for Placements: Patterns and 20 Solved Examples

Pseudo Code Questions for Placements: Patterns and 20 Solved Examples

Twenty solved pseudo-code questions with traced output, the conventions tests follow, and a two-week practice plan for IT services placement tests.

Last updated: 13 October 2026 · By the Asuraa Team

Quick answer: Pseudo-code questions show a short language-neutral program and ask for its output, loop count or bug. They appear inside the technical sections of IT services tests: Accenture's assessment checks applied technical knowledge and coding, and Capgemini lists a coding or technical assessment. Solve them by tracing every variable line by line, assuming integer division and arrays starting at 0 unless stated.

Key takeaways

  • Pseudo-code questions ask for the output, loop count or bug in a short language-neutral program, testing precise code reading without a compiler.
  • Accenture's assessment checks logical reasoning, applied technical knowledge and coding, and Capgemini lists a coding or technical assessment that tests programming knowledge.
  • Unless a question says otherwise, assume integer division drops fractions, for loops include both bounds, and arrays start at index 0.
  • A loop that swaps arr[i] with arr[n-1-i] for every i reverses the array twice and leaves it unchanged, a common trap.
  • Clearing the lowest set bit with n = n & (n - 1) counts set bits, so 29 (binary 11101) gives 4.

What are pseudo-code questions in placement tests?

Pseudo-code questions show a short, language-neutral program and ask what it prints, how many times a loop runs, or which line has a bug. They test whether you can read code precisely, without needing a compiler. Indian IT services tests use them inside their technical sections: Accenture says its assessment checks logical reasoning, applied technical knowledge and coding (Accenture), Capgemini lists a coding or technical assessment that tests programming knowledge (Capgemini), and Cognizant's GenC 2026 page lists an aptitude and technical assessment (Cognizant). The AMCAT syllabus includes an Automata Fix module (7 questions in 20 minutes) where you fix logical or syntax errors in given code (AMCAT), which uses the same tracing skill.

None of these companies publishes a fixed count of pseudo-code questions, so treat them as a format to master, not a section with known marks. Company-specific guides: Capgemini hiring process and Accenture hiring process.

What conventions do pseudo-code questions follow?

Most follow C-like rules unless the question says otherwise:

  • Integer a means whole numbers, so 7 / 2 is 3 (fraction dropped).
  • a mod b (or %) is the remainder.
  • for (i = 1 to 5) includes both 1 and 5.
  • &, |, ^, <<, >> are bitwise AND, OR, XOR, left shift and right shift.
  • Arrays start at index 0 unless stated.

The method that never fails: draw a table with one column per variable and write a new row after every line that changes a value.

How do you solve loop questions? (Examples 1-4)

Count iterations exactly and update the table each pass.

Example 1

Integer a = 0
for (i = 1 to 5)
    a = a + i * i
end for
print a

Trace: a = 1, 5, 14, 30, 55. Output: 55.

Example 2

Integer n = 4096, s = 0
while (n > 0)
    s = s + n mod 10
    n = n / 10
end while
print s

Trace: digits taken from the right are 6, 9, 0, 4; s = 6, 15, 15, 19; n becomes 409, 40, 4, 0. Output: 19.

Example 3

Integer n = 1230, r = 0
while (n > 0)
    r = r * 10 + n mod 10
    n = n / 10
end while
print r

Trace: r = 0, 3, 32, 321 (the first step adds 0). Output: 321, not 0321, because the leading zero disappears.

Example 4

Integer c = 0
for (i = 1 to 4)
    for (j = i to 4)
        c = c + 1
print c

Trace: inner loop runs 4, 3, 2, 1 times. Output: 10.

How do you trace recursion questions? (Examples 5-9)

Write each call on a new line, indent for depth, and resolve from the deepest call upward.

Example 5

Integer fun(Integer n)
    if (n <= 1) return 1
    return n * fun(n - 2)
print fun(7)

Trace: 7 x fun(5) = 7 x 5 x fun(3) = 7 x 5 x 3 x fun(1) = 105. Output: 105.

Example 6

Integer calls = 0
Integer fib(Integer n)
    calls = calls + 1
    if (n <= 1) return n
    return fib(n - 1) + fib(n - 2)
print fib(5), calls

Trace: fib(5) = 5. Calls follow C(n) = 1 + C(n-1) + C(n-2) with C(0) = C(1) = 1, giving 1, 1, 3, 5, 9, 15. Output: 5 15.

Example 7

void show(Integer n)
    if (n == 0) return
    print n
    show(n - 1)
    print n
show(3)

Trace: prints 3, goes down to 2, then 1, hits 0, then unwinds printing 1, 2, 3. Output: 3 2 1 1 2 3.

Example 8

Integer gcd(Integer a, Integer b)
    if (b == 0) return a
    return gcd(b, a mod b)
print gcd(48, 18)

Trace: (48, 18) to (18, 12) to (12, 6) to (6, 0). Output: 6.

Example 9

Integer mul(Integer a, Integer b)
    if (b == 0) return 0
    return a + mul(a, b - 1)
print mul(4, 3)

Trace: 4 + 4 + 4 + 0. Output: 12.

How do you handle array questions? (Examples 10-13)

Write the array after every change; most traps come from overwritten values.

Example 10

Integer arr[5] = {3, 8, 1, 9, 4}
Integer max = arr[0], idx = 0
for (i = 1 to 4)
    if (arr[i] > max)
        max = arr[i]
        idx = i
print max, idx

Trace: max becomes 8 at i = 1, then 9 at i = 3. Output: 9 3.

Example 11

Integer arr[4] = {1, 2, 3, 4}
for (i = 1 to 3)
    arr[i] = arr[i] + arr[i - 1]
print arr[3]

Trace: array becomes {1, 3, 6, 10} because each step uses the already-updated previous value. Output: 10.

Example 12

Integer arr[4] = {1, 2, 3, 4}
for (i = 0 to 3)
    swap(arr[i], arr[3 - i])
print arr

Trace: i = 0 and 1 reverse the array to {4, 3, 2, 1}; i = 2 and 3 swap the same pairs back. Output: 1 2 3 4. The loop should stop at the middle.

Example 13

Integer arr[5] = {5, 1, 4, 2, 8}
for (j = 0 to 3)
    if (arr[j] > arr[j + 1])
        swap(arr[j], arr[j + 1])
print arr

Trace: one bubble-sort pass: swap 5 and 1, swap 5 and 4, swap 5 and 2, no swap with 8. Output: 1 4 2 5 8.

How do you solve string questions? (Examples 14-16)

Index every character first: position 0 is the first letter.

Example 14

String s = "PLACEMENT"
Integer v = 0
for each ch in s
    if (ch is 'A' or 'E' or 'I' or 'O' or 'U')
        v = v + 1
print v

Trace: A, E, E. Output: 3.

Example 15

String s = "PROGRAM", t = ""
for (i = 0 to length(s) - 1 step 2)
    t = t + s[i]
print t

Trace: indices 0, 2, 4, 6 give P, O, R, M. Output: PORM.

Example 16

String s = "CAT"
Integer total = 0
for each ch in s
    total = total + (ch - 'A' + 1)
print total

Trace: C = 3, A = 1, T = 20. Output: 24.

How do you solve bit-manipulation questions? (Examples 17-20)

Convert to binary first, then apply the operator bit by bit.

Example 17

Integer a = 12, b = 10
print a & b, a | b, a ^ b

Trace: 1100 and 1010 give AND 1000, OR 1110, XOR 0110. Output: 8 14 6.

Example 18

Integer x = 5
x = x << 2
Integer y = x >> 3
print x, y

Trace: left shift by 2 multiplies by 4 (20); right shift by 3 divides by 8, dropping the fraction (2). Output: 20 2.

Example 19

Integer n = 29, count = 0
while (n != 0)
    n = n & (n - 1)
    count = count + 1
print count

Trace: 29 is 11101; each step clears the lowest set bit: 28, 24, 16, 0. Output: 4.

Example 20

Integer arr[5] = {4, 7, 4, 9, 7}
Integer x = 0
for (i = 0 to 4)
    x = x ^ arr[i]
print x

Trace: equal values cancel under XOR, leaving the one unpaired value. Output: 9.

How should you practise pseudo code over two weeks?

Two weeks of 30 to 45 minutes a day is enough to become reliable.

DaysTopicDaily targetCheckpoint
1-2Loops, integer division, mod10 tracesDigit-sum and reverse with zero errors
3-4Nested loops and iteration counts10 tracesCount iterations without listing them
5-7Recursion, call counts, print order8 tracesExample 6 and 7 types correct
8-9Arrays and in-place updates10 tracesSpot the swap-twice trap
10-11Strings and character arithmetic10 tracesIndex-based questions correct
12-13Bitwise operators and shifts10 tracesConvert to binary in under 20 seconds
14Mixed timed set25 questions in 25 minutesAccuracy above 80%

Combine this with the aptitude test preparation guide, and see our interview preparation guide for the rounds after the test.

What do most guides on pseudo-code questions get wrong?

Most guides treat pseudo code as a separate, officially defined section with fixed marks for every company. The companies' own pages describe broader "technical" or "applied technical knowledge" assessments and leave the exact layout to your test invite. Prepare the skill, not a rumoured question count.

They also teach shortcuts before tracing. Shortcuts work until a question changes one detail, such as a loop that runs to the middle versus the end (Example 12) or a recursion that prints before and after the call (Example 7). Tracing every line in a variable table is slower for a week and faster for the rest of your placement season. For a broader foundation, our DSA preparation for placements covers the concepts behind these questions.

Related guides

FAQ

Which companies ask pseudo-code questions in placement tests?

Pseudo-code output questions commonly appear in the technical sections of IT services tests. Accenture says its assessment checks applied technical knowledge and coding, Capgemini lists a coding or technical assessment, and Cognizant's GenC lists an aptitude and technical assessment. None publishes a fixed pseudo-code question count, so confirm the format in your test invite.

What language are pseudo-code questions written in?

They use a neutral, C-like notation with words such as Integer, for, while, mod and print. Unless the question states otherwise, assume integer division drops fractions, for loops include both bounds, and arrays start at index 0. Anyone who knows basic C, C++, Java or Python can read them.

How do I avoid mistakes in recursion questions?

Write each call on its own line, indent by depth, and only compute return values once you reach the base case. Track anything printed before and after the recursive call separately, because print order changes when the print statement sits after the call. Counting calls follows the same tree.

How long should I spend per pseudo-code question?

Aim for about one minute per question once you are practised. In timed sets, skip anything that needs a full trace of more than about ten iterations, then return to it at the end. Speed comes from a clean variable table, not from guessing patterns.

Are bitwise operator questions common?

They appear often enough to prepare for. Learn AND, OR, XOR, left shift and right shift on small numbers in binary, and two standard tricks: x XOR x equals 0, and n AND (n minus 1) clears the lowest set bit. These cover most bit-manipulation output questions.

Is the AMCAT Automata Fix module the same as pseudo code?

Not exactly, but it uses the same skill. The AMCAT syllabus describes Automata Fix as fixing logical or syntax errors in given code or completing code by reusing functions, with 7 questions in 20 minutes. Tracing practice from pseudo-code questions directly helps you find those errors.

Final thoughts

Pseudo-code questions are some of the most learnable marks in a placement test: the rules are few, and a variable table removes guesswork. Work through these 20 examples until each trace is automatic, then mix in timed sets. When you are ready to apply, check your resume against a real fresher listing with the Asuraa resume reviewer.

Related articles

Share this article

Continue Reading

Data Science Career Paths

Explore different career trajectories in data science and find your perfect fit.

Read article →

Building Your DS Portfolio

Learn how to create projects that impress hiring managers and showcase your skills.

Read article →

Salary Negotiation Guide

Get the compensation you deserve with our proven negotiation strategies.

Review Your Resume →