Cambly Interview Question

Optimizing a database query with indexing