| about | help | code help+videos | done | prefs |
tripleSort123
Given an array of length 3, return a new array with the elements sorted in order from least to greatest; however, if the three values are all the same, then the new array should instead contain {first, 2 * second, 3 * third}.
Hint:
Math.min(int a, int b) returns the smaller of two int values.
Math.max(int a, int b) returns the larger of two int values.
Quick Array Syntax Review
int[] arr1 = new int[4]; // makes a new array of length 4
int[] arr2 = new int[]{4, 5}; // makes a new length 2 array containing {4, 5}
arr1[2] = 5; // the element at index 2 of arr1 is now 5
arr1[1] = arr1.length; // the element at index 1 of arr1 is now 4 (the length of arr1)
tripleSort123([3, 5, 4]) → [3, 4, 5] tripleSort123([17, 15, 15]) → [15, 15, 17] tripleSort123([7, 7, 7]) → [7, 14, 21] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy