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:
- Minimum digits to be removed to make either all digits or alternating digits same
- Minimum number of elements to be removed so that pairwise consecutive elements are same
- Minimum number of elements to be removed to make XOR maximum
- Minimum number of elements that should be removed to make the array good
- Find the minimum number of elements that should be removed to make an array good
- Minimum labelled node to be removed from undirected Graph such that there is no cycle
- Minimum characters that are to be inserted such that no three consecutive characters are same
- Count of strings possible by replacing two consecutive same character with new character
- Check whether two strings contain same characters in same order
- Check if two numbers have same number of digits
- Find the position of the last removed element from the array
- Count consecutive pairs of same elements
- Length of the longest substring with no consecutive same letters
- Longest substring such that no three consecutive characters are same
- Probability of getting two consecutive heads after choosing a random coin among two different types of coins
- Sum of the products of same placed digits of two numbers
- Count distinct pairs from two arrays having same sum of digits
- Find smallest possible Number from a given large Number with same count of digits
- Maximum sum and product of the M consecutive digits in a number
- Maximize product of same-indexed elements of same size subsequences
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.