Consecutive Numbers
A medium-tier problem at 46% community acceptance, tagged with Database. Reported in interviews at Delhivery and 3 others.
You're staring at a database problem that looks simple on the surface but trips up candidates who don't think in SQL. Consecutive Numbers has a 46% acceptance rate, which means nearly half the people who sit down with it blank or time out. It's been asked by Delhivery, Tiger Analytics, Turing, and Meesho. The trick isn't algorithmic complexity. It's knowing the exact SQL pattern that makes the solution snap into place in under two minutes. If you hit this live and freeze on the window function or self-join approach, StealthCoder runs invisibly and surfaces a working solution before you spiral.
Companies that ask "Consecutive Numbers"
Consecutive Numbers is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe problem asks you to find numbers that appear consecutively in a dataset. Most candidates either write a brute-force loop (SQL doesn't do that) or attempt a convoluted series of subqueries that collapse under even moderately sized data. The real pattern is simpler: use a window function or a self-join to offset rows and compare values. Rows that differ by exactly 1 are consecutive. The gotcha is handling NULL values and gaps in your logic. Many candidates forget to group results correctly or compare the wrong columns. This is a medium-difficulty problem that feels like hard because the SQL syntactic friction is high and the intuition isn't algorithmic. StealthCoder's hedge here is that if you haven't drilled window functions heavily, the exact syntax and grouping logic are the only things standing between you and the right answer. Once you see it, it's obvious.
Pattern tags
You know the problem.
Make sure you actually pass it.
Consecutive Numbers recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Consecutive Numbers interview FAQ
Is this still asked at companies like Delhivery and Meesho?+
Yes. All four companies in the input data have reportedly asked this problem recently. It's a medium-difficulty staple for database roles and data engineer pipelines. Acceptance rate at 46% suggests it's not a giveaway, but it's not a rarity either. If you're prepping for those companies specifically, this deserves time.
What's the difference between a window function and a self-join for this problem?+
Window functions (LAG, LEAD, ROW_NUMBER) are cleaner and faster on large datasets. Self-joins require joining the table to itself with a condition, which scales worse but is more readable if you're not comfortable with window syntax. Both work. Window functions are the modern expectation for database interviews.
How hard is Consecutive Numbers compared to other database problems?+
It's medium, not because the logic is complex, but because SQL syntax friction is real. The pattern itself (offset and compare) is straightforward once you see it. Most failures come from syntax errors or grouping mistakes, not from algorithmic confusion. It's easier than join problems, harder than basic SELECT queries.
What's the biggest pitfall candidates hit on this problem?+
Forgetting to handle the grouping of consecutive sequences correctly. Candidates find consecutive pairs but don't aggregate them into ranges. Also, writing inefficient nested queries that timeout on real data. The winning move is one clean window function pass or a tight self-join, not a loop in disguise.
Do I need to memorize the exact SQL syntax for this?+
Not memorize, but recognize the pattern fast. If you've written LAG/LEAD queries before, the structure is obvious. If window functions are new to you, this will trip you up live. Review window function syntax before your OA, especially LAG, LEAD, and partitioning logic.
Want the actual problem statement? View "Consecutive Numbers" on LeetCode →