File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ 626 . Exchange Seats
2+ Solved
3+ Medium
4+ Topics
5+ Companies
6+ SQL Schema
7+ Pandas Schema
8+ Table: Seat
9+
10+ + -- -----------+---------+
11+ | Column Name | Type |
12+ + -- -----------+---------+
13+ | id | int |
14+ | student | varchar |
15+ + -- -----------+---------+
16+ id is the primary key (unique value) column for this table.
17+ Each row of this table indicates the name and the ID of a student.
18+ The ID sequence always starts from 1 and increments continuously.
19+
20+
21+ Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.
22+
23+ Return the result table ordered by id in ascending order.
24+
25+ The result format is in the following example.
26+
27+
28+
29+ Example 1 :
30+
31+ Input:
32+ Seat table:
33+ + -- --+---------+
34+ | id | student |
35+ + -- --+---------+
36+ | 1 | Abbot |
37+ | 2 | Doris |
38+ | 3 | Emerson |
39+ | 4 | Green |
40+ | 5 | Jeames |
41+ + -- --+---------+
42+ Output:
43+ + -- --+---------+
44+ | id | student |
45+ + -- --+---------+
46+ | 1 | Doris |
47+ | 2 | Abbot |
48+ | 3 | Green |
49+ | 4 | Emerson |
50+ | 5 | Jeames |
51+ + -- --+---------+
52+ Explanation:
53+ Note that if the number of students is odd, there is no need to change the last one' s seat.
54+
55+
You can’t perform that action at this time.
0 commit comments