Bit Manipulation Interview Problems Solved Step by Step | Competitive Programming | Data Structures

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

What is bit manipulation?

Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a word. Computer programming tasks that require bit manipulation include low-level device control, error detection and correction algorithms. Bit manipulation, in some cases, can obviate or reduce the need to loop over a data structure and can give many-fold speed-ups, as bit manipulations are processed in parallel, but the code can become more difficult to write and maintain.

The following topics are covered in this bit manipulation tutorial:

0:00 - Introduction
1:05 - Importance of bit manipulation
2:21 - Bit manipulation part 1
1:05:10 - Bit manipulation part 2

---------------------------------------- About Scaler --------------------------------------------------

We are a tech-focused upskilling and reskilling platform catering to tech enthusiasts in universities and working professionals. There are more Scaler graduates working at Amazon than all of the IITs combined!

📌 Follow us on Social and be a part of an amazing tech community📌

🔔 Hit that bell icon to get notified of all our new videos 🔔

If you liked this video, please don't forget to like and comment. Never miss out on our exclusive videos to help boost your coding career! Subscribe to Scaler now!

#bitmanipulation #datastructures #competitiveprogramming
Рекомендации по теме
Комментарии
Автор

1:26:02 .
Suppose the question is modified and is asking to return the min XOR the number can have in the array with any other remaining number, for every index.

Then,
This Approach fails for array [ 8, 9, 11, 10, 7, 14]. As minimum XOR of 7 will be with 14 giving XOR = 9.
XOR of 7^8 = 15 so the original approach will give answer 15 but that is not true imo.

How should we proceed with such question ?

shivamrastogi
Автор

Question : for an input number N, return the minimum number possible K such that there are N distinct integers less than or equal to K with total XOR as 0.

Example : for N = 4, minimum number possible is 5 as 2^3^4^5 = 0.

How should we solve this?

shivamrastogi
Автор

The first question, check if the ith bit is set or not, 0110 is six right, but given i=2, 1<<i will be 4 (0100) not 0010, hence return value should be
return (n&(1<<(i-1)))>0,
am I wrong?

phardik
Автор

sir at first you are taking one mask '010' which is comming from left shift of '001' and after that we are doing bitwise and.

rajdipdas