Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. Problem Statement
  2.  
  3. A rigorous teacher makes all his students stand in a line before entering the classroom. Being a rigorous teacher, he makes the students line up in non-descending order by height. One time, while the students were lining up, the teacher had to go to the bathroom. The students took the opportunity to play with the teacher's head and make a crazy line. They defined the craziness of a line as the sum of the absolute difference in height between each pair of consecutive students. Since a line ordered by height has minimum craziness, they of course decided to arrange themselves in a line with maximum craziness.
  4.  
  5. You are given a int[] heights, where each element is the height of a single student. Return the maximum possible craziness of a line made by those students.
  6.  
  7.  
  8. Definition
  9.  
  10. Class: CrazyLine
  11. Method: maxCrazyness
  12. Parameters: int[]
  13. Returns: int
  14. Method signature: int maxCrazyness(int[] heights)
  15. (be sure your method is public)
  16.  
  17.  
  18. Constraints
  19. - heights will contain between 1 and 50 elements, inclusive.
  20. - Each element of heights will be between 1 and 1000, inclusive.
  21.  
  22. Examples
  23. 0)
  24.  
  25. {5,10,25,40,25}
  26. Returns: 100
  27. If the line is arranged in this order: 25-10-40-5-25, the sum of the differences is 15+30+35+20=100.
  28. 1)
  29.  
  30. {2,3,5,7,11,13,17,19}
  31. Returns: 82
  32. The following order is optimal: 7-17-5-13-2-19-3-11.
  33. 2)
  34.  
  35. {1,1,1,1,1,1,501}
  36. Returns: 1000
  37. Make sure to place the tall guy in the middle.
  38. 3)
  39.  
  40. {1000,1000,1000,1000,1000,1000,1000,1000,1000}
  41. Returns: 0
  42. There is not much difference.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement