Hexaware Coding Round Questions with Solutions
Last updated 2026-11-19
These ten easy-to-medium problems practise the string and array techniques commonly used in IT services screening tests, with Python and Java solutions, complexity and mistakes. Hexaware has not published its test content, so this is practice, not a claimed paper.
Use it with Hexaware interview questions and how to crack the DSA coding round.
| Level | Easy to medium |
|---|---|
| Languages | Python and Java shown |
| Topics | Two pointers, windows, XOR, strings |
What these Hexaware-style problems cover
Hexaware does not publish its test content, and prep material for services-company tests describes easy to medium problems on strings and arrays, with extra weight on logic and SQL. The ten problems here are practice in that range: two pointers, sliding windows, bit tricks and in-place array edits. They are not claimed to come from any paper. If your track is testing, the same skills show up when you write test scripts and data-driven checks.
Habits that earn marks
- Read whether the problem asks for in-place work and respect it.
- Check the empty array and single-element cases first.
- Write the complexity next to your solution.
- Prefer simple code that is easy to verify over clever one-liners.
Hexaware Coding Round Questions with Solutions: questions with worked answers
1 Minimum insertions to make parentheses valid
easyScan with an open counter and a fix counter. A closing bracket with no open one needs an inserted opening bracket; leftover opens at the end each need a closing bracket. Complexity: O(n) time, O(1) space. Common mistakes: using a stack unnecessarily and forgetting leftover opening brackets.
pythondef min_add(s): open_, fix = 0, 0 for c in s: if c == '(': open_ += 1 elif open_: open_ -= 1 else: fix += 1 return fix + open_ print(min_add("())"), min_add("(((")) # 1 3javaclass Solution { static int minAdd(String s) { int open = 0, fix = 0; for (char c : s.toCharArray()) { if (c == '(') open++; else if (open > 0) open--; else fix++; } return fix + open; } }2 Excel column title from a number
mediumThis is base 26 without a zero digit. Subtract 1 before each division so A is 0 and Z is 25, take the remainder as the letter, divide by 26, and reverse the result. Complexity: O(log26 n) time. Common mistakes: using n % 26 without subtracting 1, which breaks at multiples of 26 (Z, AZ).
pythondef title(n): out = [] while n: n -= 1 out.append(chr(ord('A') + n % 26)) n //= 26 return ''.join(reversed(out)) print(title(1), title(26), title(27), title(701)) # A Z AA ZYjavaclass Solution { static String title(int n) { StringBuilder sb = new StringBuilder(); while (n > 0) { n--; sb.append((char) ('A' + n % 26)); n /= 26; } return sb.reverse().toString(); } }3 Reverse only the vowels in a string
easyTwo pointers move inward, each stopping at a vowel, then swap. Treat uppercase vowels too. Complexity: O(n) time, O(n) space for the character array. Common mistakes: reversing the whole string and ignoring case.
pythondef reverse_vowels(s): v, a = set("aeiouAEIOU"), list(s) i, j = 0, len(a) - 1 while i < j: if a[i] not in v: i += 1 elif a[j] not in v: j -= 1 else: a[i], a[j] = a[j], a[i]; i += 1; j -= 1 return ''.join(a) print(reverse_vowels("hello")) # hollejavaclass Solution { static String reverseVowels(String s) { char[] a = s.toCharArray(); int i = 0, j = a.length - 1; String v = "aeiouAEIOU"; while (i < j) { if (v.indexOf(a[i]) < 0) i++; else if (v.indexOf(a[j]) < 0) j--; else { char t = a[i]; a[i++] = a[j]; a[j--] = t; } } return new String(a); } }4 Segregate even and odd numbers, evens first
easyTwo pointers: advance the left while it holds an even, retreat the right while it holds an odd, and swap when both stop. In place and one pass. Complexity: O(n) time, O(1) space. Common mistakes: building two lists when in-place is asked and not preserving anything the statement requires (this version does not keep order).
pythondef segregate(a): l, r = 0, len(a) - 1 while l < r: if a[l] % 2 == 0: l += 1 elif a[r] % 2 == 1: r -= 1 else: a[l], a[r] = a[r], a[l] return a print(segregate([1, 2, 3, 4, 5, 6])) # [6, 2, 4, 3, 5, 1]javaclass Solution { static void segregate(int[] a) { int l = 0, r = a.length - 1; while (l < r) { if (a[l] % 2 == 0) l++; else if (a[r] % 2 != 0) r--; else { int t = a[l]; a[l] = a[r]; a[r] = t; } } } }5 Maximum average of any subarray of length k
easyCompute the sum of the first k elements, then slide: add the new element, subtract the one leaving, keep the maximum sum. Divide by k at the end. Complexity: O(n) time, O(1) space. Common mistakes: recomputing each window sum (O(n * k)) and initialising the maximum to 0 with negative numbers.
pythondef max_avg(a, k): s = sum(a[:k]); best = s for i in range(k, len(a)): s += a[i] - a[i - k] best = max(best, s) return best / k print(max_avg([1, 12, -5, -6, 50, 3], 4)) # 12.75javaclass Solution { static double maxAvg(int[] a, int k) { long s = 0; for (int i = 0; i < k; i++) s += a[i]; long best = s; for (int i = k; i < a.length; i++) { s += a[i] - a[i - k]; best = Math.max(best, s); } return (double) best / k; } }6 Single number where every other number appears twice
easyXOR all numbers: pairs cancel because x ^ x = 0 and x ^ 0 = x, leaving the unique number. Complexity: O(n) time, O(1) space. Common mistakes: using a hash map when constant space is requested and assuming the unique number is largest or smallest.
pythondef single(a): r = 0 for x in a: r ^= x return r print(single([4, 1, 2, 1, 2])) # 4javaclass Solution { static int single(int[] a) { int r = 0; for (int x : a) r ^= x; return r; } }7 Squares of a sorted array, in sorted order
mediumNegatives squared can be large, so the largest square is at one of the two ends. Fill the result from the back using two pointers, comparing absolute values. Complexity: O(n) time, O(n) space. Common mistakes: squaring and sorting (O(n log n), acceptable but not optimal) and filling from the front.
pythondef sorted_squares(a): n = len(a); res = [0] * n l, r = 0, n - 1 for i in range(n - 1, -1, -1): if abs(a[l]) > abs(a[r]): res[i] = a[l] ** 2; l += 1 else: res[i] = a[r] ** 2; r -= 1 return res print(sorted_squares([-4, -1, 0, 3, 10])) # [0, 1, 9, 16, 100]javaclass Solution { static int[] sortedSquares(int[] a) { int n = a.length, l = 0, r = n - 1; int[] res = new int[n]; for (int i = n - 1; i >= 0; i--) { if (Math.abs(a[l]) > Math.abs(a[r])) { res[i] = a[l] * a[l]; l++; } else { res[i] = a[r] * a[r]; r--; } } return res; } }8 Find all duplicates in an array of 1..n without extra space
mediumUse the sign of a[|x| - 1] as a visited marker: if it is already negative, |x| is a duplicate; otherwise negate it. Values must lie in 1..n. Complexity: O(n) time, O(1) extra space. Common mistakes: forgetting to take the absolute value of the current element and modifying input when it must stay intact (restore signs afterwards).
pythondef find_dups(a): out = [] for x in a: i = abs(x) - 1 if a[i] < 0: out.append(abs(x)) else: a[i] = -a[i] return out print(find_dups([4, 3, 2, 7, 8, 2, 3, 1])) # [2, 3]javaimport java.util.*; class Solution { static List<Integer> findDups(int[] a) { List<Integer> out = new ArrayList<>(); for (int x : a) { int i = Math.abs(x) - 1; if (a[i] < 0) out.add(Math.abs(x)); else a[i] = -a[i]; } return out; } }9 Isomorphic strings
mediumTwo strings are isomorphic if characters map one to one consistently. Keep two dictionaries (s to t and t to s) and check both directions at each position. Complexity: O(n) time, O(k) space. Common mistakes: checking only one direction, which accepts 'ab' to 'aa'.
pythondef isomorphic(s, t): if len(s) != len(t): return False a, b = {}, {} for x, y in zip(s, t): if a.setdefault(x, y) != y or b.setdefault(y, x) != x: return False return True print(isomorphic("egg", "add"), isomorphic("ab", "aa")) # True Falsejavaimport java.util.*; class Solution { static boolean isomorphic(String s, String t) { if (s.length() != t.length()) return false; Map<Character, Character> a = new HashMap<>(), b = new HashMap<>(); for (int i = 0; i < s.length(); i++) { char x = s.charAt(i), y = t.charAt(i); if (a.containsKey(x) && a.get(x) != y) return false; if (b.containsKey(y) && b.get(y) != x) return false; a.put(x, y); b.put(y, x); } return true; } }10 Merge a sorted array into another in place from the back
mediumWith nums1 having room at the end, fill from the largest positions: compare the last elements of each array and place the larger at the write index, moving backwards. No shifting is needed. Complexity: O(m + n) time, O(1) space. Common mistakes: merging from the front, which overwrites unread elements, and not copying the leftover of the second array.
pythondef merge(a, m, b, n): i, j, k = m - 1, n - 1, m + n - 1 while j >= 0: if i >= 0 and a[i] > b[j]: a[k] = a[i]; i -= 1 else: a[k] = b[j]; j -= 1 k -= 1 return a print(merge([1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3)) # [1, 2, 2, 3, 5, 6]javaclass Solution { static void merge(int[] a, int m, int[] b, int n) { int i = m - 1, j = n - 1, k = m + n - 1; while (j >= 0) { if (i >= 0 && a[i] > b[j]) a[k--] = a[i--]; else a[k--] = b[j--]; } } }
Frequently asked questions
Is Hexaware coding hard?
There is no published description; prep material for similar firms suggests easy to medium.
Do I need DSA for testing roles?
Basic programming and logic matter; deep DSA is less common.
Which languages should I know?
Python or Java are safe; check your test instructions.
Where are Hexaware notices?
On Hexaware's own careers site.
Related guides
- Hexaware Interview Questions for Freshers
- Array interview questions with worked solutions
- String interview questions with worked solutions
- Two pointers interview questions with worked solutions
- Bit manipulation interview questions with worked solutions
- Sliding window interview questions with worked solutions
More in Company Interview Questions
- Hexaware Interview Questions for Freshers
- Honeywell Coding Round Questions with Solutions
- Honeywell Interview Questions and Answers for India Engineering Roles
- HSBC coding round questions with solutions
- HSBC interview questions with answers (technology graduates)
- IBM coding round questions
- IBM interview questions and answers
- Info Edge (Naukri) Interview Questions with Answers
- Info Edge Coding Round Questions
- Infosys Coding Round Questions with Solutions
- Infosys Interview Questions for Freshers
- Intel Coding Round Questions with Solutions