LeetCode April Challenge Day 1 - Easy Start

preview_player
Показать описание
First day problem took me 19 seconds to read+code because it's the world's best-known XOR problem... well, at least I will talk about some intuition behind it.

Subscribe for more educational videos on algorithms, coding interviews and competitive programming.

#Coding #Programming
Рекомендации по теме
Комментарии
Автор

We can think of it as the following facts:-
1. XOR of a number with itself is 0
2. XOR of a number with 0 is the number itself
3. XOR is commutative so the order of numbers does not matter

lovvyparhar
Автор

Now I came up with a nice way to put it:
For every bit, bitwise XOR holds total parity of this bit in numbers that you xored.

Errichto
Автор

I hope Errichto earns enough money from YouTube so that he can be our full time teacher. 😂

jameshello
Автор

The idea is based on following two facts.
a) XOR of a number with itself is 0.
b) XOR of a number with 0 is number itself.

danyjacob
Автор

Hey Errichto! Really appreciate these videos man, I'm just starting my competitive programming journey because i was invited to join my university's team, and I'm glad that your videos exist out here cause the best way I learn is through consumption of youtube videos in my free time. Thanks a lot, and keep up the good work!

seanpe
Автор

Great videos, your actual skill is insane and I love the way you wrap up the problem at the end of the video with some further information and explanaition! Keep it up, Errichto

befrog
Автор

Very well explained! Most explanations just say 'XOR it'. But you explained very cleanly WHY we might need to do that. Thank you!

vishnusingh
Автор

Am I the only noob coder in this channel? I barely know little bit of C language but I like the way he explains the solution. loving your content man.

boco
Автор

I just want to tell you that these videos helped me immensely. a huge thing thank you. it would be amazing if you did more similar series. I’m learning so much

occo
Автор

I request to activate ads, your so so so good at teaching, and having thousands of subs, I would happily watch 2 ads at the start and 2 at the end to watch such content

AkshatSinghania
Автор

Saw your reminder yesterday and solved it.thanks otherwise i would have forgotten to do it.

angiras
Автор

Thanks for uploading this. I will also do them daily and it is always good to have a reference for when you are stuck.

subarukun
Автор

Thanks man for your such efforts I am a beginner and I have tried starting competitive programming even once before but I gave up due to lack of knowledge and frustration of not improving and remaining stuck....hope to get past this time with your guidance and motivation.

AdityaKumar-zfcf
Автор

For those who have difficulty understanding this like I had, imagine the integers as a stack in tetris, where same number disappear because of ex-or operation, leaving only the number appearing once.

nileshkharat
Автор

I really like the way you present your solutions.

karshtharyani
Автор

Once you solved it, you can click the 'Solution' button and see the editorial with 4 different approaches and complexities: (1) List operation, (2) Hash Table, (3) Math and (4) Bit Manipulation. The last one is the only one with Space Complexity of O(1).

eloyhz
Автор

i add an extra:
- XOR a number with itself *odd number of times* the result is number itself.
- XOR a number *even number of times* with itself, the result is 0.
and because of the associativity and commutativity of XOR operation, Xoring the list of numbers will give you the unique number

LEURKify
Автор

errichto, your vidoes are very encouraging

gautamkumarshukla
Автор

did you ever felt depressed when you had to see editorials of problems continuously during your beginner's days? Also what did you do for math and numbers theory problems?

AvinashKumar-mkti
Автор

XOR a number with itself is 0, so the numbers that appear twice in the list will XOR themselves out leaving behind the desired number, the only number without a duplicate.

The same principle applies when you think of it in terms of bit parities.

For each bit of each number in the list, the duplicate bit between two numbers in the list will XOR themselves out to 0, leaving behind the desired bit. If the leftover desired bit is 0, then 0 XOR 0 is 0, if the leftover is 1, then 0 XOR 1 is 1.

MikeLeed