opimized prob4 to use deque. useful for later larger problems.