Ad

You start with a bag of blocks. Each block has a number on it. Build the tallest tower possible from the blocks. The criteria for the tower are:

Each level for the tower must satify one of the following conditions:

  1. it must have more blocks than the previous level
    or
  2. the sum of the numbers on the blocks must have a lower value than the sum of the previous level.

You can only use the blocks provided in the bag. It's okay if not every block can be used in the tower, simply give the tallest tower possible.

The input is represented as a one dimensional array of integers.
The output should be a two dimensional array of integers, starting at the top of the tower, going down.

Example 1:

Input:

[1, 2, 3]

Output:

[
  [1],
  [2],
  [3],
]

Example 2:

Input:

[1, 1, 1]

Output:

[
  [1],
  [1, 1],
]

Example 3:

Input:

[1, 1]

Output:

[
  [1],
]

There can be many possible solutions per bag of blocks. The only important part is that the tower is valid and the tallest possible with the bag given.

using System;

namespace Solution
{
  public class BlockBuilder
  {
    public static int[,] BuildATower(int[] bag)
    {
      return new int[,] { { 1 } }; // Code goes here ...
    }
  }
}