major function -  recursively find the next layer
sol of q077