calculateOptimalLayout

Calculate the optimal grid layout based on content.