Тёмный

HackerRank Solution: Missing Numbers in C++ 

nexTRIE
Подписаться 6 тыс.
Просмотров 3 тыс.
50% 1

HackerRank solution for Missing Numbers, in C++. We need to find missing numbers between two arrays, which are permutations of each other. In my Missing Numbers HackerRank solution, I am using a sorted map and std::pair in C++. The map is used to count the occurrences of the numbers inside both arrays, because we will encounter duplicates.
All HackerRank solutions on GitHub (please leave a star): github.com/IsaacAsante/Hacker...
Missing Numbers HackerRank problem: www.hackerrank.com/challenges...

Опубликовано:

 

29 сен 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 14   
@nextrie
@nextrie 3 года назад
In this video, I keep saying "frequencies". It would have been better for me to use the word "occurrences". But hey, I guess that's what happens when you record a video at night after a long day :D. I hope you guys still understand and enjoy this video. Thanks :)
@AhmetKaan
@AhmetKaan 3 года назад
Awesome vid, loved it my friend. Personally I love your content. Would love to see your future videos :) 🙂🙏
@nextrie
@nextrie 3 года назад
Thanks! Btw, I intend to post more videos about data structures soon. Which data structure would you love to see (trees, stacks, etc)?
@dipeshjha3528
@dipeshjha3528 3 года назад
Thanks bro I was waiting for this
@nextrie
@nextrie 3 года назад
I hope you enjoy it! Sorry the video is a bit long... I tried to explain my solution as easily as I could.
@sirnawaz
@sirnawaz 3 года назад
Your solution is O(nlog(n)) because you used std::map. This problem can be solved in O(n) but for that you need to make use of the given fact that the difference between max and min is
@manaskhare412
@manaskhare412 2 года назад
I don't think thik solution is nlogn, becoz at last, you will not get an sorted array, so you need sorted array array in the output, you need to sort it, then you eventually get nlogn as you said. I don't know how this video has worked with this, O(n) solution with O(n) Aux space. Map is taking O(n) here..
@enlove6971
@enlove6971 2 года назад
can i see that version of code?
@dipeshjha3528
@dipeshjha3528 3 года назад
Wowww I m ur fan now
@nextrie
@nextrie 3 года назад
Thanks!
@user-uc9ig7qb2p
@user-uc9ig7qb2p 2 года назад
Hi! again me. I gave my solution and i think it would be right but i failed one test case. After trying test against custom input. I found the output is exactly the same with the expected solution, which means my solution should be right. Do u know why is this happend(such as over time)? Or will u please point out the mistake in my code? Thanks a lot vector missingNumbers(vector arr, vector brr) { vector solution; map data; for(int i=0;i0){ solution.push_back(it->first); it->second--; } } return solution; }
@nextrie
@nextrie 2 года назад
Yes, you have an error in your code so your output is not the same for Test 1. You don't need a nested while loop when you iterate through your map. Just change the for loop (for your data map) to the following, and then run your tests again: for(it =data.begin();it!=data.end();it++) { if(it->second!=0) { solution.push_back(it->first); } }
@user-uc9ig7qb2p
@user-uc9ig7qb2p 2 года назад
@@nextrie Hi, thanks for ur reply and it works. I think i got missundertanding to that question.
@nextrie
@nextrie 2 года назад
@@user-uc9ig7qb2p You're welcome. Keep up the good work.
Далее