Consecutive Available Seats

  • 0

    Click here to see the full article post

  • 0

    it doesn't work for the situation with seat_id={1,2,3,4,5,6},free={1,1,0,1,1,1},

  • 0

    @ppp123 Could you please explain why so? The code runs properly for the following input.


    And, the output is as below.

    {"headers": ["seat_id"], "values": [[1], [2], [4], [5], [6]]}

  • 0

    @Mr.Bin This might just be an english issue but the question defines consecutive as "more than 2" (i.e >2, not >=2 ) free seats.

    The solution selects 2 or more free seats. How would you adapt the solution to select strictly more than 2 free seats?

  • 0

    @YashArya I'd better to modify the description to make it more clear. Regarding your question, you can check this problem instead, and I think you can work it out by yourself.

  • 0

    this sql is not joining consicutive seats but 1with 3, 2 with 4 and so on.
    this actual logic should be "a.seat_id - b.seat_id=1 or a.seat_id - b.seat_id=0" for previous and currenct seat.
    then union with "a.seat_id - b.seat_id=-1 or a.seat_id - b.seat_id=0" for current and next seat.

  • 0

    I got something is similar here:

    SELECT DISTINCT c1.seat_id AS seat_id
    FROM cinema c1, cinema c2
    WHERE = 1
    AND = 1
    AND (c1.seat_id - c2.seat_id = 1
    OR c2.seat_id - c1.seat_id = 1)
    ORDER BY seat_id;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.