SG Analytics interview question

Python string matching ques and SQL query