id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

abraskin@mbusd.org > add
prev  |  next  |  chance

Given an array of integers, an index, and a new element return a new array with the element inserted at the index.
If the index is less than zero or greater than the length of the array then return the array unchanged.


add([0, 1, 2, 3, 4, 5], 0, -1) → [-1, 0, 1, 2, 3, 4, 5]
add([0, 1, 2, 3, 4, 5], 6, 6) → [0, 1, 2, 3, 4, 5, 6]
add([0, 1, 2, 3, 4, 5], 7, 99) → [0, 1, 2, 3, 4, 5]

...Save, Compile, Run (ctrl-enter)

public int[] add(int[] arr, int index, int e) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200

Copyright Nick Parlante 2017 - privacy