LC 602. Who Has the Most Friends #interviewprep #leetcode #sql #unionall #fullouterjoin

preview_player
Показать описание
Question 602 - Who has the most friends. This question is asking you to look through a table of request and accept interactions and return the user with the most friends along with the number of friends they have.

So, this question boils down to how we want to perform column combination and count aggregation.

The first method would be to UNION ALL the requester and accepter columns then perform a count on the result.

A second method would be to perform counts within each respective column first, then FULL OUTER JOIN the CTEs and add the counts.

The big learning objective here is to step back and realize that both of these options suck and are the result of narrow-scoped interview questions.

In industry, you’d likely have access to a customer table which you could incorporate into approach 2 with inner joins.

So, during your technical screen, remember to not only solve the problem, but also reflect on how you’d approach a similar question with all the tools and resources available on the job.
Рекомендации по теме
join shbcf.ru