SG Analytics Interview Question

Python string matching ques and SQL query