BackmediumArrays Accenture

Array Index Shift Solution

Problem Statement

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 within the stage's available space.

Example 1
Input
[['Blackpink', 1], ['EXO', 2], ['Red Velvet', 3], ['Twice', 4]]
Output
[1, 2, 3, 4]

Explanation: Step-by-step: Given the input [['Blackpink', 1], ['EXO', 2], ['Red Velvet', 3], ['Twice', 4]], we first check if the group is not at the first position (i.e., its index is not 1). If it is not at the first position, we increment its index by 1. The output is then [1, 2, 3, 4].

Example 2
Input
[['BTS', 1], ['BTS', 1], ['BTS', 1], ['BTS', 1]]
Output
[2, 3, 4, 5]

Explanation: Step-by-step: Given the input [['BTS', 1], ['BTS', 1], ['BTS', 1], ['BTS', 1]], we first check if the group is not at the first position (i.e., its index is not 1). Since all groups are at the first position, we increment their indices by 1. The output is then [2, 3, 4, 5].

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.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free