Clutter Interview Question

Two coding question. The first one is super easy, the second one need to use hashmap to solve it.