Sum of All Subsets XOR Total - Leetcode 1863 - Python

  Рет қаралды 9,495

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/sum-of-...
0:00 - Read the problem
0:30 - Drawing Explanation 1
4:45 - Coding Explanation 1
6:55 - Drawing Explanation 2
17:10 - Coding Explanation 2
leetcode 1863
#neetcode #leetcode #python

Пікірлер: 41
@lexkilpatrick3441
@lexkilpatrick3441 2 ай бұрын
How could this possibly be an easy problem when generating all subsets is a medium backtracking problem in itself 🤣
@tommyshelby6277
@tommyshelby6277 2 ай бұрын
cry
@NeetCodeIO
@NeetCodeIO 2 ай бұрын
Yeah good point
@krateskim4169
@krateskim4169 2 ай бұрын
@@tommyshelby6277 you need not be rude, just because you are better
@nirmalgurjar8181
@nirmalgurjar8181 2 ай бұрын
yeah, right, it's an easy problem for only those, who knows subset problem.
@EduarteBDO
@EduarteBDO 2 ай бұрын
I have a theory that it's because generating all subsets is an older problem and at that time this was considered hard, but right now the expected difficult level, of easy, medium and hard questions are increasing.
@grantpeterson2524
@grantpeterson2524 2 ай бұрын
I (somehow) managed to deduce the mathematical OR solution by myself without seeing it, and I gotta say, I'm pretty damn proud of myself
@DanielGarza27
@DanielGarza27 2 ай бұрын
Thank you for making this! Super helpful as these problems are quite tricky and I want to start leetcoding a bit every day.
@m.kamalali
@m.kamalali 2 ай бұрын
Wow, Amazingly explained!!
@leo8755
@leo8755 Күн бұрын
This is a cool problem and solution! You have a small calculation error around 14:39, it should be 28 like you calculated right after.
@MP-ny3ep
@MP-ny3ep 2 ай бұрын
Great explanation. Thank you
@SC2Edu
@SC2Edu 2 ай бұрын
Awesome explanation
@krateskim4169
@krateskim4169 2 ай бұрын
Thank you so much
@AGENT-gw4vd
@AGENT-gw4vd 2 ай бұрын
Explaination was nice
@i75kddy74
@i75kddy74 2 ай бұрын
hence subscribed to your channel
@ritikaagrawal769
@ritikaagrawal769 2 ай бұрын
the person who assigns difficulty level on leetcoode is probably high all the time.
@nirmalgurjar8181
@nirmalgurjar8181 2 ай бұрын
Thank you neetcode, was able to come up with first solution. was wondering any trick to introduce caching but since there are 2^n different possibilities so caching won't be helpful but still i have this doubt in my mind, is there any way we can introduce caching?
@mohanedomer9081
@mohanedomer9081 2 ай бұрын
yo bro thx
@koreandude
@koreandude 2 ай бұрын
will you have any promotions for the pro course for memorial day? struggling wannabe engineer here.
@ish90917
@ish90917 2 ай бұрын
Why did we not use memoisation in the backtracking solution ?
@NeetCodeIO
@NeetCodeIO 2 ай бұрын
there's not necessarily any repeated sub problems, every subset could be different
@RahulJain-kk5no
@RahulJain-kk5no 2 ай бұрын
How can I handle nervousness and anxiety during an interview? I messed up my last interview due to this, even though the questions that were asked weren't that difficult.
@juanmacias5922
@juanmacias5922 2 ай бұрын
I have very limited interview experience, but I'd suggest mock interviews, talking out your solution while you are doing Leetcode problems on your own. And only start coding once you have an algo, or solution. I like to write out the inputs, output requested, what my solution is, and before I start coding, I'll comment the whole solution out (pseudocode), then it's just a matter of writing the code under said comments. In cross country running circles there's a quote "the hay is in the barn", which basically means you worked your ass off, you just need to trust in the training, and perform. Edit: also work on asking interviewers clarifying questions, even if it seems obvious, or trivial, and always go for the naive solution first, unless the more optimal solution comes to you right away, but I'd also explain that to them "the brute force is", but "I believe because of" "this approach will be better". It's all about communicating your intent. Also, it might be beneficial to mention the time/space complexity with your solution.
@anonymous10906
@anonymous10906 2 ай бұрын
Best
@sophiophile
@sophiophile 2 ай бұрын
Just practice. Most of us have been there. Apply for jobs that you don't care about getting. Ask a friend to do a mock with you (but provide them the q without knowing the solution- I have asked people in the past and they have tried 'making up' questions, and ended up asking something that goes beyond hard, lol).
@deadlyecho
@deadlyecho 2 ай бұрын
Just build a truth table and you will understand the last solution... this will help in getting why the 50% percent ratio still the same even if we added a number with a one bit in the position we are looking at....
@MohanRam-mq2pk
@MohanRam-mq2pk 2 ай бұрын
me findind difficult to understand O(2^n) itself 😭
@michael._.
@michael._. 2 ай бұрын
ngl but this bit manipulation method was pretty damn "creative"
@rgolanng
@rgolanng 2 ай бұрын
Have you ever worked with AI project in big tech yet?
@EduarteBDO
@EduarteBDO 2 ай бұрын
I'm bad at math and bad at bit manipulation, now lc are fusing both with these questions.
@brenocabral5924
@brenocabral5924 2 ай бұрын
Why does the LeetCode logo look like a fancy way to pick a toothpick?
@licokr
@licokr 2 ай бұрын
Wow, it's crazy huh. I couldn't believe it the problem is an easy problem. it's worth it solving the problem though, I think that would be enough knowing how to work the recursive solution. var subsetXORSum = function(nums) { let answer = 0; const b = (initialNums, choices) => { let xor = 0; for (let i = 0; i < initialNums.length; i++) { xor ^= initialNums[i]; } answer += xor; while (choices.length > 0) { b(initialNums.concat(choices.shift()), [...choices]); } } b([],nums); return answer; }; This is my solution, which is less efficient than the solution shown up in this video. It get rid of an element from the list the func gets then will pass the new array. I think the solution you introduced in the video has a point to understand how recursive works. Thanks for the video! 👍 --- ps I think why it's a bit hard to understand the solution is because the concept of passing by value, the total. In the case where nums is [5, 1, 6]. dfs(i + 1, total ^ nums[i]) i == 4 -> returns 0 0 ^ 6 + 0 ^ 1 + 0 ^ 5 + 0 (0 ^ 1) + (0 ^ 1) ^ 6 + 0 (0 ^ 5) + (0 ^ 5) ^ 1 + (0 ^ 5) ^ 6 + 0 (0 ^ 5 ^ 1) + 0
@freykong
@freykong Ай бұрын
The optimal solution is 👻👻👻
@deathbombs
@deathbombs 2 ай бұрын
Correction- we hate math AND bit manipulation!
@MichaBalcerak
@MichaBalcerak 2 ай бұрын
I am too dumb for coding
@pastori2672
@pastori2672 2 ай бұрын
i did NOT understand this its ok tho who would expect you to come up with this
@mnaresh3382
@mnaresh3382 2 ай бұрын
kindly make the videos approximately 10-12min length, 20 min for an easy problem explanation is not very appealing.
@chien-yuyeh9386
@chien-yuyeh9386 2 ай бұрын
Let’s goooo 🫡
Time Needed to Buy Tickets - Leetcode 2073 - Python
12:45
NeetCodeIO
Рет қаралды 12 М.
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 11 МЛН
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 33 МЛН
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 78 МЛН
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 281 М.
Whiteboard Coding Interviews: 6 Steps to Solve Any Problem
15:18
Fullstack Academy
Рет қаралды 362 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 330 М.
How to NOT Fail a Technical Interview
8:26
Fireship
Рет қаралды 1,3 МЛН
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 260 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 221 М.
Fastest way to become a Software Engineer
9:10
Sahil & Sarra
Рет қаралды 278 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 624 М.