We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Indeed it works on MySQL. I had my version similar to yours but its always timed out.
SELECT h.hacker_id, h.name, count(c.hacker_id) as cnt
FROM hackers h
JOIN challenges c
on (h.hacker_id=c.hacker_id)
group by h.hacker_id, h.name, c.hacker_id
having count(c.challenge_id) not in
(
SELECT max(total) FROM
(SELECT c.hacker_id, count(c.challenge_id) TOTAL FROM challenges c
GROUP BY c.hacker_id) c
where c.total <>
(SELECT count(c.challenge_id) TOT FROM challenges
GROUP BY c.hacker_id
)
GROUP BY c.total
having count(c.total) > 1
)
order by count(c.hacker_id) desc , h.hacker_id;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Challenges
You are viewing a single comment's thread. Return to all comments →
Indeed it works on MySQL. I had my version similar to yours but its always timed out.
SELECT h.hacker_id, h.name, count(c.hacker_id) as cnt
FROM hackers h
JOIN challenges c
on (h.hacker_id=c.hacker_id) group by h.hacker_id, h.name, c.hacker_id having count(c.challenge_id) not in ( SELECT max(total) FROM (SELECT c.hacker_id, count(c.challenge_id) TOTAL FROM challenges c GROUP BY c.hacker_id) c where c.total <> (SELECT count(c.challenge_id) TOT FROM challenges GROUP BY c.hacker_id )
GROUP BY c.total having count(c.total) > 1 ) order by count(c.hacker_id) desc , h.hacker_id;