Pinterest Interview Question

General case using SQL and solved with dense_rank