MEDIUMasked at 1 company

Bitwise OR of All Subsequence Sums

A medium-tier problem at 65% community acceptance, tagged with Array, Math, Bit Manipulation. Reported in interviews at Zomato and 0 others.

Founder's read

Bitwise OR of All Subsequence Sums is the kind of problem that looks straightforward until you realize the naive approach will time out. You're asked to find the bitwise OR of every possible sum you can make from array subsequences. A brute force solution generates all 2^n subsequences, computes their sums, and ORs them together. That works for n=20, fails at n=30. Zomato has asked this. The acceptance rate sits at 65%, which means half the people who see it can't finish in time. If this problem hits your live assessment and the exponential solution doesn't pass, StealthCoder will surface the bit-focused trick in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
65%

Companies that ask "Bitwise OR of All Subsequence Sums"

If this hits your live OA

Bitwise OR of All Subsequence Sums is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The key insight is that you don't need to generate all subsequences. Instead, track which sums are reachable using bit manipulation and dynamic programming. At each step, as you consider adding a new element to the array, you can compute all possible new sums by combining it with previously reachable sums. The critical observation is that the answer is bounded by the sum of all array elements, and the number of distinct reachable sums is typically much smaller than 2^n. Use a set or boolean array to track reachable sums, iterate through the array once, and for each element, compute new sums by adding it to existing reachable sums. Finally, bitwise OR all reachable sums together. This reduces the problem from exponential to pseudo-polynomial time. Zomato tests candidates on whether they can recognize when brute force fails and shift to a DP-based enumeration strategy without timeout.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Bitwise OR of All Subsequence Sums recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Bitwise OR of All Subsequence Sums interview FAQ

Why does generating all 2^n subsequences fail?+

For n around 25 to 30, 2^n exceeds a few million operations, and modern judges timeout around that threshold. The problem setter knows this and expects you to recognize the bottleneck. Bit manipulation and DP optimization are required to pass large test cases.

How do I know which sums are actually reachable?+

Use dynamic programming. Start with an empty set of reachable sums. For each array element, iterate through all currently reachable sums and add the element to each one, inserting the new sums into your set. After processing all elements, all possible subsequence sums are in the set.

Is this really asked at Zomato?+

Yes. Zomato appears in the company data for this problem. The acceptance rate of 65% suggests it's moderately hard for their candidate pool, not a trivial warm-up but not extreme either.

How does the bit manipulation angle fit in?+

Bit manipulation is used in two ways: first, to efficiently compute the final bitwise OR of all reachable sums, and second, to understand that certain bit patterns will always appear once you can form enough distinct sums. Some candidates miss that you're not manipulating bits during sum generation, only at the end.

What's the actual time complexity after optimization?+

Pseudo-polynomial. If the sum of all elements is S, you have at most O(n*S) time and space. For bounded arrays, this beats 2^n exponential. The constraint on array size and values in the problem statement determines if this passes.

Want the actual problem statement? View "Bitwise OR of All Subsequence Sums" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.