Swap two bits in a number

In this problem, we have to swap bits in a given number or an integer. This can be solved in constant time O(1) using XOR operation. So before moving towards this problem first we have to understand what is a bit that needs to be swapped.

Table of contents:

Introduction to bits and Problem statementNaive ApproachTime and Space Complexity Analysis of Naive ApproachXOR Swap ApproachTime and Space Complexity analysis of XOR Swap ApproachIntroduction to bits and Problem statement

A bit is the...

 •  0 comments  •  flag
Share on Twitter
Published on November 28, 2021 09:07
No comments have been added yet.