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

 

sspiege3@schools.nyc.gov arrayshift > moveMisbehavingStudent
prev  |  next  |  chance

The order of "students" in a line is represented by an array of Strings. Position 0 represents the student at the beginning of the line. The student at "pos" is misbehaving, and needs to have its place in line switched with the student after it in line. If the misbehaving student is the last student in line, then that student should be removed from the line by setting the value at "pos" to be null. The "students" array will always have at least one value, and "pos" will be a valid position in "students".


moveMisbehavingStudent(["Bob", "Moe", "Curly"], 0) → ["Moe", "Bob", "Curly"]
moveMisbehavingStudent(["Bob", "Moe", "Curly"], 1) → ["Bob", "Curly", "Moe"]
moveMisbehavingStudent(["Bob", "Moe", "Curly"], 2) → ["Bob", "Moe", null]

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

public String[] moveMisbehavingStudent(String[] students, int pos) { }

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: 150 Post-solution available

Copyright Nick Parlante 2017 - privacy