Given an integer n, the task is to generate all the left shift numbers possible. A left shift number is a number that is generated when all the digits of the number are shifted one position to the left and the digit at the first position is shifted to the last.
Input: n = 123
Output: 231 312
Input: n = 1445
Output: 4451 4514 5144
- Assume n = 123.
- Multiply n with 10 i.e. n = n * 10 = 1230.
- Add the first digit to the resultant number i.e. 1230 + 1 = 1231.
- Subtract (first digit) * 10k from the resultant number where k is the number of digits in the original number (in this case, k = 3).
- 1231 – 1000 = 231 is the left shift number of the original number.
Below is the implementation of the above approach:
4451 4514 5144
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of rotations required to generate a sorted array
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Maximum sum of i*arr[i] among all rotations of a given array
- Check if all rows of a matrix are circular rotations of each other
- Print all possible rotations of a given Array
- Find element at given index after a number of rotations
- Number of strings which starts and ends with same character after rotations
- Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed
- Count rotations divisible by 4
- Check if two numbers are bit rotations of each other or not
- Quickly find multiple left rotations of an array | Set 1
- Minimum rotations to unlock a circular lock
- Count rotations divisible by 8
- Generating numbers that are divisor of their right-rotations
- Maximum contiguous 1 possible in a binary string after k rotations
- Count rotations of N which are Odd and Even
- Count rotations which are divisible by 10
- Range sum queries for anticlockwise rotations of Array by K indices
- Minimum circular rotations to obtain a given numeric string by avoiding a set of given strings
- Maximize count of corresponding same elements in given permutations using cyclic rotations
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.