Count Later Lower Readings
Updated
Problem statement
A sensor stores one reading per hour, in order, in the array nums. For each hour i, count the hours j with j > i whose reading is strictly lower: nums[j] < nums[i]. A later reading equal to nums[i] does not count.
Return a list counts of the same length as nums, where counts[i] is the count for hour i.
Function
countSmaller(nums: int[]) → List<Integer>Examples
Example 1
nums = [3,7,-2,7,5,0]return = [2,3,0,2,1,0]After 3 come -2 and 0, which are lower: 2. After the first 7 come -2, 5 and 0: 3 (the second 7 is equal, so it does not count). After -2 nothing is lower: 0. After the second 7 come 5 and 0: 2. After 5 comes 0: 1. The last reading has nothing after it: 0.
Example 2
nums = [9,9,9]return = [0,0,0]Every later reading is equal, not lower, so every count is 0.
Example 3
nums = [1000000000,-1000000000,0,0]return = [3,0,0,0]All three later readings are below 1000000000, so the first count is 3. Nothing is below -1000000000. The first 0 is followed by another 0, which is equal, so its count is 0.
Constraints
1 <= nums.length <= 3000-10^9 <= nums[i] <= 10^9
More Rippling Onsite Interview questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delivery Cost TrackerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Maximum Currency Conversion Along a Simple PathPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent WordsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Future-Effective Employee SalaryONSITE INTERVIEW · Seen Aug 2026
- Filter and Sort Scheduled TasksONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Minimum Operations to Make an Array ContinuousAmazon · ONSITE INTERVIEW
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Count Points in Each Boundary IntervalBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
- Room Occupancy at Query TimesWhatNot · ONSITE INTERVIEWWhatNot interview questions
- HTTP Log QueriesDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Smallest Common Integer in Sorted ListsMotive · ONSITE INTERVIEWMotive interview questions
- Sliding Window MedianAuxoAI · OA
Interview reports that mention this question
Rippling interview experiences
- Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)