No video

LeetCode Medium 180 "Consecutive Numbers" Amazon Uber Interview SQL Question Detailed Explanation

  Рет қаралды 8,560

Everyday Data Science

Everyday Data Science

Күн бұрын

Question: leetcode.com/p...
In this video I solve and explain a medium difficulty leetcode SQL question using MySQL query. This question has been asked in Apple, Facebook, Amazon, Google, Adobe, Microsoft, Adobe interviews or what we popularly call FAANG interviews.
I explain the related concept as well. This question includes points to keep in mind to develop SQL queries.
LeetCode is the best platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.
If you found this helpful, Like and Subscribe to the channel for more content.
#LeetCodeSQL #FAANG #SQLinterviewQuestions

Пікірлер: 32
@EverydayDataScience
@EverydayDataScience 26 күн бұрын
Working solution: WITH cte AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY num ORDER BY id) AS rnk FROM Logs), cte2 AS (SELECT *, (id*1.0-rnk*1.0) AS diff. // multiplication with 1.0 is done so that SIGNED/UNSIGNED difference error doesn't occur FROM cte) SELECT DISTINCT num AS ConsecutiveNums FROM cte2 GROUP BY diff, num HAVING COUNT(*) >= 3;
@aspirationqueen
@aspirationqueen 2 ай бұрын
when id's are jumbled up and id's don't follow sequence use this query with cte as ( select id, num ,lead(num,1) over(order by id) as next, lead(num,2) over(order by id ) as next_2_next, lead(id,1) over(order by id) as next_team_id, lead(id,2) over(order by id) as next_2_next_team_id from Logs ) select distinct num as ConsecutiveNums from cte where (num=next and num=next_2_next) and (id+1=next_team_id and id+2=next_2_next_team_id)
@supriyakushwaha21
@supriyakushwaha21 Ай бұрын
I WAS WONDERING WHY THE CODE IN THIS VIDEO IS NOT WORKING. BUTY, AFTER WRITING YOUR CODE , ALL TESTCASES PASSED. THANKS
@june17you
@june17you 29 күн бұрын
Hi Bro, The given solution is not working currently. Not sure if test cases are updated. Kindly help us if there is any other easy approach to solve this. Thank you
@saisaketh8433
@saisaketh8433 9 ай бұрын
These videos are very helpful in learning sql!!!!
@KshitijSoni-kn2gp
@KshitijSoni-kn2gp 3 ай бұрын
This won't work when Id's are jumbled up
@aspirationqueen
@aspirationqueen 2 ай бұрын
with cte as ( select id,num,lead(num,1) over(order by id) as next,lead(num,2) over(order by id ) as next_2_next, lead(id,1) over(order by id) as next_team_id,lead(id,2) over(order by id) as next_2_next_team_id from Logs ) select distinct num as ConsecutiveNums from cte where (num=next and num=next_2_next) and (id+1=next_team_id and id+2=next_2_next_team_id) can use this one
@EverydayDataScience
@EverydayDataScience 26 күн бұрын
WITH cte AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY num ORDER BY id) AS rnk FROM Logs), cte2 AS (SELECT *, (id*1.0-rnk*1.0) AS diff. // multiplication with 1.0 is done so that SIGNED/UNSIGNED difference error doesn't occur FROM cte) SELECT DISTINCT num AS ConsecutiveNums FROM cte2 GROUP BY diff, num HAVING COUNT(*) >= 3;
@amanraheja2905
@amanraheja2905 Жыл бұрын
brilliant solution thanks
@oliver_comp
@oliver_comp Жыл бұрын
explanation top 100%
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Glad that you found the video useful 😊
@PiyushKumar-tv6dr
@PiyushKumar-tv6dr 3 ай бұрын
for sql server? we can't mention inside the argument in lead function
@gowtham4383
@gowtham4383 Жыл бұрын
Great. Thanks
@user-qf4il9qt3p
@user-qf4il9qt3p Жыл бұрын
why can't we write where num = next_1 = next_2? Thank you!
@rupdeepthey
@rupdeepthey Жыл бұрын
Fails for negative nums idk why.
@digitaldruglord7232
@digitaldruglord7232 3 ай бұрын
perfectly explained, Thnx
@callmeruks
@callmeruks Жыл бұрын
Great Explanation
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Glad that you found it useful, Rukshar.
@callmeruks
@callmeruks Жыл бұрын
@@EverydayDataScience Can you make a video on Tree node -problem 608
@rupdeepthey
@rupdeepthey Жыл бұрын
Awesome !!
@EverydayDataScience
@EverydayDataScience Жыл бұрын
Glad that you found the video useful 😊
@RajeshKumar._.16
@RajeshKumar._.16 11 ай бұрын
nice
@massvinod8413
@massvinod8413 27 күн бұрын
This solution is not working for some test cases. Please check it once .
@EverydayDataScience
@EverydayDataScience 26 күн бұрын
WITH cte AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY num ORDER BY id) AS rnk FROM Logs), cte2 AS (SELECT *, (id*1.0-rnk*1.0) AS diff. // multiplication with 1.0 is done so that SIGNED/UNSIGNED difference error doesn't occur FROM cte) SELECT DISTINCT num AS ConsecutiveNums FROM cte2 GROUP BY diff, num HAVING COUNT(*) >= 3;
@atharvaathalye
@atharvaathalye Ай бұрын
test case with 4 1's are not accepting.
@EverydayDataScience
@EverydayDataScience 26 күн бұрын
WITH cte AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY num ORDER BY id) AS rnk FROM Logs), cte2 AS (SELECT *, (id*1.0-rnk*1.0) AS diff. // multiplication with 1.0 is done so that SIGNED/UNSIGNED difference error doesn't occur FROM cte) SELECT DISTINCT num AS ConsecutiveNums FROM cte2 GROUP BY diff, num HAVING COUNT(*) >= 3;
@ce_070_sunny_nath8
@ce_070_sunny_nath8 Жыл бұрын
Sir please update the solution since question is telling that atleast three so there can be many more occurrences for same no.
@aakashmittal8598
@aakashmittal8598 10 ай бұрын
use DISTINCT in SELECT statement: WITH cte AS( SELECT *, LEAD(num,1) OVER() AS NEXT_1, LEAD(num,2) OVER() AS NEXT_2 FROM Logs) SELECT DISTINCT num AS ConsecutiveNums FROM cte WHERE num = NEXT_1 AND num = NEXT_2;
@EverydayDataScience
@EverydayDataScience 26 күн бұрын
WITH cte AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY num ORDER BY id) AS rnk FROM Logs), cte2 AS (SELECT *, (id*1.0-rnk*1.0) AS diff. // multiplication with 1.0 is done so that SIGNED/UNSIGNED difference error doesn't occur FROM cte) SELECT DISTINCT num AS ConsecutiveNums FROM cte2 GROUP BY diff, num HAVING COUNT(*) >= 3;
@rayyanamir8560
@rayyanamir8560 2 жыл бұрын
Thanks sir for such a great explanation. What's your paypal?
@user-bk5mk9zl9g
@user-bk5mk9zl9g 10 ай бұрын
@kelvinlow823
@kelvinlow823 Жыл бұрын
brilliant solution thanks
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 11 МЛН
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 22 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 37 МЛН
SQL Interview Problem asked during Amazon Interview
15:15
techTFQ
Рет қаралды 23 М.
LeetCode 180: Consecutive Numbers [SQL]
5:27
Frederik Müller
Рет қаралды 22 М.
LeetCode Medium 1341 "Movie Rating" SAP Interview SQL Question with Explanation
12:04
LeetCode 626: Exchange Seats [SQL]
7:58
Frederik Müller
Рет қаралды 9 М.
33. Consecutive Numbers | SQL Interview Questions and Answers
5:59
Start Practicing
Рет қаралды 1 М.
LeetCode 1251 Interview SQL Question with Detailed Explanation | Practice SQL
17:11
Whiteboard Coding Interviews: 6 Steps to Solve Any Problem
15:18
Fullstack Academy
Рет қаралды 367 М.
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 11 МЛН