No video

LeetCode Interview SQL Question with Detailed Explanation | Practice SQL | LeetCode 613

  Рет қаралды 9,228

Everyday Data Science

Everyday Data Science

Күн бұрын

Пікірлер: 21
@pankajchandel1000
@pankajchandel1000 Жыл бұрын
select min(abs(p2.x-p1.x)) as shortest from Point p1 inner join Point p2 where p1.x
@meenayegan6634
@meenayegan6634 2 жыл бұрын
Cross join or windows_function? which one has minimum run_time? Just using an windows function here.... select min(distance) from ( select x, lead (x) over (order by x) as next_pos, lead (x) over (order by x) - next_pos as distance from points )x
@anjanijanyavula373
@anjanijanyavula373 Жыл бұрын
Yep done the same
@abhishekasane2635
@abhishekasane2635 10 ай бұрын
Today Interviewer asked me same question
@EverydayDataScience
@EverydayDataScience 10 ай бұрын
Amazing, hopefully you were able to answer it and will get past to next round. All the best 😊
@prakhargupta2066
@prakhargupta2066 5 ай бұрын
Which company
@anuragkumawat7069
@anuragkumawat7069 8 ай бұрын
We can do it by window function . Or we can create a CTE with rank of the rows. Then join the rank with the next rank+ 1.
@imdeepu7855
@imdeepu7855 Жыл бұрын
select (ax-bx) as shortest from (select x as ax from distance d1) a join (select x as bx from distance d1) b where (a.ax-b.bx)=1
@nikhilvyas9497
@nikhilvyas9497 Жыл бұрын
It can be solved using Window Function too i guess select MIN(abs( next_pos - x )) as Distance FROM (select x, Lead(x) over( order by x) as next_pos from point order by x) a
@27-Joshna
@27-Joshna 9 ай бұрын
From this we are able to get only next position value ie consecutive distance but in order to get a solution we need all possible combinations so i think it doesn't work
@prnvsgr
@prnvsgr 2 жыл бұрын
As you told cross join doesn't require 'on' statement , does it goes same for inner join ..as i tried to use 'on' statement " on p1.x = p2.x" but it is giving null value as shortest value.
@dibakarmandal2148
@dibakarmandal2148 2 жыл бұрын
It is database dependent scenerio, if you use inner join without on clause it will not work in SQL SERVER but in MYSQL that behave as cross join.
@nikitasinha8181
@nikitasinha8181 Жыл бұрын
Thank you so much sir
@raulkishore
@raulkishore Жыл бұрын
Can you explain how it works for duplicate records
@pushankarmakar1783
@pushankarmakar1783 9 ай бұрын
exactly
@yashwani209
@yashwani209 Жыл бұрын
Can this also be done through lead and lag? If table is arranged in ascending order
@anjanijanyavula373
@anjanijanyavula373 Жыл бұрын
No they have't asked for consecutive distance . We have check through all possibility distance so cross is best method.
@yashwani209
@yashwani209 Жыл бұрын
@@anjanijanyavula373 nope first sort the table and then use lead lag
@mlvprasadofficial
@mlvprasadofficial 2 жыл бұрын
12 th
@AmanAshutoshBCS
@AmanAshutoshBCS Жыл бұрын
BUT sir, hum kuch aisa nhi kar sakte hai ki .... Kyunki data ascending order main hai. hence humein to uske next row ke sath compare karna chasiye
@AmanAshutoshBCS
@AmanAshutoshBCS Жыл бұрын
i think by using some windos function we can do that
LeetCode 1251 Interview SQL Question with Detailed Explanation | Practice SQL
17:11
Smart Sigma Kid #funny #sigma #comedy
00:40
CRAZY GREAPA
Рет қаралды 37 МЛН
Harley Quinn's plan for revenge!!!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 30 МЛН
My Cheetos🍕PIZZA #cooking #shorts
00:43
BANKII
Рет қаралды 24 МЛН
LeetCode 1211 Interview SQL Question with Detailed Explanation | Practice SQL
13:28
MLV Prasad - LeetCode SQL [ EASY ] | 0613 | "Shortest Distance in a Line" |
5:41
Data Science University - MLV Prasad
Рет қаралды 293
Smart Sigma Kid #funny #sigma #comedy
00:40
CRAZY GREAPA
Рет қаралды 37 МЛН