EASYasked at 1 company

Shortest Subarray With OR at Least K I

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

Founder's read

You need to find the shortest subarray where the bitwise OR of all elements is at least K. It sounds simple until you realize OR doesn't shrink as you extend the window, which breaks the typical two-pointer pattern. At 42.8% acceptance, this problem catches candidates who skip the bit manipulation insight and try brute force. Mitsogo has asked it. If this hits your live OA and you blank on why standard sliding window fails here, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
EASY
Acceptance
43%

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

If this hits your live OA

Shortest Subarray With OR at Least K I 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 for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The trap is assuming a smaller subarray always has a smaller OR. Wrong. Adding elements increases OR (or keeps it the same), but removing elements from the left doesn't guarantee it decreases. That breaks the monotonic property sliding window relies on. The real pattern: iterate the right pointer, track which bits flip on, and use a greedy left-pointer reset when OR reaches K. You can also optimize by storing only unique OR values as you extend, since OR can only change O(log max value) times per position. Most candidates waste time on a two-pointer approach that doesn't work here. StealthCoder handles the bit manipulation bookkeeping and finds the minimum length without the false starts.

Pattern tags

The honest play

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

Shortest Subarray With OR at Least K I recycles across companies for a reason. It's easy-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 for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest Subarray With OR at Least K I interview FAQ

Why can't I use standard sliding window here?+

Sliding window assumes removing elements from the left decreases the result monotonically. OR doesn't work that way. Removing a bit doesn't turn it off unless all other elements in the window lack it. You need a different strategy: expand right, track bit changes, and reset left greedily when you hit K.

How do I know when to stop shrinking the left pointer?+

Stop shrinking once OR falls below K. The moment removing the leftmost element breaks the OR value, you've found the shortest subarray ending at your current right pointer. Record the length and move the right pointer forward.

What's the O(log max value) optimization about?+

As you extend right, OR can only gain new bits. Since integers have a fixed bit count, OR can change at most O(log max value) times before plateauing. Store unique OR values instead of checking every position. This keeps the inner loop tight and avoids redundant bit checks.

Is bit manipulation really required or can I brute force?+

Brute force (checking every subarray) works but times out on large inputs. At 42.8% acceptance, most failures are TLE, not WA. The bit optimization and greedy left-pointer reset are what separate AC from TLE.

How does this relate to the other bit manipulation topics?+

This combines Array iteration, Sliding Window mechanics (with a twist), and Bit Manipulation fundamentals. You're not just computing OR; you're understanding how bits behave under accumulation, which is core to problems involving bitwise operations at scale.

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