AC using self join


  • 2
    K
    select distinct a.seat_id
    from cinema a
    join cinema b
    on abs(a.seat_id - b.seat_id) = 1
    and a.free=true and b.free=true
    order by a.seat_id;
    

  • 0

    Same idea:

     select distinct a.seat_id
     from cinema a, cinema b
     where a.free = 1 and b.free = 1 and
     (a.seat_id+1 = b.seat_id or a.seat_id = b.seat_id+1)
     order by a.seat_id asc

Log in to reply
 

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