Kth Greater Element Index to the Right
Updated
Problem statement
For each array position, scan strictly to its right and consider positions whose value is strictly greater than the current value.
Return the 1-based index of the kth such position in left-to-right encounter order, or -1 if fewer than k exist. Equal values do not qualify.
Function
kthGreaterIndexes(nums: int[], k: int) → int[]Examples
Example 1
nums = [2,4,0,9,6]k = 2return = [4,5,5,-1,-1]For value 2, the second greater position is 4; other positions are evaluated independently.
Example 2
nums = [3,1,5,2,4]k = 1return = [3,3,-1,5,-1]Return each next encountered greater position.
Example 3
nums = []k = 1return = []Empty input gives an empty result.
Constraints
0 <= nums.length <= 5000.1 <= k <= nums.lengthwhen the array is nonempty.
More Concentric AI interview questions
- Find the Intersection Node of Two Linked ListsOA · Seen Sep 2026
- Count Students Outside Their Sorted PositionsOA · Seen Aug 2026
- Maximum Profit Under a Bitwise OR LimitOA · Seen Aug 2026
- Minimum Weighted Manhattan Travel CostOA · Seen Aug 2026
- Rearrange a Linked List from Alternating EndsONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Payment Partner RoutingStripe · OAStripe interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Index of the Maximum After Left RotationsChubb · OAChubb interview questions
- Leaves Remaining After WindCresta · OACresta interview questions