TopcoderArchive
Archive
Algorithm problem

TowerLifts

Problem statement, definition, constraints, and public examples.

Problem Statement

While building a tower, workers want to lift boxes up from the ground floor to the top floor using elevators. There are two types of boxes. Each box has a weight 50 or 100. Each elevator has enough space for up to two boxes, and can carry a maximum combined weight of 150. Each elevator can only be used once. Given a int[] boxWeights containing the weight of each box, return the minimum number of elevators necessary to transport all the boxes.

Definition

Class:
TowerLifts
Method:
leastNumber
Parameters:
int[]
Returns:
int
Method signature:
int leastNumber(int[] boxWeights)
(be sure your method is public)

Constraints

  • boxWeights will contain between 1 and 50 elements, inclusive.
  • Each element of boxWeights will be equal to 50 or 100.

Examples

  1. {50, 100, 50, 50, 50}
    Returns: 3
    There are two boxes in the first elevator: 50, 100. The second elevator contains: 50 and 50. The third elevator contains only one box: 50.
  2. {100, 100, 50, 100}
    Returns: 3
  3. {50, 50}
    Returns: 1
  4. {50, 50, 100, 100}
    Returns: 2
  5. {50, 50, 100, 100, 50, 100, 50, 50, 50}
    Returns: 5
Back to all problems