Given a number N. The task is to count the minimum number of digits to be removed from the number so that no two consecutive digits are same.
Input : N = 11344
Output : 2
Explanation : Remove the digit 1 from 2nd place and 4 from the end so that the number becomes 134. Thus no two consecutive digits are same. Hence answer is 2.
Input : N = 55553
Output : 3
Explanation : Remove the digit 5 from the 2nd, 3rd and 4th places so that the number becomes 53. Thus no two consecutive digits are same. Hence answer is 3.
The problem can be easily solved if we just count the number of consecutive pairs of equal digits. That would be the minimum number digits to remove from the given number so that no two consecutive digits are same.
Below is the implementation of the above approach:
- Maximum sum and product of the M consecutive digits in a number
- Minimum number of elements to be removed so that pairwise consecutive elements are same
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Minimum number with digits as 4 and 7 only and given sum
- Smallest number with given sum of digits and sum of square of digits
- Check if the sum of digits of number is divisible by all of its digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Minimum number to be added to all digits of X to make X > Y
- Minimum digits to remove to make a number Perfect Square
- Sum of the digits of square of the given number which has only 1's as its digits
- Find the Largest Cube formed by Deleting minimum Digits from a number
- Find smallest number with given number of digits and sum of digits
- Find the Largest number with given number of digits and sum of digits
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
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.