1830. Mixed-Radix Clock
A station clock counts in units that do not share one base: 60 seconds make a minute, 60 minutes make an hour, 24 hours make a day, and days keep counting without limit. A mixed-radix number has a different base at each position. radices[0] is the base of the lowest position, radices[1] is the base of the next one, and so on. The highest position has no limit.
Given value and radices, return the digits of value with the lowest position first. The first radices.length entries are each smaller than their radix, and the final entry holds whatever is left over, which can be large. The array therefore has radices.length + 1 entries. Aim for O(k) time, where k is radices.length.
Example 1
- Input:
- value = 100000, radices = [60,60,24]
- Output:
- [40,46,3,1]
- Explanation:
100000 seconds is 1 day, 3 hours, 46 minutes and 40 seconds, listed from the lowest position.
Example 2
- Input:
- value = 59, radices = [60,60,24]
- Output:
- [59,0,0,0]
- Explanation:
Only the lowest position is used.
Example 3
- Input:
- value = 31, radices = [2,2,2,2]
- Output:
- [1,1,1,1,1]
- Explanation:
31 is 1111 in binary, and the leftover quotient is 1.
Constraints
0 ≤ value ≤ 1015
1 ≤ radices.length ≤ 20
2 ≤ radices[i] ≤ 106
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(k)
- Space
- O(k)