Autocoder

Citi coding round questions with solutions

Last updated 2026-11-19

Citi technology assessments in India are commonly described as aptitude plus coding problems at easy to medium level. Core array, string, number and linked-list problems are what decide such a test, along with some SQL and CS MCQs. The ten problems below are practice in that style. None is a recalled question.

Each answer has the approach, complexity, the common mistake and runnable Python and Java. For interviews, see Citi interview questions.

StyleEasy to medium fundamentals: arrays, strings, numbers, lists, SQL
Languages herePython, Java, SQL
Problems8 coding, 1 SQL, 1 MCQ
LevelEasy to medium

How to approach this set

At this level, speed with the basics matters: you should be able to write binary search, two pointers and a sieve without hesitation. Practise until each takes under ten minutes including testing.

Always test the edges: an empty array, one element, all equal values and the largest input. See how to crack an online assessment and how to crack the aptitude test for the non-coding sections.

Citi coding round questions with solutions: questions with worked answers

  1. 1

    Check whether an integer is a palindrome without converting it to a string.

    easy

    Negative numbers and numbers ending in 0 (except 0 itself) are not palindromes. Reverse the second half of the digits by repeatedly moving the last digit of x onto a reversed number until the reversed half is at least as large as what is left of x. Then x equals the reversed half (even digit count) or equals it after dropping the middle digit (odd count). Time O(log10 n), space O(1). Reversing the whole number risks overflow in fixed-width integers.

    python
    def is_palindrome(x):
        if x < 0 or (x % 10 == 0 and x != 0):
            return False
        rev = 0
        while x > rev:
            rev = rev * 10 + x % 10
            x //= 10
        return x == rev or x == rev // 10
    java
    class Solution {
        static boolean isPalindrome(int x) {
            if (x < 0 || (x % 10 == 0 && x != 0)) return false;
            int rev = 0;
            while (x > rev) { rev = rev * 10 + x % 10; x /= 10; }
            return x == rev || x == rev / 10;
        }
    }
  2. 2

    Find the second largest distinct element in an array.

    easy

    One pass with two variables: first and second, both starting at negative infinity. For each value greater than first, shift first into second and update first; otherwise, if it is greater than second and different from first, update second. Time O(n), space O(1). Sorting is O(n log n) and also needs deduplication. Mistake: failing on duplicates of the maximum, and returning a sentinel when no second distinct value exists without saying so.

    python
    def second_largest(a):
        first = second = float('-inf')
        for x in a:
            if x > first:
                first, second = x, first
            elif first > x > second:
                second = x
        return None if second == float('-inf') else second
    java
    class Solution {
        static Integer secondLargest(int[] a) {
            long first = Long.MIN_VALUE, second = Long.MIN_VALUE;
            for (int x : a) {
                if (x > first) { second = first; first = x; }
                else if (x < first && x > second) second = x;
            }
            return second == Long.MIN_VALUE ? null : (int) second;
        }
    }
  3. 3

    Remove duplicates from a sorted array in place and return the new length.

    easy

    Two pointers: a write index marks the end of the unique prefix. For each element after the first, if it differs from the last unique value, write it at the next position. Time O(n), space O(1). The elements beyond the returned length do not matter. Mistake: using a set or a new list when the question requires in-place O(1) space, and forgetting that the input must be sorted for this to work.

    python
    def remove_duplicates(a):
        if not a:
            return 0
        w = 1
        for r in range(1, len(a)):
            if a[r] != a[w - 1]:
                a[w] = a[r]
                w += 1
        return w
    java
    class Solution {
        static int removeDuplicates(int[] a) {
            if (a.length == 0) return 0;
            int w = 1;
            for (int r = 1; r < a.length; r++)
                if (a[r] != a[w - 1]) a[w++] = a[r];
            return w;
        }
    }
  4. 4

    Binary search: return the index of a target in a sorted array, or -1.

    easy

    Keep low and high bounds; compare the middle element with the target and discard the half that cannot contain it. Time O(log n), space O(1). Compute the middle as low + (high - low) / 2 to avoid overflow in Java. The loop condition low <= high with high = mid - 1 and low = mid + 1 must be used consistently; mixing styles creates infinite loops. See binary search interview questions.

    python
    def binary_search(a, t):
        lo, hi = 0, len(a) - 1
        while lo <= hi:
            mid = lo + (hi - lo) // 2
            if a[mid] == t:
                return mid
            if a[mid] < t:
                lo = mid + 1
            else:
                hi = mid - 1
        return -1
    java
    class Solution {
        static int binarySearch(int[] a, int t) {
            int lo = 0, hi = a.length - 1;
            while (lo <= hi) {
                int mid = lo + (hi - lo) / 2;
                if (a[mid] == t) return mid;
                if (a[mid] < t) lo = mid + 1; else hi = mid - 1;
            }
            return -1;
        }
    }
  5. 5

    Reverse the order of words in a sentence, collapsing extra spaces.

    easy

    Split on whitespace (which drops leading, trailing and repeated spaces), reverse the list and join with a single space. Time O(n), space O(n). In Python, s.split() with no argument does the whitespace handling; in Java use trim and split with the regex \s+. The mistake is splitting on a single space, which leaves empty strings for repeated spaces. The in-place variant for a character array reverses the whole string and then each word.

    python
    def reverse_words(s):
        return ' '.join(reversed(s.split()))
    java
    import java.util.*;
    class Solution {
        static String reverseWords(String s) {
            String[] w = s.trim().split("\\s+");
            Collections.reverse(Arrays.asList(w));
            return String.join(" ", w);
        }
    }
  6. 6

    Count the primes below n using the Sieve of Eratosthenes.

    medium

    Mark every number as prime, then for each prime p up to the square root of n mark its multiples starting from p squared as composite. The count of unmarked numbers from 2 up to n - 1 is the answer. Time O(n log log n), space O(n). Starting the inner loop at p squared (not 2p) is an important optimisation since smaller multiples were already marked. Trial division for every number is O(n sqrt n).

    python
    def count_primes(n):
        if n < 3:
            return 0
        sieve = [True] * n
        sieve[0] = sieve[1] = False
        p = 2
        while p * p < n:
            if sieve[p]:
                for m in range(p * p, n, p):
                    sieve[m] = False
            p += 1
        return sum(sieve)
    java
    class Solution {
        static int countPrimes(int n) {
            if (n < 3) return 0;
            boolean[] comp = new boolean[n];
            int count = 0;
            for (int p = 2; p < n; p++) {
                if (!comp[p]) {
                    count++;
                    for (long m = (long) p * p; m < n; m += p) comp[(int) m] = true;
                }
            }
            return count;
        }
    }
  7. 7

    Compute the GCD and LCM of two positive integers.

    easy

    Euclid's algorithm: gcd(a, b) = gcd(b, a mod b) until b is 0. It runs in O(log min(a, b)) time. The LCM is a / gcd x b (divide first to reduce overflow), since gcd x lcm = a x b. Mistake: computing a x b / gcd in a fixed-width integer, which can overflow before the division. For more than two numbers, fold the function across the list.

    python
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    
    def lcm(a, b):
        return a // gcd(a, b) * b
    java
    class Solution {
        static long gcd(long a, long b) {
            while (b != 0) { long t = a % b; a = b; b = t; }
            return a;
        }
        static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    }
  8. 8

    Find the middle node of a singly linked list in one pass.

    easy

    Slow and fast pointers: slow moves one step, fast moves two. When fast reaches the end, slow is at the middle. For an even number of nodes this returns the second middle node when the loop condition is fast and fast.next. Time O(n), space O(1). Counting the length first needs two passes. The same technique is the first step of palindrome-list checks and merge sort on lists.

    python
    def middle(head):
        slow = fast = head
        while fast and fast.next:
            slow = slow.next
            fast = fast.next.next
        return slow
    java
    class Solution {
        static class ListNode { int val; ListNode next; }
        static ListNode middle(ListNode head) {
            ListNode slow = head, fast = head;
            while (fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; }
            return slow;
        }
    }
  9. 9

    SQL: show the highest-paid employee in each department.

    medium

    Join employees to a derived table of each department's maximum salary and keep matching rows; this returns ties as well, which is usually wanted. A window function with RANK = 1 gives the same result. Mention that a plain GROUP BY with a non-aggregated name column is invalid in standard SQL.

    sql
    SELECT e.dept_id, e.name, e.salary
    FROM Employee e
    JOIN (SELECT dept_id, MAX(salary) AS top FROM Employee GROUP BY dept_id) m
      ON e.dept_id = m.dept_id AND e.salary = m.top;
  10. 10

    MCQ: after one full pass of bubble sort (ascending) on [5, 1, 4, 2, 8], what does the array look like?

    easy

    Compare adjacent pairs from the left: (5,1) swap gives 1 5 4 2 8; (5,4) swap gives 1 4 5 2 8; (5,2) swap gives 1 4 2 5 8; (5,8) no swap. The result is [1, 4, 2, 5, 8]: the largest element has bubbled to its final place after one pass. After k passes, the last k elements are in position. A flag that records whether any swap happened lets bubble sort stop early, giving O(n) on sorted input.

Frequently asked questions

How hard is the Citi coding test?

It is commonly described as easy to medium, built on arrays, strings and basic algorithms.

Is there an aptitude section?

Some technology cycles are reported to include aptitude questions. Check your invitation.

Should I use Python or Java?

Either is fine. Pick the language where you are fastest and least likely to make syntax mistakes.

Are these the real questions?

No. They are original practice problems in the style of the topics the round commonly covers.

Related guides

More in Company Interview Questions

See all in this section