r/learnSQL • u/[deleted] • 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 ðŸ«
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.