@@ -0,0 +1,1200 @@
+// https://community.topcoder.com/stat?c=problem_statement&pm=11336%0A%0Apublic class GogoXBallsAndBinsEasy %7B%0A%09public static int solve(int%5B%5D T) %7B%0A%09%09int movesCount = 0;%0A%09%09%0A%09%09// The trick here - how many balls would you move to sort the array in descending order?%0A%09%09%0A%09%09/*%0A%09%09 * %09For example:%0A%09%09 * %09  T%5B%5D = %7B 1, 2, 3, 4, 5, 6, 7, 8 %7D%0A%09%09 * %0A%09%09 * %09When sorted in descending order, it would look like this:%0A%09%09 * %09  T_sorted%5B%5D = %7B 8, 7, 6, 5, 4, 3, 2, 1 %7D%0A%09%09 * %0A%09%09 * %09T%5B%5D is sorted in ascending order, so to switch to descending order, simply switch first element with last element%0A%09%09 * %09%091 with 8, %0A%09%09 * %09%092 with 7 etc.%0A%09%09 * %0A%09%09 *  When doing this, simply count how many balls have actually been moved (that is - the difference between the larger element and the smaller one)%0A%09%09 *  For example: when switching 1 with 8, you need the difference between 8 and 1, which is 7 %0A%09%09 *  (since you added 7 balls to the first bin and removed 7 from the last one)%0A%09%09 *  %0A%09%09 *  Store these differences in a variable.%0A%09%09 *  This is your end result.%0A%09%09 * %0A%09%09 */%0A%09%09%0A%09%09int lastBallIndex = T.length - 1;%0A%09%09for (int i = 0; i %3C (T.length / 2); ++i) %7B%0A%09%09%09movesCount += T%5BlastBallIndex-i%5D - T%5Bi%5D;%0A %09%09%7D%0A%09%09%0A%09%09return movesCount;%0A%09%7D%0A%7D%0A

Create GogoXBallsAndBinsEasy.java