Reported September 2026
MakeMyTripprefix sum

Count Subarrays with Sum K

Reported by candidates from MakeMyTrip's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live MakeMyTrip OA. Under 2s to a working solution.
Founder's read

Strip away the wording and the MakeMyTrip question reported in September 2026 is a prefix sum problem in disguise. You count contiguous subarrays that add up to a target, and the array has negatives, so the obvious sliding window won't work. If you've got an OA invite and a day or two, this is the pattern to lock in. It's short once you see it, and it's a common trap for people who reach for two pointers. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank during the live OA, but the idea below is small enough to carry in your head.

The problem

Given an integer array numbers and an integer target, return the number of non-empty contiguous subarrays whose elements sum to target.
Subarrays with the same values at different positions count separately.

Function
countSubarraysWithSum(numbers: int[], target: int) → int

Examples
Example 1
numbers = [1,1,1]
target = 2
return = 2
The qualifying subarrays occupy indices [0,1] and [1,2].
Example 2
numbers = [1,-1,0]
target = 0
return = 3
The qualifying subarrays are [1,-1], [1,-1,0], and [0].

Constraints
1 <= numbers.length <= 100000
-10000 <= numbers[i] <= 10000
-10^9 <= target <= 10^9
The answer fits in a signed 32-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: let prefix[j] be the sum of the first j elements. A subarray (i, j] sums to target when prefix[j] - prefix[i] = target, so prefix[i] = prefix[j] - target. Walk the array once, keep a hash map of how many times each prefix sum has appeared, and at each step add map[current - target] to the answer. Seed the map with {0: 1} so subarrays starting at index 0 get counted. That's O(n) time and O(n) space. The pitfall is sliding window. It breaks because numbers can be negative, as in the [1,-1,0] example where the answer is 3. Another mistake is forgetting the seed entry or updating the map before the lookup, which matters when target is 0. The count fits in 32 bits, but use a wide integer anyway if your language makes it easy. If you freeze mid-assessment, StealthCoder can hand you this solution in real time.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Count Subarrays with Sum K cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as subarray sum equals k. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass MakeMyTrip's OA.

MakeMyTrip reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Subarrays with Sum K FAQ

What's the trick for Count Subarrays with Sum K?+

Use running prefix sums and a hash map of counts. At each index, look up how many earlier prefixes equal current sum minus target and add that to the answer. Seed the map with 0 mapped to 1 so subarrays starting at the first element count. One pass, linear time.

Why doesn't a sliding window work here?+

Sliding window needs a monotonic sum, which requires all non-negative values. This input allows negatives and zeros, so extending the window can lower the sum and shrinking can raise it. In Example 2, [1,-1,0] with target 0 gives 3, and a window approach would miss some of those.

How hard is this problem really for the MakeMyTrip OA?+

It's medium. The code is about ten lines, but you have to know the prefix sum plus hash map idea. If you've seen it, you finish in minutes. If you haven't, you'll probably try brute force or two pointers and get stuck on the n up to 100000 constraint.

What edge cases should I test before submitting?+

Test target 0 with zeros and cancelling pairs, like [1,-1,0]. Test a single element equal to target, all negatives, and a target that never appears. Check that the initial map entry is set before the loop. Also confirm you update the map after the lookup, not before.

How do I prepare for this in 48 hours?+

Write the prefix sum plus hash map solution from scratch twice, without peeking. Then trace Example 2 by hand and watch the map change. Spend remaining time on related ideas like running sums with modulo. Brute force with O(n^2) will time out at 100000, so don't settle for it.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with MakeMyTrip.

OA at MakeMyTrip?
Invisible during screen share
Get it