Capgemini Coding Round Questions with Solutions
Last updated 2026-11-19
Capgemini's coding or technical assessment for technical roles is described by the company as part of the fresher process but not published. These ten mid-level problems cover the patterns such tests are commonly reported to use, with Python and Java solutions, complexity and mistakes.
See Capgemini interview questions and how to crack the DSA coding round alongside.
| Level | Easy to medium, one hard |
|---|---|
| Languages | Python and Java shown |
| Topics | Heaps, stacks, hashing, DP, binary search |
What the Capgemini coding assessment looks like
Capgemini India's recruitment page says the fresher process can include a coding or technical assessment for technical roles, and that it does not publish the content. Prep material describes medium-level data-structure problems alongside aptitude and pseudocode sections, with difficulty varying by role and cycle. These ten problems cover that mid-range toolkit: heaps, stacks, hashing, two pointers, simple DP and binary search. They are practice in the style of those topics, not a recorded paper.
Patterns to master
- Monotonic stack for next-greater problems.
- Hash sets for sequences and membership.
- Two pointers on sorted or bounded data.
- One-dimensional DP with rolling variables.
- Binary search on arrays and on conditions.
Capgemini Coding Round Questions with Solutions: questions with worked answers
1 Kth largest element in an array
mediumKeep a min-heap of size K; push each number and pop when the size exceeds K. The heap's top is the Kth largest. Quickselect gives O(n) average if you can modify the array. Complexity: O(n log k) time, O(k) space. Common mistakes: sorting the whole array when n is huge, and using a max-heap of all n elements.
pythonimport heapq def kth_largest(a, k): h = [] for x in a: heapq.heappush(h, x) if len(h) > k: heapq.heappop(h) return h[0] print(kth_largest([3, 2, 1, 5, 6, 4], 2)) # 5javaimport java.util.*; class Solution { static int kthLargest(int[] a, int k) { PriorityQueue<Integer> h = new PriorityQueue<>(); for (int x : a) { h.add(x); if (h.size() > k) h.poll(); } return h.peek(); } }2 Merge two sorted linked lists
easyUse a dummy head and a tail pointer, appending the smaller of the two current nodes each time, then attach whichever list remains. Complexity: O(m + n) time, O(1) space. Common mistakes: forgetting the leftover list and losing the head by moving it.
pythonclass Node: def __init__(self, v, nxt=None): self.v, self.next = v, nxt def merge(a, b): d = t = Node(0) while a and b: if a.v <= b.v: t.next, a = a, a.next else: t.next, b = b, b.next t = t.next t.next = a or b return d.next n = merge(Node(1, Node(3)), Node(2, Node(4))) out = [] while n: out.append(n.v); n = n.next print(out) # [1, 2, 3, 4]javaclass Solution { static class Node { int v; Node next; Node(int v) { this.v = v; } } static Node merge(Node a, Node b) { Node d = new Node(0), t = d; while (a != null && b != null) { if (a.v <= b.v) { t.next = a; a = a.next; } else { t.next = b; b = b.next; } t = t.next; } t.next = a != null ? a : b; return d.next; } }3 Next greater element for each position
mediumUse a monotonic stack of indices whose values are waiting for a greater one. When the current value is larger than the stack top's value, pop and record the current value for it. Complexity: O(n) time, O(n) space. Common mistakes: using nested loops (O(n squared)) and pushing values instead of indices, which loses positions.
pythondef next_greater(a): res, st = [-1] * len(a), [] for i, x in enumerate(a): while st and a[st[-1]] < x: res[st.pop()] = x st.append(i) return res print(next_greater([4, 5, 2, 25])) # [5, 25, 25, -1]javaimport java.util.*; class Solution { static int[] nextGreater(int[] a) { int[] res = new int[a.length]; Arrays.fill(res, -1); Deque<Integer> st = new ArrayDeque<>(); for (int i = 0; i < a.length; i++) { while (!st.isEmpty() && a[st.peek()] < a[i]) res[st.pop()] = a[i]; st.push(i); } return res; } }4 Longest consecutive sequence
mediumPut all numbers in a set. For each number that has no predecessor (x - 1 not in the set), count upward while x + 1 exists. Each element is visited at most twice. Complexity: O(n) time, O(n) space. Common mistakes: sorting (O(n log n), acceptable but slower) and starting a count from every number, which degrades to O(n squared).
pythondef longest_consecutive(a): s, best = set(a), 0 for x in s: if x - 1 not in s: y = x while y + 1 in s: y += 1 best = max(best, y - x + 1) return best print(longest_consecutive([100, 4, 200, 1, 3, 2])) # 4javaimport java.util.*; class Solution { static int longestConsecutive(int[] a) { Set<Integer> s = new HashSet<>(); for (int x : a) s.add(x); int best = 0; for (int x : s) { if (s.contains(x - 1)) continue; int y = x; while (s.contains(y + 1)) y++; best = Math.max(best, y - x + 1); } return best; } }5 Check whether an integer is a palindrome without converting to a string
easyReverse only half the number: build the reversed half until it is at least as large as what remains. Compare, allowing a middle digit for odd lengths. Negative numbers and numbers ending in 0 (except 0) are not palindromes. Complexity: O(log n) time, O(1) space. Common mistakes: reversing the whole number (can overflow) and forgetting numbers like 10 that end in zero.
pythondef is_pal(x): if x < 0 or (x % 10 == 0 and x != 0): return False r = 0 while x > r: r = r * 10 + x % 10 x //= 10 return x == r or x == r // 10 print(is_pal(12321), is_pal(120), is_pal(1221)) # True False Truejavaclass Solution { static boolean isPal(int x) { if (x < 0 || (x % 10 == 0 && x != 0)) return false; int r = 0; while (x > r) { r = r * 10 + x % 10; x /= 10; } return x == r || x == r / 10; } }6 Maximum product subarray
mediumTrack both the maximum and minimum product ending at each position, since a negative number can turn the minimum into the maximum. Swap them when the current number is negative. Complexity: O(n) time, O(1) space. Common mistakes: tracking only the maximum, which fails on arrays such as [-2, 3, -4], and resetting incorrectly at zeros.
pythondef max_product(a): mx = mn = best = a[0] for x in a[1:]: if x < 0: mx, mn = mn, mx mx = max(x, mx * x) mn = min(x, mn * x) best = max(best, mx) return best print(max_product([2, 3, -2, 4]), max_product([-2, 3, -4])) # 6 24javaclass Solution { static int maxProduct(int[] a) { int mx = a[0], mn = a[0], best = a[0]; for (int i = 1; i < a.length; i++) { int x = a[i]; if (x < 0) { int t = mx; mx = mn; mn = t; } mx = Math.max(x, mx * x); mn = Math.min(x, mn * x); best = Math.max(best, mx); } return best; } }7 House robber: maximum money without robbing adjacent houses
mediumDP with two values: take = best if you rob this house, skip = best if you do not. At each house, new take = skip + money, new skip = max(take, skip). Complexity: O(n) time, O(1) space. Common mistakes: a greedy choice of every other house and wrong handling of arrays of length one or zero.
pythondef rob(a): take = skip = 0 for x in a: take, skip = skip + x, max(take, skip) return max(take, skip) print(rob([2, 7, 9, 3, 1])) # 12javaclass Solution { static int rob(int[] a) { int take = 0, skip = 0; for (int x : a) { int nt = skip + x, ns = Math.max(take, skip); take = nt; skip = ns; } return Math.max(take, skip); } }8 Container with the most water
mediumTwo pointers at both ends. The area is width times the shorter height; move the pointer at the shorter line inward, since moving the taller one cannot improve the area. Complexity: O(n) time, O(1) space. Common mistakes: moving the taller side and checking all pairs (O(n squared)).
pythondef max_area(h): l, r, best = 0, len(h) - 1, 0 while l < r: best = max(best, min(h[l], h[r]) * (r - l)) if h[l] < h[r]: l += 1 else: r -= 1 return best print(max_area([1, 8, 6, 2, 5, 4, 8, 3, 7])) # 49javaclass Solution { static int maxArea(int[] h) { int l = 0, r = h.length - 1, best = 0; while (l < r) { best = Math.max(best, Math.min(h[l], h[r]) * (r - l)); if (h[l] < h[r]) l++; else r--; } return best; } }9 Set matrix zeroes in place
hardUse the first row and first column as markers: record whether they themselves contain a zero, mark zeros in the rest in those slots, then zero cells based on the markers, and finally clear the first row and column if needed. Complexity: O(m * n) time, O(1) extra space. Common mistakes: zeroing while scanning, which spreads new zeros and wrecks later checks.
pythondef set_zeroes(m): R, C = len(m), len(m[0]) r0 = any(m[0][j] == 0 for j in range(C)) c0 = any(m[i][0] == 0 for i in range(R)) for i in range(1, R): for j in range(1, C): if m[i][j] == 0: m[i][0] = m[0][j] = 0 for i in range(1, R): for j in range(1, C): if m[i][0] == 0 or m[0][j] == 0: m[i][j] = 0 if r0: m[0] = [0] * C if c0: for i in range(R): m[i][0] = 0 return m print(set_zeroes([[1, 1, 1], [1, 0, 1], [1, 1, 1]])) # [[1,0,1],[0,0,0],[1,0,1]]javaclass Solution { static void setZeroes(int[][] m) { int R = m.length, C = m[0].length; boolean r0 = false, c0 = false; for (int j = 0; j < C; j++) if (m[0][j] == 0) r0 = true; for (int i = 0; i < R; i++) if (m[i][0] == 0) c0 = true; for (int i = 1; i < R; i++) for (int j = 1; j < C; j++) if (m[i][j] == 0) { m[i][0] = 0; m[0][j] = 0; } for (int i = 1; i < R; i++) for (int j = 1; j < C; j++) if (m[i][0] == 0 || m[0][j] == 0) m[i][j] = 0; if (r0) for (int j = 0; j < C; j++) m[0][j] = 0; if (c0) for (int i = 0; i < R; i++) m[i][0] = 0; } }10 Find a peak element in O(log n)
mediumA peak is greater than its neighbours. Binary search: if a[mid] < a[mid + 1], a peak lies to the right, otherwise at mid or to the left. This works for any array where neighbouring elements differ. Complexity: O(log n) time, O(1) space. Common mistakes: comparing with both neighbours and indexing out of range at the ends.
pythondef find_peak(a): lo, hi = 0, len(a) - 1 while lo < hi: mid = (lo + hi) // 2 if a[mid] < a[mid + 1]: lo = mid + 1 else: hi = mid return lo print(find_peak([1, 2, 1, 3, 5, 6, 4])) # 5javaclass Solution { static int findPeak(int[] a) { int lo = 0, hi = a.length - 1; while (lo < hi) { int mid = lo + (hi - lo) / 2; if (a[mid] < a[mid + 1]) lo = mid + 1; else hi = mid; } return lo; } }
Frequently asked questions
How hard is the Capgemini coding test?
Capgemini does not publish it; prep material suggests easy to medium. Role and cycle matter.
Which patterns should I practise?
Hashing, two pointers, stacks, heaps, simple DP and binary search cover most mid-level problems.
Do I need system design?
For fresher roles, no. It matters for experienced hires.
Where do I read about the process?
Read Capgemini's recruitment page and how to crack the Capgemini interview.
Sources
Related guides
More in Company Interview Questions
- Capgemini Interview Questions for Freshers
- Cisco Coding Round Questions with Solutions in Python and Java
- Cisco Interview Questions and Answers: Networking and SDE Roles
- Citi coding round questions with solutions
- Citi interview questions with answers (technology analyst)
- ClearTax Coding Round Questions
- ClearTax Interview Questions with Answers
- Coforge Coding Round Questions with Solutions
- Coforge Interview Questions for Freshers
- Cognizant Coding Round Questions with Solutions
- Cognizant Interview Questions for Freshers
- CRED Coding Round Questions with Solutions