clean code of prefixSum method for the sumBetweenTress function