Pinterest interview question

General case using SQL and solved with dense_rank