Algorithm Question: Stacking bricks of different colours? I have a bunch of coloured bricks. There are X different colours, and a random number of each colour. How do I stack them up into Y columns so that a) no row has two bricks of the same colour and b) the height of the largest column is minimised?

There is an obvious lower bound of highest number of bricks of a single colour but beyond that I don't know where to go. This is equivalent to an optimisation problem I'm trying to solve and I'd be grateful if someone recognised the problem!
Let $n$ be the number of bricks and $c_i$ be the number of bricks of color $i$.
First notice that in a $w \times h$ grid we can fit at most $wh$ bricks.
Therefore, $\lceil \frac{n}{Y} \rceil$ is a lower bound on your height. The
minimum height $h$ to stack all your bricks without violating the constraint will be
$\max(\max_i(c_i), \lceil \frac{n}{Y} \rceil)$. 

The idea is to go from left to right (column 1 to X) and keep pushing a brick of the same color on to the left most non-full stack. And by non-full I mean that the size of the stack is lower than our defined height $h$. No two colors will be in the same row and it is also obviously true, that we have enough room for all $n$ bricks. 

A pseudo code is also provided:

color_count[i] = number of bricks of color i
height = max(max(color_count), ceil(n / Y))

current_column = 1
current_row = 1
current_color = 1
while current_color &lt;= X
  while color_count[current_color] &gt; 0
    put a brick at (current_row, current_column) with current_color
    color_count[current_color] -= 1
    if current_row == height
      current_column += 1
      current_row = 1
    else
      current_row += 1
  current_color += 1