Median of Parsed Integer Strings
Updated
Problem statement
You are given a nonempty array values of integers written as strings, each in the one standard base-10 form: a minus sign for negatives, no leading zeros, no plus sign. Turn every string into a number and return the median as a double.
Keep duplicates. If the number of values is odd, the median is the middle value after sorting. If it is even, the median is the average of the two middle values.
Dictionary follow-up
Once the direct version works, explain or write a second way to get the same answer. Use a dictionary that maps each parsed integer to how many times it appears. Find the median positions by walking through the keys in increasing numeric order.
Function
parsedMedian(values: String[]) → doubleExamples
Example 1
values = ["10","2","7"]return = 7.0Parsing and sorting gives [2, 7, 10]. The single middle value is 7.
Example 2
values = ["-5","20","3","8"]return = 5.5The sorted values are [-5, 3, 8, 20]. The two middle values are 3 and 8, so the median is (3 + 8) / 2 = 5.5.
Example 3
values = ["4","4","4","9","12","12"]return = 6.5Duplicates remain in the multiset. The middle positions contain 4 and 9, whose arithmetic mean is 6.5.
Constraints
1 <= values.length <= 2 * 10^5.- Every
values[i]is the canonical base-10 representation of an integer in[-10^4, 10^4]. - Zero is written as
"0"; nonzero values have no leading zeros, and positive values have no leading plus sign.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Find Accounts with Negative Converted BalancesStripe · PHONE SCREENStripe interview questions
- Numbers With Exactly Two Square-Sum RepresentationsGoogle · PHONE SCREENGoogle interview questions
- Implement k-Nearest NeighborsApple · PHONE SCREENApple interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
- House ValuationIMC Trading · OAIMC Trading interview questions
- Config Store with Priority OverridesMicrosoft · PHONE SCREENMicrosoft interview questions
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions