Count Decreasing Triplets
Updated
Problem statement
You are given an integer array nums. Count the triplets of positions (i, j, k) where i < j < k and nums[i] > nums[j] > nums[k].
In other words, pick three values, keeping their order in the array. They do not need to sit next to each other. Each value must be strictly smaller than the one before it, so equal values never count as going down. Return the number of such picks.
Function
countDecreasingTriplets(nums: int[]) → longExamples
Example 1
nums = [9,4,6,3,2]return = 7Written as values, the decreasing picks are (9,4,3), (9,4,2), (9,6,3), (9,6,2), (9,3,2), (4,3,2), and (6,3,2). That is seven picks, so the answer is seven.
Example 2
nums = [5,4,3,2]return = 4The array has 4 values and keeps going down, so every pick of 3 positions works. Each pick leaves out exactly one value, so there are 4 picks.
Example 3
nums = [3,3,2,1]return = 2Each of the two 3 values can start a pick followed by 2,1. The two 3s cannot be used together, because equal values do not count as going down. So there are two picks.
Constraints
0 <= nums.length <= 200000.-10^9 <= nums[i] <= 10^9.- The answer fits in a signed 64-bit integer.
More Airbnb Online Assessment questions
- Count Card Duel RoundsOA · Seen Nov 2026
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
- Progressive Banking SystemOA · Seen Nov 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
Similar questions at other companies
- Maximize Shipment Order by Sorting One WindowAmazon · OA
- Most Items Within Budget from a Start IndexHudson River Trading · OA
- Power Update After K-th Largest InsertionGoogle · OA
- Rebuild the Queue From Taller-in-Front CountsAdobe · PHONE SCREEN
- Crossed User Pairs on One DateRippling · ONSITE INTERVIEW
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEW
- Earliest Meeting Time for All EmployeesCapital One · OA
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Servers With No Requests in a Time WindowIBM · OA
- Maximum Escape Game ScoreMicrosoft · OA