|
U
Pro28. Delete Element at Index Preserving Order
Easy
Problem Description
Given an array of N integers, delete the element at 0-based index idx (0≤idx<N) while preserving the relative order of the remaining elements.
Input Format
- •Line 1: An integer N (1≤N≤105).
- •Line 2: N space-separated integers A0,…,AN−1.
- •Line 3: An integer idx (0≤idx<N).
Output Format
Print the remaining N−1 space-separated integers, or EMPTY if N=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
Code
|Loading Code Editor...
SavedLn 1, Col 1
param_1 =
param_2 =
param_3 =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit