Dive log limits
MediumOnline Assessment
Check a dive shop's logbook against its no-decompression limit table and list the dives that went over.
table is a list of [maxDepth, limit] rows sorted by increasing maxDepth, both in whole units (metres and minutes). The base limit for a dive at depth d comes from the first row with maxDepth >= d: the table is never interpolated and never rounded down, a dive at 19 m uses the row for 21 m. A dive deeper than the last row is too deep, whatever its time.
dives lists the logbook entries as [diver, start, depth, minutes], in no particular order: the diver's name, the start time in minutes since the shop opened, the maximum depth, and the dive's total time. A diver's dives never overlap and never start at the same minute.
Divers who dive again soon carry leftover nitrogen. For each dive that is not a diver's first, look at that diver's previous dive (by start time) and compute the surface interval start - (previousStart + previousMinutes):
- under 60: deduct half of the previous dive's
minutes, rounded up, from the base limit; - 60 to 179: deduct a quarter of the previous dive's
minutes, rounded up; - 180 or more: no deduction.
The adjusted limit is the base limit minus the deduction, but never below 0. Only the immediately previous dive matters, and it counts even if it was itself over its limit or too deep. A dive is over when minutes is greater than its adjusted limit; being exactly at the limit is fine.
Input: table and dives.
Output: a list of strings for the dives that broke a limit, ordered by start (ties by diver name in ordinary string order): "<diver>@<start>: too deep", or "<diver>@<start>: over by <n>" where n is minutes minus the adjusted limit. Return an empty list if every dive is fine.
Example 1
- Input:
- [[[18,56],[24,39],[30,25]],[["Ines",0,17,50],["Ines",70,22,30],["Omar",10,31,5]]]
- Output:
- ["Omar@10: too deep","Ines@70: over by 16"]
- Explanation
- Depths round up to the next table row. Ines dives at 17 m: the 18 m row gives 56 minutes, and 50 is fine. Her second dive starts at 70, so the surface interval is 70 - (0 + 50) = 20, under 60, deducting half of 50 = 25. At 22 m the 24 m row gives 39, adjusted to 14, and 30 minutes is over by 16. Omar's dive at 31 m is deeper than the last row (30 m), so it is too deep.
Example 2
- Input:
- [[[12,70],[18,50],[30,30],[40,15]],[["Bo",100,40,15],["Rae",100,18,45],["Rae",0,14,30],["Rae",400,30,20],["Bo",0,9,40]]]
- Output:
- ["Bo@100: over by 10","Rae@100: over by 3"]
- Explanation
- Dives arrive unsorted, so each diver's history must be ordered by start. Rae dives at 0, 100 and 400. At 100 the surface interval is 100 - 30 = 70, so a quarter of 30 rounded up (8) is deducted: the 18 m row gives 50, adjusted to 42, and 45 minutes is over by 3. At 400 the interval is 260, no deduction, and 20 minutes is within the 30-minute limit. Bo's second dive at 100 has a surface interval of exactly 60 after a 40-minute dive (a quarter, 10): the 40 m row gives 15, adjusted to 5, so 15 minutes is over by 10. Both flagged dives start at 100, so Bo comes before Rae.
Example 3
- Input:
- [[[18,60],[27,30]],[["Cy",0,18,7],["Cy",67,18,59]]]
- Output:
- ["Cy@67: over by 1"]
- Explanation
- A dive at exactly 18 m uses the 18 m row (60 minutes). Cy's second dive has a surface interval of exactly 67 - 7 = 60, so the quarter rule applies: a quarter of 7 rounded up is 2, giving an adjusted limit of 58. At 59 minutes the dive is over by 1. Cy's first dive (7 minutes) is fine and is not listed.
Constraints
1 <= table.length <= 20,maxDepthstrictly increasing andlimitpositive0 <= dives.length <= 1,0001 <= depth <= 100,1 <= minutes <= 300,0 <= start <= 100,000- diver names are 1 to 12 letters