N
Your solution should be linear in time, but you will probably need to define several functions to achieve that complexity.