I found this site that has some really neat challenges.
http://www.devx.com/DevX/Door/17707
I'm stuck on the circle dance problem.(It says it's easy, but...)
I got a solution but it does't work for all the tests:
Anyone up to the challenge?Code:import java.util.*; class CircleDance { public int arrangeDancers(int[] heights) { int[] lowestSoFar = heights; Collections.reverse(Arrays.asList(heights)); if (heights.length == 3) { return heights[heights.length-1] - heights[0]; } int maxDifference = heights[heights.length-1]-heights[0]; int temp; int temp2; for (int back=heights.length-1; back>=0; back--) { for(int front=0; front<heights.length; front++) { if (front == heights.length-1) { if (heights[front] > heights[0]) { temp = heights[front]; temp2 = heights[0]; heights[front] = temp2; heights[0] = temp; } } else if (front < heights.length-1) { if (heights[front] > heights[front+1]) { temp = heights[front]; temp2 = heights[front+1]; heights[front] = temp2; heights[front+1] = temp; for (int i=0; i<heights.length; i++) { if (i == heights.length-1) { if ((heights[i]+heights[0]) < maxDifference) { maxDifference = heights[i] + heights[0]; } } else if (i < heights.length-1) { if ((heights[i] + heights[i+1]) < maxDifference) { maxDifference = heights[i] + heights[i+1]; } } } if ((heights[0] + heights[heights.length-1]) < maxDifference) { maxDifference = heights[0] + heights[heights.length-1]; } } } } } return maxDifference; } public static void main(String[] args) { int[] d = {170,180,190}; CircleDance cd = new CircleDance(); System.out.println(cd.arrangeDancers(d)); } }




Reply With Quote