Feasible Indices After Reduction
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
With n up to 10^5, simulating every possible prefix and suffix deletion for every index is dead on arrival. This Amazon OA question, reported in April 2026, looks like a game of choosing operations, but it collapses into a single linear scan over the array. You need a running minimum from the left and a running maximum from the right. If you blank on the reduction, StealthCoder runs invisibly during the live assessment and can hand you the scan. Know the shape first, though. The statement is long and the code is about fifteen lines.
The problem
You are given an integer array arr of size n. All elements of arr are distinct. You may perform either of the following operations any number of times: Choose a non-empty prefix of the current array and delete every element in that prefix except the minimum element of the prefix. Choose a non-empty suffix of the current array and delete every element in that suffix except the maximum element of the suffix. After each operation, the remaining elements are concatenated to form the new array. An index i is called feasible if it is possible to reduce the array to the single element [arr[i]]. Return a binary string of length n where the i-th character is '1' if index i is feasible, and '0' otherwise. Function feasibleIndicesAfterReduction(arr: int[]) → String Examples Example 1 arr = [1, 3, 2, 5, 4] return = "10011" The feasible values are 1, 5, and 4. They are the prefix minimum at index 0 or suffix maximums at indices 3 and 4. Example 2 arr = [4, 1, 3, 2] return = "1111" All four indices are feasible. Values 4 and 1 are prefix minima, while values 3 and 2 are suffix maxima. For example, after reducing prefix [4,1] to 1, value 3 can survive a reduction of suffix [3,2] and then the whole array. The same first step followed by reducing the whole remaining suffix can leave 2. Constraints 1 <= n <= 10^5 1 <= arr[i] <= 10^9 All values in arr are distinct.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that you never simulate anything. An index is feasible when its value is a prefix minimum (smaller than everything before it) or a suffix maximum (larger than everything after it). Both examples confirm this. In [1,3,2,5,4], only 1 is a prefix minimum, and 5 and 4 are suffix maxima, giving "10011". In [4,1,3,2], 4 and 1 are prefix minima while 3 and 2 are suffix maxima, so all four are feasible. Do one pass left to right tracking the min so far, mark the index if it's a new low, then one pass right to left tracking the max so far and mark new highs. That's O(n) time and O(n) for the output string. The common pitfall is using nested loops or recursion on the deletions, which times out at 10^5. Another is off-by-one on the first and last elements, which are always feasible. StealthCoder is your hedge if the live OA clock gets loud.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Feasible Indices After Reduction 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Feasible Indices After Reduction FAQ
What's the actual trick in Feasible Indices After Reduction?+
Skip the simulation. An index is feasible if its value is a strict prefix minimum or a strict suffix maximum. Scan left to right tracking the smallest value so far, then right to left tracking the largest so far. Mark '1' whenever you hit a new record in either direction. Everything else stays '0'.
How hard is this Amazon OA question really?+
The statement looks intimidating, but the solution is two linear passes. Difficulty is mostly in reading the operations and trusting the pattern instead of simulating. If you can write a running min and a running max, you can finish it. Check your logic against both examples before submitting.
Why does brute force fail here?+
Constraints go up to n = 10^5. Trying every sequence of prefix and suffix deletions per index explodes combinatorially, and even an O(n^2) check per-index approach is far too slow. The accepted solution has to be O(n) or O(n log n), and the two-pass scan is O(n).
Are the first and last indices always feasible?+
Yes. Index 0 is trivially a prefix minimum of its own one-element prefix, and index n-1 is trivially a suffix maximum of its own one-element suffix. In example 1, index 0 (value 1) and index 4 (value 4) both come out as '1'. Edge case n = 1 returns "1".
How do I prepare for this in 48 hours?+
Write the two-pass scan from memory once, then test it on both examples and on a strictly increasing and strictly decreasing array. Practice building the result as a character array and joining at the end. Also review monotonic running-min and running-max patterns generally, since Amazon reuses them in other forms.