first solution

this is my first attempt to solve this problem, I will invest more time
about data structures, I think I could do it better