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.
At the very beginning, I realized union find was the best solution. But when implementing it, I found 1000000000 would definitely lead to stack overflow if I set the size of vectors as 10^9. Then I found those numbers which hadn't appeared yet would not influence others which had appeared already, so setting vectors with a fixed size was not necessary. Thus, hash map appeared in my solution.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Friend Circle Queries
You are viewing a single comment's thread. Return to all comments →
At the very beginning, I realized union find was the best solution. But when implementing it, I found
1000000000
would definitely lead to stack overflow if I set the size of vectors as 10^9. Then I found those numbers which hadn't appeared yet would not influence others which had appeared already, so setting vectors with a fixed size was not necessary. Thus, hash map appeared in my solution.