Longest Well-Performing Interval
A medium-tier problem at 36% community acceptance, tagged with Array, Hash Table, Stack. Reported in interviews at Infosys and 0 others.
Longest Well-Performing Interval is a medium-difficulty problem that appears in Infosys assessments. With a 36% acceptance rate, it's a filtering question that breaks most candidates who don't spot the underlying pattern. The problem asks you to find the longest contiguous subarray where the count of high-performing days exceeds non-performing days. Most people try greedy or sliding window first and hit a wall. If this lands in your live OA and you blank on the trick, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Longest Well-Performing Interval"
Longest Well-Performing Interval 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 a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe core insight is to convert the problem into a prefix-sum variant: map each day to +1 or -1 based on performance, then hunt for the longest subarray with a positive sum. Brute force checking every subarray works for small inputs but times out. The real solution uses a hash table to track the first occurrence of each prefix sum. When you see a prefix sum again, the subarray between those two positions sums to zero, then you need one more day to break the tie. A monotonic stack approach also works but is overkill. The trick most candidates miss is recognizing this as a prefix-sum problem disguised as an interval problem. When you're stuck on the live assessment, StealthCoder surfaces the hash table solution immediately.
Pattern tags
You know the problem.
Make sure you actually pass it.
Longest Well-Performing Interval 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 a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Well-Performing Interval interview FAQ
Why does greedy or two-pointer fail here?+
Greedy assumes the longest interval with the right property expands monotonically. It doesn't. You can have a suboptimal interval early that blocks the real answer. Two-pointer has the same issue: the window doesn't shrink predictably. You need a global perspective, not a local one.
Is this really asked at Infosys?+
Yes, Infosys includes it in their assessments. At 36% acceptance, it's a strong filter. Most candidates either solve it in the first 5 minutes or spend 30 struggling. There's rarely a middle ground.
What's the core insight?+
Reframe it as a prefix-sum problem. Convert days to +1/-1, then find the longest subarray with sum greater than zero. Use a hash table to track the first occurrence of each prefix sum and count distances. This breaks the quadratic brute force.
How do Array and Hash Table topics connect here?+
The Array part is the input itself. The Hash Table stores prefix sums and their first indices. You iterate the array once, compute prefix sums on the fly, and look up past occurrences in the hash table. It's O(n) time because of the table lookup.
Do I need the monotonic stack approach?+
No. The hash table solution is cleaner and faster to code under pressure. Monotonic stack works too but is harder to reason through live. Stick with hash table unless you've drilled monotonic stack heavily.
Want the actual problem statement? View "Longest Well-Performing Interval" on LeetCode →