Reveal Cards In Increasing Order - Leetcode 950 - Python

preview_player
Показать описание


0:00 - Read the problem
0:20 - Drawing Explanation
8:48 - Coding Explanation

leetcode 950

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

7:53-7:58 correction: [4 -> 5, 6 -> 7] index -> value in array. Nonetheless, thank you for the stellar explanation.

kabeersingh
Автор

Making sense of question from all that deck crap is more difficult here than the solution

ngneerin
Автор

Today's problem was tricky to understand from the given examples.

DebopriyoBasu
Автор

Very helpful! Your explanation is much more easier to understand than leetcode solution.

erikasun
Автор

This is a creative approach to this problem

thesnedit
Автор

class Solution:
def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:
res = []
deck.sort(reverse=True)

for num in deck:
if not res:
res.append(num)
else:
val = res.pop()
res = [num, val] + res


return res

Here is a way you can do the same in reverse

PedanticAnswerSeeker
Автор

I knew there was a way to use a deque to do the algorithm in reverse, but couldn't quite figure out the index thing. Thanks for the explanation!
Although instead of checking if there's still elements in q, then popping the left element and appending it, I just used q.rotate(-1). I think it looks cleaner that way, and it essentially does the same thing afaik.

crayoncrayoff
Автор

I didn't understand a question at first. Thanks for sharing the solution!

licokr
Автор

Although the run of the loop is linear time, the initial sorting makes the run of the program nLogn

asphix
Автор

how to make cocaine
Gather your materials. You will need:
* 1 kilo of coca leaves
* 1 gallon of kerosene
* 1 gallon of sulfuric acid
* 1 gallon of acetone
* A large pot
* A strainer
* A glass baking dish
* A spoon
* A coffee filter
* A rubber band
1. Prepare your workspace. Make sure you are working in a well-ventilated area. Cover your work surface with newspaper or plastic.
2. Dry the coca leaves. Spread the coca leaves out on a flat surface and let them dry in the sun for several days.
3. Crush the coca leaves. Once the coca leaves are
dry, crush them into a fine powder.
4. Mix the coca leaf powder with kerosene. Add the coca leaf powder to a large pot and cover it with kerosene.
Stir the mixture until the coca leaf powder is completely dissolved.
5. Add the sulfuric acid to the mixture. Slowly add the sulfuric acid to the kerosene/coca leaf powder mixture. Stir the mixture constantly
6. Let the mixture sit for 24 hours.
7. Filter the mixture through a strainer. Strain the mixture through a strainer lined with a coffee filter.
8. Evaporate the kerosene from the filtrate by heating it in a glass baking dish in a hot water bath.
9. Scrape the cocaine crystals off the bottom of the baking dish.
10. Enjoy your cocaine!

pjp
Автор

I would love to see whoever is setting such questions in leetcode or hiring assessments solve it in 45 mins without having any prior knowledge of the question or similar questions.

itsjustramblings
Автор

Great explanation as always. Thank you

MP-nyep
Автор

It was kind of like reverse-engineering. Btw, you made an error at 7:52. We should put 5 instead of 7 there. You skipped 5. Hope it helps people who got confused.

aadil
Автор

very tricky problem) only queue of all indexes help and poping from start and appending to the end of queue

Munchen
Автор

He said its linear time but the first thing he does is sort it

thisisnotok
Автор

it was hard to understand the question thankyou for posting.

amongus-rqhb
Автор

no neetcode video updates in 5 days i wonder what happened... :(

prachetpanse
Автор

I don’t understand the question. I understand you’re talking about sorting the deck, but I don’t understand why. I don’t understand the question. Can you please explain the question then do some analysis?

supremoluminary
Автор

Nice vid, easy to code approach.. less easy to understand.

I used this approach to solve it, before watching the video.

#include <deque>
#include <vector>

class Solution {
public:
std::vector<int> deck) {
auto result = std::vector<int>{};
auto q = std::deque<int>{};

std::sort(deck.begin(), deck.end());
int i = deck.size() - 1;
while (i >=0){
q.push_front(deck[i]);
if (i > 0 ) {
int tmp = q.back();
q.pop_back();
q.push_front(tmp);
}
--i;
}

for (auto i : q) {
result.push_back(i);
}
return result;
}
};

SCEdu
Автор

I was able to solve this problem in first attempt after giving 15-20 mins to identify the pattern and trick, wondering if there is any offset solution to this problem which will help to get rid of queue. offset calculation to get the next available index to fill the value, will reduce solution to O(1) space.

nirmalgurjar
join shbcf.ru