Question
In java 1. prepend5() -- Given an array of ints, return a new array with the number 5 prepended at the start of the array.
In java
1. prepend5() -- Given an array of ints, return a new array with the number 5 prepended at the start of the array.
prepend5([1, 2, 3]) [5, 1, 2, 3] prepend5([10]) [5, 10] prepend5([20, 42, 1, 6, 5]) [5, 20, 42, 1, 6, 5]
2. deleteFirst() -- Given an array of ints, delete the first element. Return the new array. The new array should be shorter than the given array. You may assume the given array contains at least one element.
deleteFirst([1, 2, 3]) [2, 3] deleteFirst([5, 4, 3, 2, 1]) [4, 3, 2, 1] deleteFirst([10]) []
3. deleteAt() -- Given an array of ints and an index, delete the element at the index. Shift the remaining elements down to fill the gap. Return a new array that is shorter than the given one. You may assume the index is valid.
deleteAt([1, 2, 3], 0) [2, 3] deleteAt([4, 5, 6], 1) [4, 6] deleteAt([9, 8, 7, 6, 5, 4], 4) [9, 8, 7, 6, 4]
4.indexOf() -- Given an array of ints and a target value, return the index of the target. If the target does not appear in the array, return -1. If the target appears multiple times, return the lowest index. indexOf([1, 2, 3], 3) 2 indexOf([45, 10, 7, 10], 10) 1 indexOf([7, 6, 4, 5], 20) -1 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started