Tower Research Coding Round Questions With Solutions
Last updated 2026-11-19
Tower Research tests are commonly described as demanding: speed matters, the maths is nontrivial, and the problems reward knowing the right technique, from bit manipulation to dynamic programming on bitmasks. These eleven practice problems follow that character.
They are practice problems, not real papers. Each gives the idea, code, complexity and a typical mistake. For the interview side read Tower Research interview questions; for general pacing see how to crack a DSA coding round.
What to expect
Reports mention timed coding with two or three problems at medium to hard difficulty, plus quantitative questions. C++ is a natural choice for performance-sensitive problems, though platforms usually allow other languages.
Hiring status
We have no sourced Tower Research hiring dates, numbers or format details, so none are given here. Check the firm's own careers site for current roles. For test preparation in general, see how to crack the online assessment.
Tower Research Coding Round Questions With Solutions: questions with worked answers
1 Single number: every element appears twice except one. Find it.
easyXOR all elements. Equal pairs cancel because x XOR x is 0, and 0 XOR y is y. Time O(n), space O(1). Follow-up: two unique numbers; XOR all, take any set bit of the result to split the array into two groups, and XOR each group.
pythondef single(a): r = 0 for x in a: r ^= x return rcppint single(const std::vector<int>& a) { int r = 0; for (int x : a) r ^= x; return r; }2 Maximum XOR of two numbers in an array.
hardBuild a binary trie of the numbers, 31 bits deep. For each number, walk the trie preferring the opposite bit at each level, which maximises the XOR. Time O(31 n), space O(31 n). Mistake: using a nested loop, which is O(n squared).
pythondef max_xor(a): trie = {} for x in a: node = trie for b in range(30, -1, -1): node = node.setdefault((x >> b) & 1, {}) best = 0 for x in a: node, cur = trie, 0 for b in range(30, -1, -1): bit = (x >> b) & 1 if (1 - bit) in node: cur |= 1 << b node = node[1 - bit] else: node = node[bit] best = max(best, cur) return best3 Travelling salesman for n up to 16 (bitmask DP).
harddp[mask][i] is the minimum cost of a path that starts at city 0, visits the cities in mask and ends at i. Transition by adding an unvisited city j. Time O(2^n times n squared), space O(2^n times n). Mistake: forgetting that mask must always include city 0 and i.
pythondef tsp(dist): n = len(dist) INF = float('inf') dp = [[INF] * n for _ in range(1 << n)] dp[1][0] = 0 for mask in range(1 << n): for i in range(n): if dp[mask][i] == INF: continue for j in range(n): if not mask & (1 << j): nm = mask | (1 << j) dp[nm][j] = min(dp[nm][j], dp[mask][i] + dist[i][j]) full = (1 << n) - 1 return min(dp[full][i] + dist[i][0] for i in range(1, n))4 Expected value of a game: roll a die, you may roll again once. Optimal strategy?
mediumWork backward. With one roll left, the expected value is 3.5. So after the first roll, keep it if it exceeds 3.5 (i.e. 4, 5, 6), otherwise reroll. Expected value = (4+5+6)/6 + (3/6)(3.5) = 2.5 + 1.75 = 4.25. A programmatic version is a backward DP over remaining rolls.
pythondef game_value(rolls): ev = 3.5 for _ in range(rolls - 1): ev = sum(max(f, ev) for f in range(1, 7)) / 6 return ev5 Count the number of set bits for every number from 0 to n.
easyUse dp[i] = dp[i >> 1] + (i & 1): the count for i is the count for i shifted right by one plus its lowest bit. Time O(n), space O(n). Mistake: calling a popcount loop for every i, which is O(n log n).
pythondef count_bits(n): dp = [0] * (n + 1) for i in range(1, n + 1): dp[i] = dp[i >> 1] + (i & 1) return dp6 Longest subarray with sum at most K in an array of positive numbers.
mediumTwo pointers: expand right, adding to the sum, and move left while the sum exceeds K. Each index enters and leaves once: O(n). For arrays with negatives this fails; use prefix sums with a monotonic structure. Mistake: using the technique when negatives exist.
pythondef longest_at_most(a, k): left = s = best = 0 for right, x in enumerate(a): s += x while s > k: s -= a[left] left += 1 best = max(best, right - left + 1) return best7 Order book: maintain best bid and best ask under insert and cancel.
hardKeep two heaps (max-heap for bids, min-heap for asks) with lazy deletion: store orders in a dictionary by id and, when reading the top, pop heap entries whose order id no longer exists. Insert O(log n), cancel O(1), best price amortised O(log n). A balanced tree map per side gives clean O(log n) for everything.
pythonimport heapq class Book: def __init__(self): self.bids, self.asks, self.live = [], [], {} def add(self, oid, side, price): self.live[oid] = (side, price) if side == 'B': heapq.heappush(self.bids, (-price, oid)) else: heapq.heappush(self.asks, (price, oid)) def cancel(self, oid): self.live.pop(oid, None) def best_bid(self): while self.bids and self.bids[0][1] not in self.live: heapq.heappop(self.bids) return -self.bids[0][0] if self.bids else None def best_ask(self): while self.asks and self.asks[0][1] not in self.live: heapq.heappop(self.asks) return self.asks[0][0] if self.asks else None8 Number of subsets with a given sum.
mediumUse a one-dimensional knapsack counting DP: dp[s] is the number of subsets summing to s, with dp[0] = 1. For each number, iterate s downwards so each item is used once. Time O(n times target). Mistake: iterating upwards, which allows reuse and counts multisets.
pythondef count_subsets(a, target): dp = [1] + [0] * target for x in a: for s in range(target, x - 1, -1): dp[s] += dp[s - x] return dp[target]9 Find the missing positive integer in O(n) time and O(1) space.
hardPlace each value v in range 1..n at index v - 1 by swapping, ignoring out-of-range and duplicate values. Then scan for the first index i where a[i] is not i + 1. Each swap puts one value in its final place, so total swaps are at most n. Mistake: swapping with a[a[i]-1] but comparing the wrong element, causing an infinite loop on duplicates.
pythondef first_missing_positive(a): n = len(a) for i in range(n): while 1 <= a[i] <= n and a[a[i] - 1] != a[i]: j = a[i] - 1 a[i], a[j] = a[j], a[i] for i in range(n): if a[i] != i + 1: return i + 1 return n + 110 Fast modular exponentiation and the modular inverse.
mediumSquare and multiply: while the exponent is positive, multiply the result when the low bit is set, square the base, and halve the exponent. O(log e). For a prime modulus p, the inverse of a is pow(a, p - 2, p) by Fermat's little theorem. Mistake: overflow in C++ when multiplying two 32-bit residues; use 64-bit intermediates.
pythondef power(b, e, m): r = 1 b %= m while e: if e & 1: r = r * b % m b = b * b % m e >>= 1 return rcpplong long power(long long b, long long e, long long m) { long long r = 1; b %= m; while (e) { if (e & 1) r = r * b % m; b = b * b % m; e >>= 1; } return r; }
Frequently asked questions
Which language should I use for Tower Research tests?
Use what the platform allows and what you are fastest in. C++ and Python are both common for these problems.
How hard are the problems?
Commonly reported as medium to hard with quantitative flavour. The firm does not publish difficulty.
Do I need bit manipulation?
It is a useful, frequently reported technique. Practise XOR tricks and bitmask DP.
Can I get partial credit?
Platforms typically score by passing test cases, but follow the instructions given for your own test.
Related guides
More in Company Interview Questions
- Uber Coding Round Questions with Solutions in Python and Java
- Uber Interview Questions and Answers for SDE Roles
- UBS coding round questions with solutions
- UBS interview questions with answers (technology graduates)
- UST coding round questions
- UST interview questions and answers
- Virtusa coding round questions
- Virtusa interview questions and answers
- Visa coding round questions with solutions
- Visa interview questions with answers (software engineer, India)
- VMware Coding Round Questions with Solutions in Python and Java
- VMware Interview Questions and Answers for Systems and SDE Roles