Add solution for #5
Speed up #5 by 10x