Visa Inc. interview question

Question on string DSA and sql query in leetcode