Minimum AND XOR OR - Codexplained

preview_player
Показать описание
On Episode 42 of Codexplained, we're going to be tackling the coding problem, "Minimum AND XOR OR". We're going to be breaking down a few mathematical concepts and deriving proof as to why our approach works. All you math-heads out there are going to love this part!

TIMESTAMPS
----------------------
0:00 - Introduction
0:31 - Problem Explanation
2:24 - Solution
9:53 - Code
10:57 - Conclusion
Рекомендации по теме
Комментарии
Автор

I also done this problem but i just try and tested some example and reach this approach, but your effort help me a lot to understand the solution much better.

rajgupta
Автор

This works great for unsigned integers, but for signed integers consider the case where
a=-1
b= 0
c=INT_MAX
It is true then that a<b<c
However
(a^c) == INT_MIN
(a^b) == -1
(b^c) == INT_MAX
So a^c is smaller than both a^b and b^c

ratman
Автор

can you please help me in java i have done everything that i know but it shows time limit exceed in two cases . BTW thanks for that great problm and awesome solution

harmeetsingh
Автор

dont know about explanation but you read very good

HonestFeedback-gyhu
Автор

I have done the same using python 3, though it is passing the sample test case it did not pass when i submit the code
t=int(input())
while t!=0:
n=int(input())
arr=list(map(int, input().split()))
arr.sort()
min=arr[0] ^ arr[1]

for i in range(1, n-1):
temp = arr[i] ^ arr[i + 1]
if temp < min:
min = temp

print(min)

print("")
t-=1

vennachadsaikiran
Автор

How much maths is a coder expected to know?
I didn't know this property that the minimum value will be found by comparing adjacent elements in a sorted list. This was the most critical thing, and I can't expect that I'll be able to come up with is in real time.

thewayofworks
Автор

I appreciate your effort, but this the problem with any YouTube video. The demand here is to know everything before your start watching. By the time it's crossed the sorting part, I was lost in the process. Like come on use atleast a good notepad app. Why data was not represented in the 8-bit format, how you get -16 why sorting works are all in background. Sorry not demotivating here the creater of the video.

ssshukla
Автор

Time limited exceeded in test case 3 and 8. I am using Kotlin.

raquibulislam
Автор

can you give the solutions in python 3 it will very helpful

rishisharma
Автор

what about this then, (18^8=26, 18^2=16), your explanation doesn't follow

nischayraj