ZS Associates Interview Question

Write query based on given problem statement