Got this question in OA of TCS-Digital | 7.2 LPA CTC | can you solve this one?

Anonymous User
2167
Mar 15, 2022

Please Guys do more leetcode, OA questions are getting tougher day by day, even for the Service Based IT Companies.

So recently i gave tcs digital off campus OA exam and this question was there. Take a look at it and
Please tell me how to approach this problem , i had gone blank during OA and was not able to solve.

QUESTION -
Given a string S of length N, Return the count of all the possible Unique Sub-Sequences of Length N-2, which can be derive from given string (each Sub-Sequences should have length = N-2).
String contains only number from 0 to 9.
As the result can be large return ans module (10^9) + 7.

sample test 1 -
input string : "15025"
output : 10
Explaination : All Unique Sub-Sequencesof length (5-2) 3 are - "025","525","505","502","125","105","155","125","150","102"

sample test case 2 :
input string : "781484"
output : 14

Constrains -
0 <= s[i] <= 9
2 <= N <= 100000


The only intuition i thought of during exam is by using Permutation and combination concept but later i noticed that this approach will give us count of all possible sub-sequences but not the distinct one (as per que).

Comments (9)