bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 626. Exchange Seats

626. Exchange Seats

Leetcode Solutions

Swapping Seats Using CASE Statement

  1. Count the total number of seats using a subquery and alias it as counts.
  2. Use a CASE statement to determine the new id for each student:
    • If the id is odd and not the last seat, set the new id to id + 1.
    • If the id is odd and the last seat, keep the id unchanged.
    • If the id is even, set the new id to id - 1.
  3. Select the new id and the student name.
  4. Order the result by the new id in ascending order.
erDiagram
    Seat {
        int id PK
        varchar student
    }

Swapping Seats Using Bit Manipulation and COALESCE()

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...