Freshworks interview question

First round: String based DSA problem (HARD)