faster solution to question 1 using btrees
working, fast solutions