My query does not pass, can anyone provide the correct solution?


  • 0

    select case when count(distinct a.sender_id, a.send_to_id) = 0 then 0.00
    else round(count(distinct a.sender_id, a.send_to_id)/(select COUNT(distinct sender_id, send_to_id) from friend_request), 2) end accept_rate
    from friend_request a
    join request_accepted b
    on a.sender_id = b.requester_id and a.send_to_id = b.accepter_id and a.request_date <= b.accept_date;

    Input:
    {"headers":{"friend_request":["sender_id","send_to_id","request_date"],"request_accepted":["requester_id","accepter_id","accept_date"]},"rows":{"friend_request":[[1,2,"2016/06/01"],[1,3,"2016/06/01"],[1,4,"2016/06/01"],[2,3,"2016/06/02"]],"request_accepted":[[1,2,"2016/06/03"],[1,3,"2016/06/08"],[2,3,"2016/06/08"],[3,4,"2016/06/09"]]}}
    Output:
    {"headers": ["accept_rate"], "values": [[0.75]]}
    Expected:
    {"headers": ["accept_rate"], "values": [[1.00]]}

    I misunderstand the question? I am still thinking my answer is correct....


  • 0

    This is a easy problem so you just need to count the accepted requests / the total requests. For the above case, there are 4 requests, and there are 4 accepted requests, so the overall acceptance rate is 4/4 = 1.00.

    Sorry for leading your misunderstanding.


Log in to reply
 

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