Daily Leetcode Challenge | Nov 8 | Maximum XOR for Each Query

preview_player
Показать описание
Daily Leetcode Challenge- November 2024 - Day 8 - Maximum XOR for Each Query

Approach: bit manipulation ( xor properties )

optimized approach beats 90% of the test cases

Like, share and subscribe
***********************
Hi, I am a SDE , at one of the Fortune 50 companies!!

The intent of this channel is to motivate the community to code everyday, and also to make their coding rounds-during interview, a bit easier !! :)

Every question has a 1)brute-force approach 2)optimized approach, and the language used is simple English

I try my best to keep my solutions beginner friendly and simple to understand.

thanks for your support!! :)
***********************

Leetcode Today Challenge,
Daily Coding Practise,
Leetcode 100 days of code,
Python Daily Coding Challenge,
Daily LeetCoding Challenge ,
daily leetcode challenge,
daily leetcode questions,
daily leetcode problem,
leetcode daily today,
leetcode daily problem today,
leetcode daily challenge,
leetcode daily practise,
leetcode solutions,
letcode python,
leetcode hard problems,
leetcode easy problems,
leetcode medium problems,
leetcode for begineers,
leetcode python problems,
leetcode python,
leetcode python solutions,
leetcode python hard,
leetcode python medium,
leetcode python easy,
leetcode python english,
leetcode python solutions in english
Where to learn dp
where to learn graphs
where to learn dsa
how to start programming
how to start coding
where to learn trees
what is memoisation
what is tabulation
what are graphs
where to learn Operating systems
where to learn dbms
where to learn oops
where to learn computer networks
where to learn low level design
where to learn cs fundamentalS
Gate smashers
Placement guide
How to start programming
where to learn cpp
where to learn python
where to learn javascript
where to learn java
Placement guide
languages to learn
resources to learn data structures
Projects development
Software developer engineer ,
Importance of side projects ,
How to become a machine learning engineer ,
Associate engineer
Data structures Algorithms
College Life, College, Memories
Where to learn dp
where to learn graphs
where to learn dsa
how to start programming
how to start coding
where to learn trees
what is memoization
what is tabulation
what are graphs
where to learn programming
how to start coding
where to learn coding
where to learn DSA
resources to learn programming
how to crack amazon
how to crack placement
what is blockchain
blockchain technology explained
blockchain technology in hindi
web development roadmap
android development roadmap
MERN stack roadmap
roadmap for 2nd years
roadmap for opensource
roadmap for ios development
roadmap to learn DSA
microsoft internship,
microsoft intern 2022,
microsoft internship India,
microsoft internship experience
microsoft,software engineer

#leetcode #leet_preparation_tips #leetcodesolution #coding #interview
#CodingInterview #NovemberLeetCodingChallenge #Google #Amazon #programming #march #codinglife #meta #faang #maang
Рекомендации по теме
Комментарии
Автор

class Solution:
def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:
xorResult=nums[0]
for i in nums[1:]:
xorResult=xorResult^i

n=len(nums)
#print(xorResult, bin(xorResult)[2:])

answer=[]
for i in range(n):

print('xor result=', xorResult, 'In binary:', binaryResult)


print('writing xorResult in maximumBits ', binaryResult)
#print(binaryResult)
k=''
for bit in binaryResult:
if(bit=='1'):
k+='0'
else:
k+='1'
print('after negating xor result: ', k)
answer.append(int(k, 2))
#remove last element
lastEle=nums[-i-1]
xorResult=xorResult^lastEle
print(answer)
print('removed element:', lastEle)

return answer

darshankumar
Автор

let a=101
a xor b should be max
ie a xor b = 111
then b= 010

a^b=k
k^b=a
k^a=b

#example 2 tracing-DRY RUN

xor result= 2 In binary: 10
writing xorResult in maximumBits 010
after negating xor result: 101
[5]
removed element: 7
xor result= 5 In binary: 101
writing xorResult in maximumBits 101
after negating xor result: 010
[5, 2]
removed element: 4
xor result= 1 In binary: 1
writing xorResult in maximumBits 001
after negating xor result: 110 =4+2+0=6
[5, 2, 6]
removed element: 3
xor result= 2 In binary: 10
writing xorResult in maximumBits 010
after negating xor result: 101
[5, 2, 6, 5]
removed element: 2

darshankumar