Shouldn't we use Union instead of Union all?

  • 5

    I think the answer missed the case when A send B a friend request, and B send A a friend request, and both requests got approved. In this case, A or B really just gained one friend. But the answer seems to count this case twice.
    Isn't union (remove duplicates) should be used instead of union all?

    select id1 as id, count(id2) as num
    (select requester_id as id1, accepter_id as id2 
    from request_accepted
    select accepter_id as id1, requester_id as id2 
    from request_accepted) tmp1
    group by id1 
    order by num desc limit 1

  • 1

    @Fangyyfrank I agree. The solution is wrong. Hope they can fix this soon.

  • 0

    @Fangyyfrank Use "UNION ALL". In Friend Requests I, it says it's possible that one user send multiple requests to another and get accepted multiple times. But you idea to use UNION is correct.

  • 0

    @Fangyyfrank Agree. Even looking through the test cases of OJ, union all is clearly wrong. There is mutual friend request and repeated friend request.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.