U

28. Delete Element at Index Preserving Order

Easy

Problem Description

Given an array of NN integers, delete the element at 0-based index idxidx (0≤idx<N0 \le idx < N) while preserving the relative order of the remaining elements.

Input Format

  • •Line 1: An integer NN (1≤N≤1051 \le N \le 10^5).
  • •Line 2: NN space-separated integers A0,…,AN−1A_0, \dots, A_{N-1}.
  • •Line 3: An integer idxidx (0≤idx<N0 \le idx < N).

Output Format

Print the remaining N−1N-1 space-separated integers, or EMPTY if N=1N = 1.

Example 1:
Input:
5
10 20 30 40 50
2
Output:
10 20 40 50
Explanation: Deleting element 30 at index 2 shifts 40 and 50 left.
Example 2:
Input:
1
99
0
Output:
EMPTY
Explanation: Deleting the only element leaves the array empty.
Example 3:
Input:
3
1 2 3
0
Output:
2 3
Explanation: Deleting index 0 leaves 2 3.
Constraints:
  • Standard integer bounds: 32-bit signed integer or input range [1, 10^5].
  • Time complexity target: O(N) or O(N log N) where applicable.
  • Auxiliary space target: O(1) or minimal auxiliary memory.
Follow up:Can this algorithm be adapted to an online streaming setting where the entire input cannot be held in memory simultaneously?
1,180 Online