Autocoder

Zensar Coding Round Questions with Solutions

Last updated 2026-11-19

These ten easy-to-medium problems practise the array and number logic common in IT services screening tests, with worked Python and Java solutions, complexity and the mistakes that cost marks. Zensar has not published its test content, so this is practice rather than a claimed paper.

Use it with Zensar interview questions and how to crack the DSA coding round.

LevelEasy to medium
LanguagesPython and Java shown
TopicsArrays, number logic, overflow, two pointers

What these Zensar-style problems cover

Zensar does not publish its test content, so we make no claim about a specific paper. These ten easy-to-medium problems are the kind of array, number and logic questions common in IT services screening tests: carries, in-place edits, overflow-aware arithmetic, two pointers and prefix sums. If your target test also includes SQL or aptitude, practise those separately; this set is only for the coding portion.

Checklist before you submit

Zensar Coding Round Questions with Solutions: questions with worked answers

  1. 1

    Plus one: add one to a number stored as a digit array

    easy

    Walk from the last digit: a 9 becomes 0 and the carry continues; any other digit is incremented and you return. If every digit was 9, prepend a 1. Complexity: O(n) time, O(1) extra space. Common mistakes: converting to an integer (overflow for long arrays) and forgetting the all-nines case.

    python
    def plus_one(d):
        for i in range(len(d) - 1, -1, -1):
            if d[i] < 9:
                d[i] += 1
                return d
            d[i] = 0
        return [1] + d
    print(plus_one([1, 2, 9]), plus_one([9, 9]))  # [1, 3, 0] [1, 0, 0]
    java
    class Solution {
        static int[] plusOne(int[] d) {
            for (int i = d.length - 1; i >= 0; i--) {
                if (d[i] < 9) { d[i]++; return d; }
                d[i] = 0;
            }
            int[] r = new int[d.length + 1];
            r[0] = 1;
            return r;
        }
    }
  2. 2

    Remove all occurrences of a value in place

    easy

    Keep a write index; copy each element not equal to the value forward, then return the new length. Order of kept elements is preserved. Complexity: O(n) time, O(1) space. Common mistakes: using remove() inside a loop over the same list and returning the old length.

    python
    def remove_element(a, val):
        w = 0
        for x in a:
            if x != val:
                a[w] = x; w += 1
        return w
    a = [3, 2, 2, 3]
    print(remove_element(a, 3), a[:2])  # 2 [2, 2]
    java
    class Solution {
        static int removeElement(int[] a, int val) {
            int w = 0;
            for (int x : a) if (x != val) a[w++] = x;
            return w;
        }
    }
  3. 3

    Valid mountain array

    easy

    Walk up while strictly increasing, then down while strictly decreasing. It is a mountain if the peak is neither the first nor the last index and the walk ends at the last index. Complexity: O(n) time, O(1) space. Common mistakes: allowing plateaus (equal neighbours) and accepting purely increasing or decreasing arrays.

    python
    def is_mountain(a):
        n, i = len(a), 0
        while i + 1 < n and a[i] < a[i + 1]: i += 1
        if i == 0 or i == n - 1: return False
        while i + 1 < n and a[i] > a[i + 1]: i += 1
        return i == n - 1
    print(is_mountain([0, 3, 2, 1]), is_mountain([1, 2, 3]))  # True False
    java
    class Solution {
        static boolean isMountain(int[] a) {
            int n = a.length, i = 0;
            while (i + 1 < n && a[i] < a[i + 1]) i++;
            if (i == 0 || i == n - 1) return false;
            while (i + 1 < n && a[i] > a[i + 1]) i++;
            return i == n - 1;
        }
    }
  4. 4

    Find the missing and the repeating number in 1..n

    medium

    Use the sum and sum of squares, or index marking. With sums: let S be the actual sum and P the actual sum of squares; with x repeated and y missing, x - y = S - n(n+1)/2 and x + y = (P - n(n+1)(2n+1)/6) / (x - y). Complexity: O(n) time, O(1) space. Common mistakes: division mistakes with integer types and assuming exactly one of each; state your assumption.

    python
    def missing_repeating(a):
        n = len(a)
        d = sum(a) - n * (n + 1) // 2                       # x - y
        e = sum(v * v for v in a) - n * (n + 1) * (2 * n + 1) // 6  # x^2 - y^2
        s = e // d                                           # x + y
        x = (d + s) // 2
        return x, x - d
    print(missing_repeating([4, 3, 6, 2, 1, 1]))  # (1, 5)
    java
    class Solution {
        static long[] missingRepeating(int[] a) {
            long n = a.length, d = 0, e = 0;
            for (int v : a) { d += v; e += (long) v * v; }
            d -= n * (n + 1) / 2;
            e -= n * (n + 1) * (2 * n + 1) / 6;
            long s = e / d, x = (d + s) / 2;
            return new long[]{x, x - d};
        }
    }
  5. 5

    Count numbers with an even number of digits

    easy

    For each number count its digits (len of its string, or a log-based count) and keep those with an even count. Values 10-99, 1000-9999 and so on qualify. Complexity: O(n * d) time, O(1) space. Common mistakes: using floating-point logarithms near powers of ten and treating zero specially without need.

    python
    def even_digits(a):
        return sum(1 for x in a if len(str(abs(x))) % 2 == 0)
    print(even_digits([12, 345, 2, 6, 7896]))  # 2
    java
    class Solution {
        static int evenDigits(int[] a) {
            int c = 0;
            for (int x : a) if (String.valueOf(Math.abs(x)).length() % 2 == 0) c++;
            return c;
        }
    }
  6. 6

    Reverse an integer, returning 0 on 32-bit overflow

    medium

    Pop digits with % 10 and push them with * 10 + digit, checking before each push whether the result would leave the 32-bit signed range. Python integers do not overflow, so check the bounds explicitly. Complexity: O(d) time, O(1) space. Common mistakes: testing overflow after it has already happened and mishandling negative remainders in Python (use abs and restore the sign).

    python
    def reverse_int(x):
        sign = -1 if x < 0 else 1
        x, r = abs(x), 0
        while x:
            r = r * 10 + x % 10
            x //= 10
        r *= sign
        return r if -2**31 <= r <= 2**31 - 1 else 0
    print(reverse_int(123), reverse_int(-120), reverse_int(1534236469))  # 321 -21 0
    java
    class Solution {
        static int reverse(int x) {
            long r = 0;
            while (x != 0) {
                r = r * 10 + x % 10;
                x /= 10;
                if (r > Integer.MAX_VALUE || r < Integer.MIN_VALUE) return 0;
            }
            return (int) r;
        }
    }
  7. 7

    Two Sum in a sorted array using two pointers

    easy

    Start pointers at both ends. If the sum is too large move the right pointer left; if too small move the left pointer right. Return when equal. Complexity: O(n) time, O(1) space. Common mistakes: using a hash map when the array is sorted and constant space is wanted, and returning 0-based versus 1-based indices inconsistently.

    python
    def two_sum_sorted(a, t):
        l, r = 0, len(a) - 1
        while l < r:
            s = a[l] + a[r]
            if s == t: return [l, r]
            if s < t: l += 1
            else: r -= 1
        return []
    print(two_sum_sorted([2, 7, 11, 15], 18))  # [1, 2]
    java
    class Solution {
        static int[] twoSumSorted(int[] a, int t) {
            int l = 0, r = a.length - 1;
            while (l < r) {
                int s = a[l] + a[r];
                if (s == t) return new int[]{l, r};
                if (s < t) l++; else r--;
            }
            return new int[0];
        }
    }
  8. 8

    Check whether an array is sorted and rotated

    medium

    Count positions where a[i] > a[(i + 1) % n]. A sorted array rotated any number of times has at most one such drop (including the wrap-around). Complexity: O(n) time, O(1) space. Common mistakes: not checking the wrap-around pair and rejecting a plain sorted array.

    python
    def check(a):
        n = len(a)
        drops = sum(1 for i in range(n) if a[i] > a[(i + 1) % n])
        return drops <= 1
    print(check([3, 4, 5, 1, 2]), check([2, 1, 3, 4]))  # True False
    java
    class Solution {
        static boolean check(int[] a) {
            int n = a.length, drops = 0;
            for (int i = 0; i < n; i++) if (a[i] > a[(i + 1) % n]) drops++;
            return drops <= 1;
        }
    }
  9. 9

    FizzBuzz with a custom rule table

    easy

    Loop from 1 to n. Build the output from a list of (divisor, word) pairs, concatenating all words whose divisor divides the number, and fall back to the number itself. This avoids the classic ordering bug. Complexity: O(n * rules) time. Common mistakes: testing divisibility by 3 or 5 before 15, which prints Fizz instead of FizzBuzz.

    python
    def fizzbuzz(n, rules=((3, "Fizz"), (5, "Buzz"))):
        out = []
        for i in range(1, n + 1):
            s = ''.join(w for d, w in rules if i % d == 0)
            out.append(s or str(i))
        return out
    print(fizzbuzz(15)[-3:])  # ['13', '14', 'FizzBuzz']
    java
    import java.util.*;
    class Solution {
        static List<String> fizzbuzz(int n) {
            List<String> out = new ArrayList<>();
            for (int i = 1; i <= n; i++) {
                String s = (i % 3 == 0 ? "Fizz" : "") + (i % 5 == 0 ? "Buzz" : "");
                out.add(s.isEmpty() ? String.valueOf(i) : s);
            }
            return out;
        }
    }
  10. 10

    Find the pivot index where left sum equals right sum

    easy

    Compute the total. Walk left to right keeping the left sum; the right sum is total minus left minus the current element. Return the first index where they match. Complexity: O(n) time, O(1) space. Common mistakes: using nested sums (O(n squared)) and forgetting that the pivot element itself is excluded from both sides.

    python
    def pivot(a):
        total, left = sum(a), 0
        for i, x in enumerate(a):
            if left == total - left - x: return i
            left += x
        return -1
    print(pivot([1, 7, 3, 6, 5, 6]), pivot([1, 2, 3]))  # 3 -1
    java
    class Solution {
        static int pivot(int[] a) {
            int total = 0, left = 0;
            for (int x : a) total += x;
            for (int i = 0; i < a.length; i++) {
                if (left == total - left - a[i]) return i;
                left += a[i];
            }
            return -1;
        }
    }

Frequently asked questions

How hard is the Zensar coding test?

Not published. Prep material for similar firms suggests easy to medium.

Do I need to know DSA deeply?

Arrays, strings and basic recursion cover most screening problems.

Which language is allowed?

Check your test instructions; Python and Java are widely supported.

Where are Zensar notices?

On Zensar's own careers site.

Related guides

More in Company Interview Questions

See all in this section