Reported June 2026
Amazonarray

Feasible Indices After Prefix/Suffix Reduction

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

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

All elements are distinct, and that one line in the statement is what makes this Amazon OA from June 2026 solvable in a single pass. You get an array, two reduction moves (keep a prefix's minimum, keep a suffix's maximum), and you return a binary string of feasible indices. n goes up to 2 * 10^5, so simulating the operations is out. It looks like a puzzle about operation order. It isn't. It's a prefix-minimum and suffix-maximum check in disguise. If you blank on the reduction argument mid-assessment, StealthCoder runs invisibly on your screen and hands you the approach, so one frozen minute doesn't sink the attempt.

The problem

Note: This problem is a duplicate of Feasible Indices After Reduction. The sighting dates have been merged into that version.
You are given an integer array arr of size n, where all elements are distinct.
You can perform the following operations any number of times:
Choose a non-empty prefix of the array and delete all elements except the minimum element of that prefix.
Choose a non-empty suffix of the array and delete all elements except the maximum element of that suffix.
After each operation, the remaining elements are concatenated to form a new array.
An index i is called feasible if it is possible to reduce the array to a single element [arr[i]] using the above operations.
Return a binary string of length n where:
1 means the index is feasible.
0 means the index is not feasible.

Function
getFeasibleIndices(arr: int[]) → String

Examples
Example 1
arr = [1, 3, 2, 5, 4]
return = "10011"

Constraints
1 <= n <= 2 * 10^5
1 <= arr[i] <= 10^6
All elements are distinct.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: index i is feasible exactly when arr[i] is a prefix minimum (smaller than everything to its left) or a suffix maximum (larger than everything to its right). Why it works. If arr[i] is a prefix minimum, collapse the right side with a suffix operation so only that side's maximum M remains. Then one prefix operation over i and M keeps the smaller, which is arr[i]. If arr[i] beats M, it's a suffix maximum anyway. The suffix maximum case is symmetric. If neither holds, a smaller element sits on the left and a larger one on the right, and they block each other. Check example 1, [1,3,2,5,4]: prefix minima give index 0, suffix maxima give indices 3 and 4, so the answer is 10011. Build it with one left-to-right scan and one right-to-left scan, O(n) time. The pitfall is brute-force simulation or recursion. If the proof feels shaky live, StealthCoder is your fallback for the clean version.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Feasible Indices After Prefix/Suffix 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Feasible Indices After Prefix/Suffix Reduction FAQ

What's the actual trick in Feasible Indices After Prefix/Suffix Reduction?+

An index is feasible if its value is a prefix minimum or a suffix maximum. Scan left to right tracking the running min, scan right to left tracking the running max, and mark 1 wherever either condition holds. Everything else is 0. That's the whole solution.

Why does the distinct-elements guarantee matter?+

With distinct values, comparisons are strict, so there are no ties to reason about. An element is either smaller than everything on its left or it isn't. You can use strict less-than and greater-than checks with no tie-breaking edge cases.

What time complexity does Amazon expect here?+

With n up to 2 * 10^5, you need O(n) or O(n log n). Two linear passes give O(n) time and O(n) space for the output string. Anything that simulates operations or tries all sequences will time out, so don't go down that road.

How do I verify my approach before submitting?+

Run the sample: [1,3,2,5,4] must return 10011. Then test n=1, which should return 1, a strictly increasing array where every index is a prefix minimum so all are 1, and a strictly decreasing array where every index is a suffix maximum so all are 1.

How should I prepare for this in 48 hours?+

Get comfortable with running-min and running-max scans, since many array problems reduce to them. Write this one from scratch twice, including the proof sketch for why the two conditions are necessary and sufficient. Then test edge cases like single elements and monotonic arrays. That's enough for this problem.

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

OA at Amazon?
Invisible during screen share
Get it