Saturday, March 2, 2013

Merge Intervals


Merge IntervalsMar 27 '12
Given a collection of intervals, merge all overlapping intervals.
For example,
Given [1,3],[2,6],[8,10],[15,18],
return [1,6],[8,10],[15,18].

Friday, March 1, 2013

Anagrams



AnagramsMar 19 '12
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.

Remove Duplicates from Sorted List II



Remove Duplicates from Sorted List IIApr 22 '12
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.


Wednesday, February 27, 2013

Length of Last Word


Length of Last WordMar 27 '12
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
For example, 
Given s = "Hello World",
return 5.


Tuesday, February 26, 2013

Valid Palindrome



Valid PalindromeJan 13
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.

Remove Duplicates from Sorted Array



Remove Duplicates from Sorted ArrayFeb 16 '12
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array A = [1,1,2],
Your function should return length = 2, and A is now [1,2].

Monday, February 25, 2013

Swap Nodes in Pairs



Swap Nodes in PairsFeb 15 '12
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.