Publicis Sapient Coding Round Questions
Last updated 2026-11-19
Online assessments at consultancies usually mix aptitude, technical MCQs and a few coding problems of easy to medium difficulty, followed by interviews that expect a working solution and a clear explanation. This page offers twelve practice problems in that style, with Java solutions (plus one in Python and two in SQL), complexity and the mistakes that commonly cost marks.
They are practice problems in the style of such rounds, not copies of any test. Use them with Publicis Sapient interview questions and the DSA coding round guide.
| Languages here | Java, Python, SQL |
|---|---|
| Themes | Arrays, trees, binary search, intervals, caching, SQL |
| Level | Easy to medium with two hard |
Working through a problem in an interview
Interviewers at client-service firms care that you reach a correct solution and can walk through it. Clarify input limits, write a simple version first, explain complexity and then improve if time allows. Dry-run your code on a tiny example out loud before saying you are done.
Hiring status
We hold no sourced facts about Publicis Sapient tests, drives, openings or cutoffs, so none are stated. Use the company's own careers site for current information.
Publicis Sapient Coding Round Questions: questions with worked answers
1 Rotate an array to the right by k positions in place.
easyReverse the whole array, then reverse the first k elements and then the rest, after reducing k modulo n. O(n) time, O(1) space. Mistake: forgetting k % n (k can exceed n) and using an extra array when constant space is requested.
javapublic class Rotate { public static void rotate(int[] a, int k) { int n = a.length; if (n == 0) return; k %= n; reverse(a, 0, n - 1); reverse(a, 0, k - 1); reverse(a, k, n - 1); } private static void reverse(int[] a, int i, int j) { while (i < j) { int t = a[i]; a[i++] = a[j]; a[j--] = t; } } }2 Valid anagram: are two strings made of the same characters?
easyCount characters of the first string up and the second down in a 26-element array (or a map for Unicode) and check all zeros, after comparing lengths. O(n) time, O(1) space for lowercase letters. Mistake: sorting both strings, which is correct but O(n log n), and ignoring case or spaces if the statement says to.
javapublic class Anagram { public static boolean isAnagram(String a, String b) { if (a.length() != b.length()) return false; int[] cnt = new int[26]; for (int i = 0; i < a.length(); i++) { cnt[a.charAt(i) - 'a']++; cnt[b.charAt(i) - 'a']--; } for (int x : cnt) if (x != 0) return false; return true; } }3 Search in a rotated sorted array (no duplicates).
mediumBinary search: at each step one half is sorted; check whether the target lies in the sorted half and discard the other. O(log n) time, O(1) space. Mistake: using strict comparisons that skip the equal case in the sorted-half test (nums[lo] <= nums[mid]), which breaks when lo equals mid.
javapublic class Rotated { public static int search(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[lo] <= a[mid]) { if (a[lo] <= t && t < a[mid]) hi = mid - 1; else lo = mid + 1; } else { if (a[mid] < t && t <= a[hi]) lo = mid + 1; else hi = mid - 1; } } return -1; } }4 Level-order traversal of a binary tree, returning a list of levels.
mediumBFS with a queue; for each level, process exactly the number of nodes currently in the queue and collect their values, enqueueing children. O(n) time, O(width) space. Mistake: not capturing the queue size before the inner loop, which mixes levels.
javaimport java.util.*; class TreeNode { int val; TreeNode left, right; TreeNode(int v) { val = v; } } public class Levels { public static List<List<Integer>> levels(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); if (root == null) return res; Deque<TreeNode> q = new ArrayDeque<>(); q.add(root); while (!q.isEmpty()) { int size = q.size(); List<Integer> level = new ArrayList<>(); for (int i = 0; i < size; i++) { TreeNode n = q.poll(); level.add(n.val); if (n.left != null) q.add(n.left); if (n.right != null) q.add(n.right); } res.add(level); } return res; } }5 Longest palindromic substring.
mediumExpand around each centre (both odd and even centres), tracking the longest. O(n^2) time, O(1) space. Manacher's algorithm gets O(n) but is rarely required. Mistake: forgetting even-length palindromes such as "abba", which need a centre between two characters.
javapublic class Palin { public static String longest(String s) { int start = 0, best = 0; for (int c = 0; c < s.length(); c++) { for (int w = 0; w < 2; w++) { int l = c, r = c + w; while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) { l--; r++; } if (r - l - 1 > best) { best = r - l - 1; start = l + 1; } } } return s.substring(start, start + best); } }6 Merge intervals (for example overlapping meeting bookings).
mediumSort by start, then walk and extend the last interval when the next starts at or before its end, keeping the maximum end. O(n log n). Mistake: using the next interval's end instead of the maximum, which breaks on nested intervals.
javaimport java.util.*; public class MergeIv { public static int[][] merge(int[][] iv) { Arrays.sort(iv, (a, b) -> Integer.compare(a[0], b[0])); List<int[]> out = new ArrayList<>(); for (int[] cur : iv) { if (out.isEmpty() || cur[0] > out.get(out.size() - 1)[1]) out.add(cur); else out.get(out.size() - 1)[1] = Math.max(out.get(out.size() - 1)[1], cur[1]); } return out.toArray(new int[0][]); } }7 Kth largest element in an array.
mediumKeep a min-heap of size k; after processing all elements the root is the answer. O(n log k) time, O(k) space. Quickselect gives O(n) average. Mistake: sorting the entire array when k is small, and using a max-heap of all elements where a size-k min-heap suffices.
javaimport java.util.*; public class Kth { public static int kthLargest(int[] a, int k) { PriorityQueue<Integer> pq = new PriorityQueue<>(); for (int x : a) { pq.offer(x); if (pq.size() > k) pq.poll(); } return pq.peek(); } }8 Stack that supports push, pop and retrieving the minimum in O(1).
mediumKeep a second stack of minima: push the new value onto it when it is less than or equal to the current minimum, and pop it when the popped value equals the minimum. All operations O(1), O(n) extra space. Mistake: using strict less-than when pushing, which loses track of duplicate minima.
pythonclass MinStack: def __init__(self): self.s, self.m = [], [] def push(self, x): self.s.append(x) if not self.m or x <= self.m[-1]: self.m.append(x) def pop(self): x = self.s.pop() if x == self.m[-1]: self.m.pop() return x def min(self): return self.m[-1]9 Product of array except self, without division.
mediumFill an output array with prefix products, then multiply by a running suffix product in a second pass. O(n) time, O(1) extra space apart from the output. Mistake: dividing the total product by each element, which fails when the array contains zeros.
javapublic class Product { public static int[] exceptSelf(int[] a) { int n = a.length; int[] out = new int[n]; out[0] = 1; for (int i = 1; i < n; i++) out[i] = out[i - 1] * a[i - 1]; int suffix = 1; for (int i = n - 1; i >= 0; i--) { out[i] *= suffix; suffix *= a[i]; } return out; } }10 SQL: customers who placed orders in three consecutive months.
mediumReduce to distinct customer-month values, number them per customer, and compare each month with the month two rows later using LEAD. Simpler: self-join the distinct set on adding one and two months. Mistake: forgetting DISTINCT so that several orders in one month count as consecutive months.
sqlWITH m AS ( SELECT DISTINCT customer_id, DATE_TRUNC('month', ordered_at) AS mth FROM orders ) SELECT DISTINCT a.customer_id FROM m a JOIN m b ON b.customer_id = a.customer_id AND b.mth = a.mth + INTERVAL '1 month' JOIN m c ON c.customer_id = a.customer_id AND c.mth = a.mth + INTERVAL '2 month';11 SQL: products that have never been ordered.
mediumAnti-join: LEFT JOIN orders to products and keep rows where the order side is NULL, or use NOT EXISTS. Avoid NOT IN when the subquery column can contain NULL, because one NULL makes the whole predicate unknown and returns nothing.
sqlSELECT p.id, p.name FROM products p WHERE NOT EXISTS (SELECT 1 FROM order_items oi WHERE oi.product_id = p.id);12 LRU cache in Java using LinkedHashMap.
hardLinkedHashMap with accessOrder true keeps entries in access order; overriding removeEldestEntry evicts the least recently used when size exceeds capacity. Operations are O(1). It is not thread-safe, so wrap it with Collections.synchronizedMap for concurrent use. Mistake: leaving accessOrder false, which gives FIFO eviction instead of LRU.
javaimport java.util.*; public class LRU<K, V> extends LinkedHashMap<K, V> { private final int cap; public LRU(int cap) { super(16, 0.75f, true); this.cap = cap; } @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > cap; } }
Frequently asked questions
How hard is the coding round at consultancies like Publicis Sapient?
Reports for such firms describe easy to medium problems on arrays, strings, trees and basic SQL, with explanation counting as much as the code.
Should I use Java?
If you are applying for a Java role, yes. Otherwise use the language you are fastest in.
Are these real Publicis Sapient questions?
No. They are practice problems in the style of such rounds, not copies of any test.
Do they ask SQL?
Database questions are plausible for application roles. Practise joins, grouping, anti-joins and window functions.
How should I prepare in one week?
Cover arrays, strings, hashing, binary search, trees and intervals in turn, doing two problems a day and revising the patterns, then spend a day on SQL.
Related guides
More in Company Interview Questions
- Publicis Sapient Interview Questions with Answers
- PwC coding round questions
- PwC interview questions and answers
- Qualcomm Coding Round Questions with Solutions
- Qualcomm Interview Questions and Answers for India Software Roles
- Razorpay Coding Round Questions with Solutions
- Razorpay Interview Questions and Answers
- Salesforce Coding Round Questions with Solutions in Python and Java
- Salesforce Interview Questions and Answers for MTS and AMTS Roles
- Samsung Coding Round Questions with Solutions
- Samsung R&D Interview Questions and Answers for India Software Roles
- SAP Coding Round Questions with Solutions in Python and Java