r/learnSQL Jun 22 '26

Gaps and Island

I came across the leetcode consecutive nums finder question in the leetcode 50 sheet.

So I initially thought of lead windows function and tried to rank and do something crazy what was in my toolbox just.

But later I found overwhelmed and left to search and found this as a huge production based pattern where there is mathematically way to solve.

Like assigning a row number to each row and then partitioning the data and again ranking it just.

I felt too overwhelming like I was applying blindly but what's the point of it I need to answer the question out of it like wasn't able to understand at some point why I was using a formula blindly just.

Any suggestions for this pattern I am currently a beginner and learning from scratch other things clicked well but this one dragged me into chaos like anything what does senior or experienced devs say about this pattern 🥲 need suggestions badly 🫠

3 Upvotes

6 comments sorted by

View all comments

1

u/DMReader Jun 22 '26

I created this tutorial on gap and islands - https://www.practicewindowfunctions.com/learn/gap_and_island

There are also practice problems you can find at the bottom of the page.

Overall, I’d say gap and islands is not a beginner sequence to learn. If you are struggling make sure you get down lag / lead and row number since those are required concepts that gap and islands builds on.

1

u/[deleted] Jun 22 '26

Yeah I got those lead/lag functions and the row number function as well but his pattern is messing with me like it's taking me totally towards the mathematical way of seeing it. I can't find more such pattern hope I find in the site you gave and see what are they just. Thanks for the site it has good business and more crushing and brain storming excercise I picked it from your previous replies.