Change to 2d Array

optimization using 2d array