fn to find maximum depth finding