Tap here to switch tabs
Problem
Submissions

Problem: Elements in Array After Removing and Replacing Elements

med
30 min
Try to solve the Elements in Array After Removing and Replacing Elements problem.

Statement

You are given a 00 indexed integer array nums that undergoes a continuous transformation process.

Initially, at minute 00, the array is nums.

  • During the first nums.length minutes, the leftmost element is removed from the array at each minute until the array becomes empty.

  • During the subsequent nums.length minutes, elements from the original nums are appended back to the array one by one in their original order until the array is fully restored.

  • This cycle repeats indefinitely, alternating between removing all elements from left to right and appending all original elements from left to right.

You are also given a 2extD2 ext{D} integer array queries, where queries[j] = [time_j, index_j]. For the jextthj^{ ext{th}} query, determine the element located at index index_j of the array at minute time_j. If the index is out of bounds or the array does not contain an element at index_j at that minute, the answer is −1-1.

Return an array of integers representing the answers to all queries in the given order.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 0≤0 \leq nums[i] ≤100\leq 100

  • n ==== queries.length

  • 1≤1 \leq n ≤105\leq 10^5

  • queries[j].length ==2== 2

  • 0≤0 \leq time_j ≤105\leq 10^5

  • 0≤0 \leq index_j << nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Elements in Array After Removing and Replacing Elements

med
30 min
Try to solve the Elements in Array After Removing and Replacing Elements problem.

Statement

You are given a 00 indexed integer array nums that undergoes a continuous transformation process.

Initially, at minute 00, the array is nums.

  • During the first nums.length minutes, the leftmost element is removed from the array at each minute until the array becomes empty.

  • During the subsequent nums.length minutes, elements from the original nums are appended back to the array one by one in their original order until the array is fully restored.

  • This cycle repeats indefinitely, alternating between removing all elements from left to right and appending all original elements from left to right.

You are also given a 2extD2 ext{D} integer array queries, where queries[j] = [time_j, index_j]. For the jextthj^{ ext{th}} query, determine the element located at index index_j of the array at minute time_j. If the index is out of bounds or the array does not contain an element at index_j at that minute, the answer is −1-1.

Return an array of integers representing the answers to all queries in the given order.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 0≤0 \leq nums[i] ≤100\leq 100

  • n ==== queries.length

  • 1≤1 \leq n ≤105\leq 10^5

  • queries[j].length ==2== 2

  • 0≤0 \leq time_j ≤105\leq 10^5

  • 0≤0 \leq index_j << nums.length