Educative

Help me to understand how BT a substring of BAT?

https://www.educative.io/courses/grokking-the-coding-interview/NEOZDEg5PlN

Please help me to understand that how BT is a substring of BAT? Thus 1A1 as one of the required set in the answer? Though BT could be a set in powerset of BAT, but I am not sure how it is a substring? Am I missing something here?

β€œBT” is not a substring of β€œBAT”.

We get β€œ1A1” by replacing two different substrings in β€œBAT”, these substrings are β€œB” and β€œT”.

1 Like

with that logic, why can’t we replace 3 different substrings β€œB”, β€œA”, and β€œT” and replace them in the original string to get β€œ111”?

In that case, we should consider the whole string as the substring (and not the individual characters as different substring). This means we will be getting the abbreviation β€œ3” and not β€œ111”. Though this is not explicitly stated in the problem statement, but all contiguous characters should be considered as one substring.

Looks like the problem statement is not clear about this. We will be adding a statement to clear this confusion. Thanks for pointing this out.