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

 

orion.a.smith@gmail.com apcsa-arrays > apcsaArraysSwapLeastTwoToFront
prev  |  next  |  chance

This function returns the input array (or a copy of the input array) where the first element has been swapped with the least element, and the second element has been swapped with the second-least element. If the first and second elements are the least and second-least elements, the array is returned unchanged.

HINT
The most common algorithm here will come to you after you reflect on the following: what does the array look like after you find and swap the first and least elements? In other words, once the element at index 0 is guaranteed to be the least element, which elements of the array do you really need to think about when finding the second-least element?

apcsaArraysSwapLeastTwoToFront([0, 1, 2, 3]) → [0, 1, 2, 3]
apcsaArraysSwapLeastTwoToFront([-1, -3, -5]) → [-5, -3, -1]
apcsaArraysSwapLeastTwoToFront([0, -1]) → [-1, 0]

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

public int[] apcsaArraysSwapLeastTwoToFront(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: 240

Copyright Nick Parlante 2017 - privacy