Last Person to Fit in the Bus | Leetcode 1204 | Crack SQL Interviews in 50 Qs

  Рет қаралды 4,574

Learn With Chirag

Learn With Chirag

Күн бұрын

Пікірлер: 26
@learnwithchirag
@learnwithchirag 10 ай бұрын
Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on Instagram Handles :- @createwithchirag - instagram.com/createwithchirag/ @learn.with.chirag - instagram.com/learn.with.chirag/ LinkedIn: www.linkedin.com/in/chirag-sehgal-9200111b8/ Let's stay connected and keep the creativity flowing! 💡
@riteshchaudhary8755
@riteshchaudhary8755 9 ай бұрын
Why do we use > operation in this condition (on q1.turn >= q2.turn)?
@akashsingh2722
@akashsingh2722 2 ай бұрын
Because we want the last person that exceeds the weight limit to be included in to list as well cuz that's thee guy that'll be the potential "last guy to fit into the bus"
@ARkhan-xw8ud
@ARkhan-xw8ud 6 ай бұрын
Didn't got it
@learnwithchirag
@learnwithchirag 6 ай бұрын
Hi , which part of the solution you aren't able to understand?
@sakshigandhi6059
@sakshigandhi6059 6 ай бұрын
@@learnwithchirag can you explain when and why we are taking q1 then we take q2 its confusing to understand that whn do we use q1 or q2
@ARkhan-xw8ud
@ARkhan-xw8ud 5 ай бұрын
why it returns 3 table instead of 4
@anirudhsinghsolanki6256
@anirudhsinghsolanki6256 4 ай бұрын
easy method :- select person_name from ( SELECT person_name,turn, sum(weight) over (order by turn) AS weight FROM queue) p where weight
@MuhammadAzeem-he6qr
@MuhammadAzeem-he6qr 10 ай бұрын
1) Why do we use > operation in this condition (on q1.turn >= q2.turn) 2) Why do we use q2 in sum(q2.weight) , as all weights in q2 are same which is 250 with the same person?
@ayanghosh7692
@ayanghosh7692 7 ай бұрын
I also have the same question. why q2.weight gives the result of q1.weight? if you got answer please reply.
@metatrader189
@metatrader189 3 ай бұрын
first one to arrange smaller turns in q2 table so that we can sum up later using sum(q2.weight)
@ranitmandal6393
@ranitmandal6393 9 ай бұрын
the solution using window function- select x.person_name from (select turn,person_id,person_name,weight, sum(weight) over(order by turn ) as total_weight from Queue order by turn desc)x where x.total_weight
@raunakkumar9521
@raunakkumar9521 5 ай бұрын
how to know that where i have to used q1 and where i have to used q2 in this question.
@ashish3487
@ashish3487 4 ай бұрын
sir why did we use sum(q2.weight)
@prathamsharma4416
@prathamsharma4416 9 ай бұрын
its accepted on leetcode, but its not running on workbench, why??
@apoorvpradhan5125
@apoorvpradhan5125 5 ай бұрын
Thank you bhaiya.
@akhilpratapsingh3223
@akhilpratapsingh3223 Жыл бұрын
Great Explanation Sir
@learnwithchirag
@learnwithchirag Жыл бұрын
Keep watching :-)
@rey619ashkash
@rey619ashkash 10 ай бұрын
With cte as ( select *, sum(weight) over ( order by turn) as w1 from queue) select person_name from cte where w1
@learnwithchirag
@learnwithchirag 10 ай бұрын
In terms of efficiency, the query using the CTE and window function is likely to perform better, especially on larger datasets, because it avoids the need for a self-join and calculates the cumulative sum in a single pass through the data. Therefore, the query using the CTE and window function is generally more efficient for this particular task. The purpose of this playlist was to clear the basics and form a strong foundation of SQL amoung people ! Ofcourse the queries can be optimized when writing for a larger database.
@abhinashnayak100
@abhinashnayak100 6 ай бұрын
select person_name from (SELECT *, sum(weight) over (order by turn) AS sum_w FROM queue) as p1 where sum_w
@nimbu_03
@nimbu_03 Жыл бұрын
This is easy than previous one for sure :D
@learnwithchirag
@learnwithchirag Жыл бұрын
Yes for sure 🎉
@mohammedsuboorahmed6282
@mohammedsuboorahmed6282 Ай бұрын
With cte as (Select *, sum(weight) over (order by turn rows between unbounded preceding and current row) as total from queue) Select person_name from cte Where total
@tenzinchoepheldev
@tenzinchoepheldev 7 күн бұрын
My code goes like. -------------------------- with cte as ( select person_name , sum(weight) over ( order by turn) as weight_sum from Queue order by turn desc ) select person_name from cte where weight_sum
@krishnabohidar7226
@krishnabohidar7226 2 ай бұрын
select person_name from ( select person_name,weight,turn, sum(weight) over(order by turn) as w from Queue) xyz where xyz.w
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
The Ultimate SQL Window Functions Course | Complete End-to-End Guide
3:51:23
35. Last Person to Fit in the Bus | SQL Interview Questions and Answers
7:55
Learn 12 Basic SQL Concepts in 15 Minutes (project files included!)
16:48
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 96 М.
Querying 100 Billion Rows using SQL, 7 TB in a single table
9:07
Arpit Agrawal (Elastiq.AI)
Рет қаралды 57 М.
Что такое SQL?
7:11
Merion Academy
Рет қаралды 367 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 224 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 849 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН