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

 

fix45


Return an array that contains exactly the same numbers as the given array, but rearranged so that every 4 is immediately followed by a 5. Do not move the 4s, but every other number may move. The array will contain the same number of 4s and 5s, and every 4 will have a number after it that is not another 4. For example, if the input is {5, 4, 9, 4, 9, 5}, the output should be {9, 4, 5, 4, 5, 9}. The 4s stay in place, and the 5s are placed immediately after each 4. The rest of the numbers may move around.


fix45([5, 4, 9, 4, 9, 5]) → [9, 4, 5, 4, 5, 9]
fix45([1, 4, 1, 5]) → [1, 4, 5, 1]
fix45([1, 4, 1, 5, 5, 4, 1]) → [1, 4, 5, 1, 1, 4, 5]

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

public int[] fix45(int[] nums) { }

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: 325

Copyright Nick Parlante 2017 - privacy