MEDIUMasked at 1 company

Shortest Subarray With OR at Least K II

A medium-tier problem at 50% community acceptance, tagged with Array, Bit Manipulation, Sliding Window. Reported in interviews at Mitsogo and 0 others.

Founder's read

You're looking at a medium-difficulty bit manipulation problem that shows up in live assessments. The twist here is that OR values don't monotonically increase like sums do, which breaks naive sliding window. You're hunting for the shortest subarray where the bitwise OR of all elements reaches at least K. The acceptance rate sits just above 50%, meaning half the candidates who attempt it miss the pattern on first try. If you're prepping for Mitsogo or similar assessments, this one rewards understanding why standard two-pointer won't work and how to rebuild your window logic around OR properties. StealthCoder runs invisible during your assessment and surfaces a working solution the moment you stall on the approach.

Companies asking
1
Difficulty
MEDIUM
Acceptance
50%

Companies that ask "Shortest Subarray With OR at Least K II"

If this hits your live OA

Shortest Subarray With OR at Least K II 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The naive instinct is to apply sliding window like you would with sums: expand right until OR >= K, then shrink left. This fails because OR doesn't have the prefix property that sums have. Shrinking the left side doesn't guarantee the OR decreases. The actual solution uses a deque to track distinct OR values within the current window. Each new element either creates a new OR state or merges with existing ones. You iterate right, compute all unique ORs formed by the new element with previous elements in your deque, prune dominated states, then check if the best OR in the window is >= K. Track the minimum length whenever the condition holds. This avoids redundant recalculation and keeps your deque small. The Array and Sliding Window topics mask the real challenge: recognizing that OR requires a different state-management strategy than linear problems. StealthCoder catches this exact inflection point during a timed assessment, preventing the 10-minute detour into a dead-end optimization.

Pattern tags

The honest play

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

Shortest Subarray With OR at Least K II 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Subarray With OR at Least K II interview FAQ

Why doesn't standard sliding window work here?+

Sliding window assumes monotonicity: removing an element always decreases the aggregate value. OR doesn't work that way. Removing a left element from [3, 5, 6] changes OR from 7 to 7 (still 7). You can't decide to shrink based on the result, so you need a deque-based state tracker instead.

Is this actually asked in live assessments?+

Yes. It's reported from at least one major company conducting OAs. The 50% acceptance rate indicates it's a real differentiator. If you haven't seen the deque-with-OR pattern before, you'll likely time out or submit a brute force solution.

What's the key insight that makes this solvable?+

When you add a new element, it forms OR combinations with all previous elements in the window. Many of these combinations are redundant (dominated by a larger OR). Storing only the distinct, undominated OR values in a deque lets you query the best result in O(1) and avoid recalculating ORs you've already seen.

How does Bit Manipulation topic play into the solution?+

The OR operation itself is the bit manipulation. Understanding that OR of two numbers is always >= either single number, and that ORing a new element can only increase or maintain the result, helps you reason about which window states are worth keeping in your deque.

What happens if K is very large?+

If K requires bits that no element in the array has, the answer is -1. Your algorithm naturally returns -1 because no subarray will ever reach OR >= K. The deque approach still runs efficiently without special-casing.

Want the actual problem statement? View "Shortest Subarray With OR at Least K II" 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.