Implemented O(n) solution for viking_ans3 question