Solved LeetCode program · 714 of 1,000
#0949 · Largest Time for Given Digits
Original English source
Keep a shared digits holding 1, 2, 3, and 4. Keep a shared order as an empty list of whole numbers. Keep a shared used holding 0, 0, 0, and 0. Keep a shared latest of 0. Keep a shared pieces as an empty list of text.
To pad with value (a whole number).
If value is less than 10.
Place "0" into pieces.
To assess. The first is item 0 of order. The second is item 1 of order. The third is item 2 of order. The fourth is item 3 of order. The one is item first of digits. The two is item second of digits. The three is item third of digits. The four is item fourth of digits. The hours is one times 10 plus two. The minutes is three times 10 plus four.
If hours is less than 24 and minutes is less than 60.
The total is hours times 60 plus minutes. If total is more than latest, set latest to total.
To take from spot (a whole number) with depth (a whole number). Place spot into order. Set item spot of used to 1. Arrange from depth plus 1. remove the last item from order. Set item spot of used to 0.
To arrange from depth (a whole number). If depth is 4, Assess, return. For every spot from 0 to 3, if item spot of used is 0, Take from spot with depth.
Arrange from 0. The hours is latest divided by 60. The minutes is latest modulo 60. Pad with hours. The hour piece is format whole number hours as text. Place hour piece into pieces. Place ":" into pieces. Pad with minutes. The minute piece is format whole number minutes as text. Place minute piece into pieces. The answer is join pieces with "". Show answer.
Expected stdout
23:41