From an integer X representing a time duration in seconds produce a simplified string representation.
For example, given X=100, you should output:"1m40s"
Use the following abbreviation w,d,h,m,s to represent:
- 1w is 1 week
- 1d is 1 day
- 1h is 1 hour
- 1m is 1 minute
- 1s is 1 second
Only the two largest non-zero integers should be used. Round up the second unit if necessary
to produce only two units even though this might mean the output represents slightly more time than X seconds
Write a function
fun solution(X: Int): String
that, given an integer X, returns a string representing the duration
Examples:
- Given X=100, return "1m40s"
- Given X=7263, return "2hm2m". (7263s=2h1m3s, but this uses too many units, so we round the
second-largest unit up to 2h2m) - Given X=3605, return 1h5s