Given a string S and a number X. There are M players who roll the dice. A player keeps on rolling the dice until he gets a number other than X. In the string S, S[i] represents the number at ith roll of a dice. The task is to find M. Note that the last character in S will never be X.
Input: s = “3662123”, X = 6
First player rolls and gets 3.
Second player rolls and gets 6, 6 and 2.
Third player rolls and gets 1.
Fourth player rolls and gets 2.
Fifth player rolls and gets 3.
Input: s = “1234223”, X = 2
Approach: Iterate in the string and count the characters which are not X. The number of characters which are not X will be the number of players.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Roll the characters of string
- Find nth term of the Dragon Curve Sequence
- Find the final co-ordinates reached by following a sequence of directions
- Find Bit whose minimum sequence flips makes all bits same
- Number of words in a camelcase sequence
- Form minimum number from given sequence
- Total number of odd length palindrome sub-sequence around each centre
- Convert an unbalanced bracket sequence to a balanced sequence
- Number of closing brackets needed to complete a regular bracket sequence
- Number of ways to divide string in sub-strings such to make them in lexicographically increasing sequence
- Given a number as a string, find the number of contiguous subsequences which recursively add up to 9
- Given a number as a string, find the number of contiguous subsequences which recursively add up to 9 | Set 2
- Find the Number which contain the digit d
- Given a number, find the next smallest palindrome
- Find the minimum number possible by changing at most one digit
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.