This question was asked in Infosys test (2022).
Wael has a sequence S. He found that the sub-sequences of S that are derived from S after deleting exactly two letters are considered as beautiful subsequences.
Given string S, your task is to find the number of different beautiful subsequences of S. Since the answer can be very large return it modulo 10^9 + 7.
Input Format:
The first line contains a string S, denoting the given sequence.
Constraints:
1 <= len(S) <= 10^6
Sample Input:
aa --> 1 (The only beautiful sub-sequence is empty sequence)
bccb --> 4 (we can get {bc,cb,cc,bb} so answer is 4)
bbbbbb --> 1 (the only possible sub-sequence is bbbb, so answer is 1)








1<=length(s)<=20
include <bits/stdc++.h>
include <math.h>
typedef long long ll;
using namespace std;
ll i, j, t, a, n, m, b, c, d, f, g;
string s, s1, s2, s3, s4, myst;
int x[50];
set ss;
int main() { ios::sync_with_stdio(0); cin.tie(0);
} /*
*/
That's not true, because if you have string abcab you can delete first or second "ab" so you can get "cab" or "abc".
Any way of confirming that the test is over.
I will try to explain this step by step. Let $$$dp[i][j]$$$ denote the number of strings possible strings with $$$j$$$ characters deleted. Here $$$j \lt =2$$$.
consider a stretch of indices with similar characters let from $$$x^{th}$$$ to $$$i^{th}$$$ i.e we are considering all ranges of equal characters. If the string is "accb" then the equal stretches are 1 to 1, 2 to 3, 4 to 4.
We will update $$$dp[i][1]$$$ and $$$dp[i][2]$$$; for $$$dp[i][1]$$$ --> we can delete one single character from xth to ith character this contributes 1 to answer or do not delete anything then add $$$dp[x-1][1]$$$ to answer.
for $$$dp[i][2]$$$ --> we can delete 2 character from xth to ith character, this contributes 1 to answer or delete one character to add $$$dp[x-1][1]$$$ or do not delete anything then add $$$dp[x-1][2]$$$ to answer. There is a chance of duplication here if $$$(x-2)^{th}$$$ character is same, so subtract this.
The final answer is $$$dp[n-1][2]$$$;
Do comment if something is wrong.