Practice algorithm for leetcode