mediumArraysPattern: NEW OR EXISTING ID

Optimal Stage Index Shifts Solution

Problem Statement

You are a music festival organizer, and you want to ensure that music groups are placed on stages with a specific order, but the original lineup must be accommodated within the stage's available space. Given a list of group names and their original lineup indices, determine which groups that are not on the first position of the stage are able to move to a new index to maintain the correct order while minimizing the number of shifts within the stage's capacity (limited to 10 unique stages).

Constraints

  • The number of groups is between 2 and 10 (inclusive).
  • The original lineup index for each group is between 1 and the number of stages (inclusive).
  • The number of stages is 10 (unique and does not repeat).
  • Groups are considered not shifted if they are already at the first position.
Time: O(n*m) Space: O(n)
To optimize this solution, we can maintain an index to track the current position in the output array and only shift groups that are not at their correct position.

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.