nCircle Tech Interview Question

Python code and SQL query