Algorithm design for problems on hackrank.com