Coding Interview Questions Set 3

For previous questions and answers please refer to Coding Interview Questions Set 1 and Coding Interview Set 2 . Let's begin with set 3, 7)How to reverse a singly linked list? a)Simple recursive solution: function reverseList(head) { if (!head || !head.next) { return head; } var newHead = reverseList(head.next); head.next.next = head; head.next = null; return newHead; } b)Iterative solution: function reverseList(head) { var prev = null; while (head) { var next = head.next; head.next = prev; prev = head; head = next; } return prev; } 8)Given a column title, return its corresponding column number. (Asked in Microsoft) Write a function that accepts a string s. Constraints: 1 <= s.length <= 7 s consists only of uppercase English letters. s is between "A" and "FXSHRXW". For example: A -> 1 B -> 2 C -> 3 .