LeetCode Interview SQL Question with Detailed Explanation | Practice SQL | LeetCode 603 | Window Fun

  Рет қаралды 21,069

Everyday Data Science

Everyday Data Science

Күн бұрын

Пікірлер: 53
@justcodeitbro1312
@justcodeitbro1312 5 ай бұрын
this guy is a blessing
@energizer9814
@energizer9814 11 ай бұрын
One of the another approch we can try is SELECT sub.seat_id FROM (SELECT *, LEAD(free) OVER(ORDER BY seat_id) AS NextSeat FROM Cinema) AS sub WHERE sub.free = 1 AND (sub.NextSeat = 1 OR sub.NextSeat IS Null) ORDER BY sub.seat_id; I hope this might run faster, not very sure
@Lucky-hh4cg
@Lucky-hh4cg Жыл бұрын
really amazing... thanks for sharing.
@samuraibhai007
@samuraibhai007 2 жыл бұрын
Thank you. I tried using LAG / LEAD for this question but was unable to solve it. Your explanation clarified things a bit more. I don't think this is an "Easy" problem as LeetCode has labeled it...
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Glad to know that the explanation was helpful. Thanks for appreciating, Rofi.
@alokkumardutta3298
@alokkumardutta3298 2 жыл бұрын
Hello, I recently discovered your channel through the comment section of an Instagram post, and after watching a few videos, I'm glad I found your channel. Thank You so much for sharing your knowledge with us. I'd really love to hear some career advice from you when it comes to data science (maybe a new video series where you can discuss tips for beginners).
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Glad that you are finding the videos useful, Alok. Thanks for such kind words. Sure, I am thinking about it as well. Will soon try to come up with some videos.
@imdeepu7855
@imdeepu7855 2 жыл бұрын
select w.seat_id from (select *, ifnull(( LEAD(free) over (order by seat_id)),"1") as Next_Seat from Cinema) as w where w.free =1 and w.Next_Seat=1
@anonymous-ze5fg
@anonymous-ze5fg 11 ай бұрын
Great explanation, really helpful, Please keep making more sql related videos,
@EverydayDataScience
@EverydayDataScience 11 ай бұрын
Definitely, videos are coming daily 😊
@asifbasheerkhan2855
@asifbasheerkhan2855 2 жыл бұрын
I really loved this playlist. Thankyou.
@abhisheksharma6617
@abhisheksharma6617 2 ай бұрын
It's a little easier to follow, using a CTE : with cte as (select *, lead(free) over(order by seat_id) ld, lag(free) over(order by seat_id) lg from cinema) select seat_id from cte where free=ld or free=lg order by seat_id;
@muhammadasjadsheikh7502
@muhammadasjadsheikh7502 Жыл бұрын
hey Buddy I just Recently came across with your channel and found it very useful your explanation and approach is very good Thanks for such a Informative Content
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Thanks for such kind words. Glad that you are finding the videos useful 😊
@T5AGamerz
@T5AGamerz 2 жыл бұрын
Amazing series with lucid explanation, thnkyou
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Glad that you are finding the videos helpful.
@Ilovefriendswebseries
@Ilovefriendswebseries 6 ай бұрын
Another approach select seat_id from ( select *,(seat_id-lag(seat_id,1) over () ) as diff from cinema )A where free-diff=0;
@manasagiduthuri6557
@manasagiduthuri6557 9 ай бұрын
Hello @Everyday Data Science, your video lectures are awesome . Thanks for making such video lectures.. but how can i practice all leetcode questions without subscription
@348_rahulbehera4
@348_rahulbehera4 2 жыл бұрын
Hey @Everyday Data Science, your video lectures are awesome 🙌. Thanks for making such video lectures 👍🤗. PS: Add the Problem link in the description so that we can access the questions directly.
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Glad that you are finding it useful. Yes I have started adding it in the description now. Some initial videos don’t have it but now every videos after those initial ones have the links as well.
@rawalrohit7929
@rawalrohit7929 2 жыл бұрын
Thanks for this clear explaination
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Glad that you found this video useful, Rawal.
@manasagiduthuri6557
@manasagiduthuri6557 9 ай бұрын
can you give any suggestion to practice
@svanaja331
@svanaja331 2 жыл бұрын
Bro please make video on over clause........
@atharvameher5880
@atharvameher5880 2 ай бұрын
can we solve this w/o the lead lag, using joins?
@sany2k8
@sany2k8 2 жыл бұрын
Can we add null condition instead of introducing lag?
@Manojkumar__
@Manojkumar__ Жыл бұрын
i think if you use Null , then Seatid 1 will also come in result...
@itechinnovations2200
@itechinnovations2200 Жыл бұрын
​@@Manojkumar__ how come the first will come in results becz for the first one next seet is not equal to zero as well as is not not null since it zero
@dhawalsood2654
@dhawalsood2654 7 ай бұрын
great explanation. just 1 question where u have written w.free=1 and w.nextseat=1. Can't we write for 0 also?? (w.free=1 and w.nextseat=1) OR (w.free=0 and w.nextseat=0)
@tejaswaniguttula5961
@tejaswaniguttula5961 7 ай бұрын
@dhawalsood2654 Here free column having values 0 or 1 (Boolean ) 1 means that the seat is free not yet filled 0 means seat is filled not free. So, (1,1) means both seats are free . (0,0) Means both seats are not free(filled) (1,0) Or (0,1) one of the seats are filled. Hope you understood. Happy learning 😊
@PawanSingh-jx8nu
@PawanSingh-jx8nu 9 ай бұрын
create table #Cinema ( seat_id int primary key identity(1,1), free bit ) insert into #Cinema values (1),(0),(1),(1),(1) select * from #Cinema select seat_id from ( select *, lead(free)over(order by seat_id) nextSeat, lag(free) over(order by seat_id)prevset from #Cinema ) s where nextSeat=1 and free=1 or prevset=1 and free=1
@soumikdey1456
@soumikdey1456 Жыл бұрын
instead i=of adding LAG function, can we write like WHERE W.free = 1 and W.NextSeat = 1 or W.free = 1 and W.NextSeat = null?
@amitshankhwar2542
@amitshankhwar2542 Жыл бұрын
We can't check null value like this
@pavanch9256
@pavanch9256 2 жыл бұрын
Please provide us the solution using the github link.
@nazrusheriff7229
@nazrusheriff7229 Жыл бұрын
SELECT seat_id FROM cinema WHERE free = 1 AND ( seat_id + 1 IN (SELECT seat_id FROM cinema WHERE free = 1) OR seat_id - 1 IN (SELECT seat_id FROM cinema WHERE free = 1) ); This can also be a solution
@vamsimadugula8524
@vamsimadugula8524 11 ай бұрын
You can use common table expression to optimise even further
@dancingindia24
@dancingindia24 2 жыл бұрын
thankyou
@sagarghare9829
@sagarghare9829 Жыл бұрын
I like your video. I guess you should teach on normal white paper or iPad with pencils with examples. It will be easier to catch up and remember
@maheshodedra8609
@maheshodedra8609 2 жыл бұрын
Hi There, Thanks for the Great explanation we can use this approach as well. Select c1.seat_id, c2.seat.id, c3.seat_id from Cinema c1 join Cinema c2 on c1.seat_id + 1 = c2.seat.id and c1.free = c2.free join Cinema c3 on c1.seat_id + 2 = c3.seat.id and c1.free = c3.free
@luyaowang4606
@luyaowang4606 6 ай бұрын
i did the same~
@AbdulRahman-zp5bp
@AbdulRahman-zp5bp 2 жыл бұрын
Bro, Please start a playlist of python where you solve interview Questions(of level Easy, Medium to Hard) while explaining logic, I'll be waiting Thanks 🙂
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Hey Abdul, sure I’ll start on the playlist very soon. I’m glad that you are finding these videos useful 😊
@AbdulRahman-zp5bp
@AbdulRahman-zp5bp 2 жыл бұрын
@@EverydayDataScience Thanks, keep going 😊
@mlvprasadofficial
@mlvprasadofficial 2 жыл бұрын
4TH ONE
@EverydayDataScience
@EverydayDataScience 2 жыл бұрын
Awesome!
@pankajchandel1000
@pankajchandel1000 Жыл бұрын
this will only work if the seat_id increase by 1. select distinct t1.seat_id from Cinema as t1 join Cinema as t2 on abs(t1.seat_id -t2.seat_id) =1 and t1.free =1 and t2.free=1 order by t1.seat_id;
@ansylpinto2301
@ansylpinto2301 Жыл бұрын
this looks like a good solution
@pragatiaggarwal8103
@pragatiaggarwal8103 Жыл бұрын
I did not understand how it worked out. Can u please explain me
@pankajchandel1000
@pankajchandel1000 Жыл бұрын
select C.seat_id from (select *,LEAD(free) over(ORDER BY seat_id ) as Next,LAG(free) over(ORDER BY seat_id) as Prev from Cinema) as C where C.free =1 and C.Next=1 or C.free=1 and C.prev=1) ORDER BY C.seat_id ;
@yassinbenyahia6801
@yassinbenyahia6801 23 күн бұрын
I don't think it is an easy problem here is a more simple solution: "select distinct S1.seat_id from Cinema S1 join Cinema S2 on (Abs(S1.seat_id-S2.seat_id)=1) and S1.free=1 and S2.free=1 order by S1.seat_id ASC ;"
@Happyface-dm5nh
@Happyface-dm5nh Ай бұрын
MY CODE SELECT SEAT_ID FROM (select SEAT_ID AS SEAT_ID , FREE , LEAD (free) OVER (ORDER BY SEAT_ID) AS NEXT_SEAT,LAG(free) OVER (ORDER BY SEAT_ID) AS PRE_SEAT from Cinema ) WHERE FREE = NEXT_SEAT OR FREE = PRE_SEAT
@surbhirautaray6872
@surbhirautaray6872 Жыл бұрын
Sir, if you have LinkedIn account, give me please
@energizer9814
@energizer9814 11 ай бұрын
One of the another approch we can try is SELECT sub.seat_id FROM (SELECT *, LEAD(free) OVER(ORDER BY seat_id) AS NextSeat FROM Cinema) AS sub WHERE sub.free = 1 AND (sub.NextSeat = 1 OR sub.NextSeat IS Null) ORDER BY sub.seat_id; I hope this might run faster, not very sure
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН
GIANT Gummy Worm #shorts
0:42
Mr DegrEE
Рет қаралды 152 МЛН
She wanted to set me up #shorts by Tsuriki Show
0:56
Tsuriki Show
Рет қаралды 8 МЛН
LeetCode 1280 Interview SQL Question with Detailed Explanation | Practice SQL
20:13
Learn SQL In 60 Minutes
56:24
Web Dev Simplified
Рет қаралды 2,2 МЛН
Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF
28:34
Decomplexify
Рет қаралды 2,2 МЛН
LeetCode 1241 Interview SQL Question with Detailed Explanation | Practice SQL
15:09
Leetcode 2547. Minimum Cost to Split an Array || Java
35:27
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН