Top Five Stock Records in a Date Range
Problem statement
Each row in records is [name,value,date]. Select records whose dates fall within startDate through endDate and return their top five records.
For this exercise, assume the date range includes both endpoints and each stock name appears in exactly one input record. Rank records by their raw integer value in descending order, then by case-sensitive ASCII stock name in ascending order. Do not combine records or calculate changes in value.
For this exercise, assume values are canonical nonnegative decimal integer strings and dates are valid zero-padded YYYY-MM-DD calendar strings. Return at most five full rows in ranking order, preserving their three original field strings. Return all qualifying rows if there are fewer than five, and an empty array if none qualify.
Function
topFiveStockRecords(records: String[][], startDate: String, endDate: String) → String[][]Examples
Example 1
records = [["A","10","2021-07-01"],["B","30","2021-07-02"],["C","30","2021-07-03"],["D","20","2021-07-04"],["E","40","2021-07-05"],["F","50","2021-07-06"],["G","999","2021-08-01"]]startDate = "2021-07-01"endDate = "2021-07-31"return = [["F","50","2021-07-06"],["E","40","2021-07-05"],["B","30","2021-07-02"],["C","30","2021-07-03"],["D","20","2021-07-04"]]This authored fixture excludes G by date, returns only five records, and orders equal values B before C.
Example 2
records = [["Beta","7","2021-07-15"],["Alpha","7","2021-07-15"],["Later","100","2021-07-16"]]startDate = "2021-07-15"endDate = "2021-07-15"return = [["Alpha","7","2021-07-15"],["Beta","7","2021-07-15"]]This authored equal-date range is inclusive and orders the two tied names lexicographically.
Example 3
records = [["Old","100","2020-12-31"],["New","0","2022-01-01"]]startDate = "2021-01-01"endDate = "2021-12-31"return = []This authored fixture has no qualifying records and returns an empty array.
Constraints
- For this exercise, assume
0 <= records.length <= 300; every row contains exactly three strings. - Names are unique, case-sensitive strings containing 1 through 20 ASCII letters or digits.
- For this exercise, assume values are canonical decimal strings for integers from
0through1000000. - For this exercise, assume all record dates and both endpoints are valid YYYY-MM-DD dates from 2000-01-01 through 2099-12-31, with startDate at most endDate.