DSAMaster Logo
DSAMaster
BackmediumArrays

Rearrange Seats by Rating

Problem Description

You are given an array of integers seats representing seat popularity ratings. Rearrange the seats such that the highest ratings are at the center, and the lower ratings are towards the sides. Specifically, seats at odd indices should have higher ratings than seats at even indices. If there is an odd number of seats, the middle seat should have the highest rating. Return the rearranged array of seat ratings.

Constraints

  • The input array is never empty
  • The total number of seats is within the range 2 <= n <= 210^5
  • All seats in the input array are unique, and the ratings are guaranteed to be non-negative
  • The ratings of seats can be the same
  • If there are an odd number of seats, the middle seat should have a higher rating.
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute