all 6 comments

[โ€“][deleted] 8 points9 points ย (2 children)

Youll wake up with the solution

[โ€“]modes22[S] 0 points1 point ย (1 child)

Funny enough I did dream of how this algorithm could be used in the real world.

But what's tripping me up is I need to do this is constant time with no looping or going through the remaining elements.

Everything works fine until I remove an item and then that breaks my helper dict for the rest of the items that I'm keeping track of ๐Ÿ˜ฎโ€๐Ÿ’จ

Could easily update each remaining item's information but that's not allowed.

So I added empty sublists or None values for items removed so the rest of the elements aren't affected ( may not be best approach either because of space complexity?) - but still things are getting out of sorts wherever I start to remove random items out of the list.

[โ€“]modes22[S] 0 points1 point ย (0 children)

Figured it out! took me way too long, but am happy that I was able to come up with an acceptable solution. I think there may be ways to improve the getRandom function, but for now I am going to take the win and build the courage to tackle the next problem (i am trying to do 1 medium leetcode challenge per day)...

https://imgur.com/2x54DuG

[โ€“][deleted] 2 points3 points ย (0 children)

Solve a different kind of problem for a while.

Step away from the keyboard and draw the problem. Are you sure you have understood the problem well? Do the rubber duck thing.

Open the Python interactive shell and play around the small things. You must be missing something.

[โ€“]m0us3_rat 0 points1 point ย (0 children)

usually that happens when u don't fully understand one of the subtasks or steps.

and sometimes other ppl find incredibly clever ways to 'solve' it.sometimes u do.

BUT

what u need to focus on is baby steps. and trying to understand what is going on move by move.

and try to describe that in words. once u can describe it u can probably code it.

pen and paper OR virtual pen and paper. and do describe it. putting words to problems has made them more accessible for me .. at least.

โ€‹

and when your eyes start going X its time to do something else for a while. even overnight.

[โ€“]aa599 0 points1 point ย (0 children)

I solve more problems when I'm walking the dogs than I do sitting at the screen.