Given a number n, the task is to count all rotations of the given number which are odd and even.
Input: n = 1234 Output: Odd = 2, Even = 2 Total rotations: 1234, 2341, 3412, 4123 Odd rotations: 2341 and 4123 Even rotations: 1234 and 3412 Input: n = 246 Output: Odd = 0, Even = 3
Efficient Approach: For large numbers, it is difficult to rotate and check whether it is odd or not for every rotation. Hence, in this approach, check the count of odd digits and even digits present in the number. These will be the answer to this problem.
Below is the implementation of the above approach:
Odd = 2 Even = 2
Time Complexity: O(n)
- Count rotations divisible by 4
- Count rotations divisible by 8
- Count rotations in sorted and rotated linked list
- Check if strings are rotations of each other or not | Set 2
- Generate all rotations of a number
- Maximum sum of i*arr[i] among all rotations of a given array
- Check if two numbers are bit rotations of each other or not
- Generating numbers that are divisor of their right-rotations
- Minimum rotations required to get the same string
- Find element at given index after a number of rotations
- Maximum contiguous 1 possible in a binary string after k rotations
- Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed
- Check if all rows of a matrix are circular rotations of each other
- Minimum rotations to unlock a circular lock
- Quickly find multiple left rotations of an array | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.