Javascript Program to Count rotations which are divisible by 10 Last Updated : 31 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Given a number N, the task is to count all the rotations of the given number which are divisible by 10.Examples: Input: N = 10203 Output: 2 Explanation: There are 5 rotations possible for the given number. They are: 02031, 20310, 03102, 31020, 10203 Out of these rotations, only 20310 and 31020 are divisible by 10. So 2 is the output. Input: N = 135 Output: 0 Naive Approach: The naive approach for this problem is to form all the possible rotations. It is known that for a number of size K, the number of possible rotations for this number N is K. Therefore, find all the rotations and for every rotation, check if the number is divisible by 10 or not. The time complexity for this approach is quadratic. Efficient Approach: The efficient approach lies behind the concept that in order to check whether a number is divisible by 10 or not, we simply check if the last digit is 0. So, the idea is to simply iterate over the given number and find the count of 0's. If the count of 0's is F, then clearly, F out of K rotations will have 0 at the end of the given number N. Below is the implementation of the above approach: JavaScript <script> // Javascript implementation to find the // count of rotations which are // divisible by 10 // Function to return the count of // all the rotations which are // divisible by 10. function countRotation(n) { let count = 0; // Loop to iterate through the // number do { let digit = n % 10; // If the last digit is 0, // then increment the count if (digit == 0) count++; n = parseInt(n / 10); } while (n != 0); return count; } // Driver code let n = 10203; document.write(countRotation(n)); </script> Output: 2 Time Complexity: O(log10N), where N is the length of the number.Auxiliary Space: O(1) Please refer complete article on Count rotations which are divisible by 10 for more details! Comment More infoAdvertise with us Next Article Javascript Program to Count rotations which are divisible by 10 kartik Follow Improve Article Tags : Mathematical Combinatorial JavaScript Web Technologies DSA rotation Numbers Number Divisibility +4 More Practice Tags : CombinatorialMathematicalNumbers Similar Reads Javascript Program to Count rotations divisible by 4 Given a large positive number as string, count all rotations of the given number which are divisible by 4. Examples: Input: 8Output: 1Input: 20Output: 1Rotation: 20 is divisible by 4 02 is not divisible by 4Input : 13502Output : 0No rotation is divisible by 4Input : 43292816Output : 55 rotations are 2 min read Javascript Program to Count rotations divisible by 8 Given a large positive number as string, count all rotations of the given number which are divisible by 8.Examples: Input: 8Output: 1Input: 40Output: 1Rotation: 40 is divisible by 8 04 is not divisible by 8Input : 13502Output : 0No rotation is divisible by 8Input : 43262488612Output : 4Approach: It 3 min read Count rotations which are divisible by 10 Given a number N, the task is to count all the rotations of the given number which are divisible by 10.Examples: Input: N = 10203 Output: 2 Explanation: There are 5 rotations possible for the given number. They are: 02031, 20310, 03102, 31020, 10203 Out of these rotations, only 20310 and 31020 are d 4 min read Javascript Program to Count of rotations required to generate a sorted array Given an array arr[], the task is to find the number of rotations required to convert the given array to sorted form.Examples: Input: arr[] = {4, 5, 1, 2, 3}Â Output: 2Â Explanation:Â Sorted array {1, 2, 3, 4, 5} after 2 anti-clockwise rotations. Input: arr[] = {2, 1, 2, 2, 2}Â Output: 1Â Explanation:Â So 4 min read Count numbers in range 1 to N which are divisible by X but not by Y Given two positive integers X and Y, the task is to count the total numbers in range 1 to N which are divisible by X but not Y. Examples: Input: x = 2, Y = 3, N = 10 Output: 4 Numbers divisible by 2 but not 3 are : 2, 4, 8, 10 Input : X = 2, Y = 4, N = 20 Output : 5 Numbers divisible by 2 but not 4 10 min read Like