Problem · Array
Feasible Indices After Prefix/Suffix Reduction
Learn this problemProblem statement
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:
1means the index is feasible.0means the index is not feasible.
Function
getFeasibleIndices(arr: int[]) → StringExamples
Example 1
arr = [1, 3, 2, 5, 4]return = "10011"Constraints
1 <= n <= 2 * 10^51 <= arr[i] <= 10^6- All elements are distinct.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026