Loading...
Loading...
Loading...
A late admission must be placed in the attendance list at position p (positions start at 1). Everyone from position p onward moves one place back. Create the new list of size n + 1 and print it.
Example 1
Input
5 10 20 30 40 50 3 25
Output
10 20 25 30 40 50
25 becomes the 3rd entry; 30, 40 and 50 move back.
Example 2
Input
3 7 8 9 4 100
Output
7 8 9 100
p = n + 1 adds the value at the end.
Try the problem first. Open one hint at a time.
Make a new array of size n + 1. The index for position p is p - 1.
Copy indexes 0 to p - 2 as they are, put v at p - 1, then copy the rest one place later.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor