180. Consecutive Numbers
UnknownView on LeetCode
Problem Overview
Consecutive Numbers is a unknown-difficulty LeetCode problem. This is a common Database pattern in coding interviews. Study the solution below and note the time and space complexity before attempting variations on your own.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Read the solution code below and trace through it on paper before submitting. For structured interview prep, follow our 30-day study guide.
180.sql
MySQL
/* Write your T-SQL query statement below */
WITH
LogsNeighbors AS (
SELECT
*,
LAG(num) OVER(ORDER BY id) AS prev_num,
LEAD(num) OVER(ORDER BY id) AS next_num
FROM LOGS
)
SELECT DISTINCT num AS ConsecutiveNums
FROM LogsNeighbors
WHERE
num = prev_num
AND num = next_num;Was this solution helpful?
Related Problems
- 176. Second Highest Salary(Unknown)
- 178. Rank Scores(Unknown)
- 620. Not Boring Movies(Unknown)
- 627. Swap Salary(Unknown)
- 1873. Calculate Special Bonus(Unknown)
- 2889. Reshape Data Pivot(Unknown)