simplified the algorithm by just considering the problem recursively and mathemathically