
Here is a short demo on generating grid dynamically, to fit into your screen.

So, instead of generating grid with GridLayoutGroup, I have used Combination of HorizontalLayoutGroup and VerticalLayoutGroup for generating Grid dynamically. So with GridLayoutGroup, each time you have to adjust cell size to fit the puzzle into the screen. You can also use GridLayoutGroup, but in case of generating grid with GridLayoutGroup, you may have to adjust its cell size each time, otherwise if you fix the cell size then generating larger grid may go beyond the screen. For more information on Horizontal Layout Group click, here and for Vertical Layout Group, click here.

For generating grids dynamically, here I have used combination of Horizontal Layout Group and Vertical Layout Group.
