![]() |
VOOZH | about |
Given integers L and R, find all numbers in range L to R whose digits are increasing-decreasing alternatively i.e. if the digits in the current number are d1, d2, d3, d4, d5 . . . then d1 < d2 > d3 < d4. . . must hold true.
Examples:
Input: L = 60, R = 100
Output: 67 68 69 78 79 89
Explanation: These numbers follow the increasing decreasing manner of digitsInput: L = 4, R = 12
Output: 4 5 6 7 8 9 12
Approach: Traverse all numbers in range L to R and find the numbers with given pattern of digits. Follow the steps mentioned below:
Below is the implementation of the above approach.
67 68 69 78 79 89
Time Complexity: O((R-L) * D) where D is the number of digits in R
Auxiliary Space: O(D)