Тёмный

HackerRank Solution: Grid Challenge in C++ (greedy algorithm) 

nexTRIE
Подписаться 7 тыс.
Просмотров 4,9 тыс.
50% 1

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

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@SarthakSPyt
@SarthakSPyt 4 года назад
I've just started solving problems on hackerrank and your videos are of great help, plus you show solutions in c++ which is exactly what i need. Keep up the good work dude, you've gained a new subscriber.
@nextrie
@nextrie 4 года назад
Yay, thank you so much! I try to post many solutions every week, so please make sure you've got your notifications turned on! Are you a Computer Science student? 😁
@SarthakSPyt
@SarthakSPyt 4 года назад
@@nextrie yep, I've the notifications on. No, I'm not actually a Computer Science student, I'm an Electronics and Comm. student i couldn't get into CS due to some reason but I've been preparing for coding competitions so that I can get a decent job as a software engineer/developer.
@nextrie
@nextrie 4 года назад
Wow, more power to you man! Knowing how to solve problems with code is a great skill to have, so you're certainly on the right track here. Keep it up!
@jarjarbinks8954
@jarjarbinks8954 2 года назад
appreciate your videos. Helps a lot of us prepping for interviews
@nextrie
@nextrie 2 года назад
That's great to hear. I have many more in my HackerRank playlist, so I hope you enjoy them. I'll be posting more in the next few days.
@jarjarbinks8954
@jarjarbinks8954 2 года назад
also i had a question why does the outer for loop run for (rows-1) ? Its on line number 17
@nextrie
@nextrie 2 года назад
This is because we are accessing the rows by index in the conditional statement on Line 19. Indices are zero-based, so we start counting from zero, instead of one. But the value stored in the rows variable is the number of rows in the vector. So, let's say we have 5 rows in the vector, then the value of the "rows" variable will be 5. But the indices of the rows actually go from 0 (first row) to 4 (last row). That's why we have to use rows-1 in the loop on Line 17, to stay within bounds. Is it clearer to you now?
@jarjarbinks8954
@jarjarbinks8954 2 года назад
@@nextrie pardon me if I am wrong here, but wouldn't we get the same result doing (i
@nextrie
@nextrie 2 года назад
@@jarjarbinks8954 Nope, because on Line 19 in the comparison, I'm checking for the current row (i) against the next row (i+1). So if the loop goes all the way to Index 4, then i+1 on Line 19 will be 5, which is out of bounds. That's why the loop only goes to 3, so that I can still compare the row at Index 3 with the last row at Index 4.
@jarjarbinks8954
@jarjarbinks8954 2 года назад
@@nextrie thanks thanks it all makes sense now. Take love mate
@huangwosaz8794
@huangwosaz8794 2 года назад
Is there any faster way to do this? I couldn't figure out a more faster way . I used same logic came to see if this one has better one.
@dipeshjha3528
@dipeshjha3528 4 года назад
What great brain u hv
@nextrie
@nextrie 4 года назад
Still learning...
@kirtipurohit1237
@kirtipurohit1237 4 года назад
you know what?..IT DOESN'T WORK passes only the sample test cases
@nextrie
@nextrie 4 года назад
Hi Kirti, I just tested my solution again and it passes all the test cases. I've published my solution as a public gist on GitHub: gist.github.com/IsaacAsante/e5e2f43cb755df4629d49b576f8531b1 Kindly try it out, it should give you full results. Please ensure that your code does not contain any typo. Let me know if anything.
@kirtipurohit1237
@kirtipurohit1237 4 года назад
@@nextrie yes..Thanks it worked .sorry for being rude. I couldn't solve it since morning and your video just gave me alot of hopes and when it didn't work ..I got really disappointed
@nextrie
@nextrie 4 года назад
It's okay! I understand. So my code eventually worked for you, right? I want to help everyone struggling to solve these coding challenges, so I try to post new solution videos everyday. I hope my other content works out correctly for you. 👍
@kirtipurohit1237
@kirtipurohit1237 4 года назад
@@nextrie yess thank you so much!
@nextrie
@nextrie 4 года назад
Great! Happy coding!
Далее
Harder Than It Seems? 5 Minute Timer in C++
20:10
Просмотров 193 тыс.
Why You Shouldn't Nest Your Code
8:30
Просмотров 2,8 млн
Family♥️👯‍♀️🔥 How old are you? 🥰
00:20
My Unconventional Coding Story | Self-Taught
27:14
Просмотров 649 тыс.
3.4 Huffman Coding - Greedy Method
17:44
Просмотров 1,6 млн
Flipping the Matrix : Solution to Hackerrank Challenge
10:33