Solution to sample-grid assignment