This was a question asked by juspay to the colleges in banglore region in online assessment round.
Given a number of string datatype. You have to pick exactly 4 digits from the number by following certain rules to ensure the 4-digit number is stable.
The rules are as follows:-
First two digits of the number is the same and lets call it x.
Last two digits of the number is also the same and lets call this number y.
x and y satisfy the relation x+1=y. and the indices of x must be strictly less than y.
Your task is to find the number of ways of finding a 4 digit number which is stable.
Example 1
Input:
s = "22233424"
Output:
4
Explanation: There are four ways of getting a stable 4 digit number.
We can form "2233" by picking indices 0,1,3,4
We can form "2233" by picking indices 1,2,3,4
We can form "2233" by picking indices 0,2,3,4
We can form "3344" by picking indices 3,4,5,7