Tidy Number Checker
A tidy number is a number whose digits are in non-decreasing order. Your task is to determine if a given number is a tidy number. For this problem, you will need to define a function isTidy which takes an integer N and returns True if N is a tidy number and False otherwise.
[ 123 ]
Explanation. The digits 1, 2, and 3 are in non-decreasing order.
[ 321 ]
Explanation. The digits 3, 2, 1 are not in non-decreasing order.
[ 455 ]
Explanation. The digits 4, 5, and 5 are in non-decreasing order.
[ -162 ]
Explanation. Negative number but digits 1, 6, 2 are not in non-decreasing order (ignoring the negative sign).
[ 1111 ]
Explanation. All the digits are the same, thus are in non-decreasing order.
Follow-up: Can you extend this solution to work with numbers represented as strings for extremely large numbers, beyond standard number limits?
1. Numbers will be within the range of a normal 32-bit signed integer.\n2. The number can be positive, negative, or zero.
- Views
- 1