Python3 Program to Find Maximum value possible by rotating digits of a given number Last Updated : 06 Sep, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a positive integer N, the task is to find the maximum value among all the rotations of the digits of the integer N.Examples:Input: N = 657Output: 765Explanation: All rotations of 657 are {657, 576, 765}. The maximum value among all these rotations is 765.Input: N = 7092Output: 9270Explanation:All rotations of 7092 are {7092, 2709, 9270, 0927}. The maximum value among all these rotations is 9270.Approach: The idea is to find all rotations of the number N and print the maximum among all the numbers generated. Follow the steps below to solve the problem:Count the number of digits present in the number N, i.e. upper bound of log10N.Initialize a variable, say ans with the value of N, to store the resultant maximum number generated.Iterate over the range [1, log10(N) - 1] and perform the following steps:Update the value of N with its next rotation.Now, if the next rotation generated exceeds ans, then update ans with the rotated value of NAfter completing the above steps, print the value of ans as the required answer.Below is the implementation of the above approach: Python # Python program for the above approach # Function to find the maximum value # possible by rotations of digits of N def findLargestRotation(num): # Store the required result ans = num # Store the number of digits length = len(str(num)) x = 10**(length - 1) # Iterate over the range[1, len-1] for i in range(1, length): # Store the unit's digit lastDigit = num % 10 # Store the remaining number num = num // 10 # Find the next rotation num += (lastDigit * x) # If the current rotation is # greater than the overall # answer, then update answer if (num > ans): ans = num # Print the result print(ans) # Driver Code N = 657 findLargestRotation(N) # This code is contributed by rohitsingh07052. Output765Time Complexity: O(log10N)Auxiliary Space: O(1) Please refer complete article on Maximum value possible by rotating digits of a given number for more details! Comment More infoAdvertise with us Next Article Maximum value possible by rotating digits of a given number K kartik Follow Improve Article Tags : Python Technical Scripter 2020 number-digits rotation Practice Tags : python Similar Reads Javascript Program to Find Maximum value possible by rotating digits of a given number Given a positive integer N, the task is to find the maximum value among all the rotations of the digits of the integer N. Examples: Input: N = 657Output: 765Explanation: All rotations of 657 are {657, 576, 765}. The maximum value among all these rotations is 765. Input: N = 7092Output: 9270Explanati 2 min read Maximum value possible by rotating digits of a given number Given a positive integer N, the task is to find the maximum value among all the rotations of the digits of the integer N. Examples: Input: N = 657Output: 765Explanation: All rotations of 657 are {657, 576, 765}. The maximum value among all these rotations is 765. Input: N = 7092Output: 9270Explanati 9 min read Find maximum number that can be formed using digits of a given number Given a number, write a program to find a maximum number that can be formed using all of the digits of this number.Examples: Input : 38293367Output : 98763332Input : 1203465Output: 6543210Simple Approach: The simple method to solve this problem is to extract and store the digits of the given number 6 min read Find the maximum sum of digits of the product of two numbers Given an array arr[] of size N( > 2). The task is to find the maximum sum of digits of the product of any two numbers of the given array.Examples: Input : arr[] = {8, 7} Output : 11 The product of 8 and 7 is 56. The sum of the digits of 56 is equal to 11.Input : arr[] = {4, 3, 5} Output : 6 Produ 5 min read What is the maximum possible value of an integer in Python ? Consider below Python program. Python3 # A Python program to demonstrate that we can store # large numbers in Python x = 10000000000000000000000000000000000000000000 x = x + 1 print (x) Output : 10000000000000000000000000000000000000000001 In Python, value of an integer is not restricted by the numb 2 min read Rotate digits of a given number by K Given two integers N and K, the task is to rotate the digits of N by K. If K is a positive integer, left rotate its digits. Otherwise, right rotate its digits. Examples: Input: N = 12345, K = 2Output: 34512 Explanation: Left rotating N(= 12345) by K(= 2) modifies N to 34512. Therefore, the required 10 min read Like