365 Days of Daily Coding: Day 108
Hello All, Posting this after much sometime. Mainly because I couldn’t wrap my head around the solution of this challenge. And then I was like “Hey, let’s try another challenge. And then it occured to me that there’s a solution to all the challenges in the site too.” Felt quite dumb but it is what it is.
The link to the challenge is here. I relied on the solution from the site however, the solution is only partially correct. If you try it, you will eventually figure out why I say so.
You could try out the below solution in this oracle environment here.
WITH temp AS (
Select 7 AS Seat FROM Dual Union All
Select 13 AS Seat FROM Dual Union All
Select 14 AS Seat FROM Dual Union All
Select 15 AS Seat FROM Dual Union All
Select 27 AS Seat FROM Dual Union All
Select 28 AS Seat FROM Dual Union All
Select 29 AS Seat FROM Dual Union All
Select 30 AS Seat FROM Dual Union All
Select 31 AS Seat FROM Dual Union All
Select 32 AS Seat FROM Dual Union All
Select 33 AS Seat FROM Dual Union All
Select 34 AS Seat FROM Dual Union All
Select 35 AS Seat FROM Dual Union All
Select 52 AS Seat FROM Dual Union All
Select 53 AS Seat FROM Dual Union All
Select 54 AS Seat FROM Dual
)
SELECT GapStart + 1 GapStart , GapEnd - 1 GapEnd
FROM
(
SELECT Seat AS GapStart ,
LEAD(Seat,1,0) OVER (ORDER BY Seat) AS GapEnd ,
LEAD(Seat,1,0) OVER (ORDER BY Seat) - Seat AS Gap
FROM temp) a
WHERE Gap > 1;

Leave a comment