Thursday, June 18, 2015

Minimum Window Substring | Leetcode

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).

For example,
S = "ADOBECODEBANC"
T = "ABC"

Minimum window is "BANC".

Note:

If there is no such window in S that covers all characters in T, return the emtpy string "".
If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.

---

Solution: Maintain a bag (multiset) of the characters in T. Iterate S from beginning to end. Keep a sliding window that goes from "windowStart" to the current index in S. Keep a counter for the number of remaining characters in T that we have not included in our sliding window yet. When the counter drops to zero, that means we have found a sliding window within S that contains all the characters in T.

There are some tricky things in this algorithm. First, the count of each element in the bag may become negative. For example, for a sliding window "ABBB", and T="AB", the count of B in the bag would be -2 and not 0! This means that you cannot use a real Bag data structure but you have to use a hashmap of integer to integer mapping.

Second, when we get a matching sliding window, try to collect the result immediately. But continue to shrink the sliding window from the left to the minimum length possible by advancing the windowStart pointer from the left. When you shrink the window until it no longer contains all the characters in T (remaining > 0), then stop shrinking the sliding window and continue iteration on S.
public class Solution {
    public String minWindow(String s, String t) {
        Map bag = new HashMap<>();
        for (int i = t.length() - 1; i >= 0; i--) {
            int ch = t.charAt(i);
            bag.put(ch, bag.containsKey(ch) ? bag.get(ch) + 1 : 1);
        }
        
        // Keep track of the minimum window found so far.        
        int minLength = 0;
        int minStart = 0;
        int minEnd = 0;
        int windowStart = 0;
        int remaining = t.length();

        for (int i = 0; i < s.length(); i++) {
            int ch = s.charAt(i);

            // Subtract ch from bag. Count could go negative!
            if (bag.containsKey(ch)) {
                if (bag.get(ch) > 0) remaining--;
                bag.put(ch, bag.get(ch) - 1);
            }
            
            while (remaining == 0 && windowStart <= i) {
                // Collect result if minimum.
                int len = i - windowStart + 1;
                if (minLength == 0 || len < minLength) {
                    minStart = windowStart;
                    minEnd = i;
                    minLength = len;
                }

                // Add back character if needed.
                ch = s.charAt(windowStart);
                if (bag.containsKey(ch)) {
                    if (bag.get(ch) >= 0) remaining++;
                    bag.put(ch, bag.get(ch) + 1);
                }

                // Advance windowStart pointer.
                windowStart++;
            }
        }
        
        return (minLength == 0) ? "" : s.substring(minStart, minEnd + 1);
    }
}

Wednesday, June 17, 2015

Sort Colors | Leetcode

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
 
Note:
You are not suppose to use the library's sort function for this problem.


Follow up:

A rather straight forward solution is a two-pass algorithm using counting sort.
First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.

Could you come up with an one-pass algorithm using only constant space?

---

Solution: Keep the index of the last red (0) and the first blue (2). Start by iterating from the end of the array and filter out the blues. Then start iterating from the first element to the element before the index of the first blue we found so far. When we see a red, swap it with the first non-red element and increment the red pointer. When we see a blue, swap it with the last non-blue element and decrement the blue pointer. All the whites (1), if any, will remain in the middle of the array.
public class Solution {
    public void sortColors(int[] nums) {
        int blue = nums.length - 1;
        while (blue >= 0 && nums[blue] == 2) blue--;
        for (int i = 0, red = 0; i <= blue; i++) {
            if (nums[i] == 0) {
                if (i != red) {
                    int tmp = nums[red];
                    nums[red] = 0;
                    nums[i] = tmp;
                }
                red++;
            } else if (nums[i] == 2) {
                int tmp = nums[blue];
                nums[blue--] = 2;
                nums[i--] = tmp;
            }
        }
    }
}

Search a 2D Matrix | Leetcode

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
  • Integers in each row are sorted from left to right.
  • The first integer of each row is greater than the last integer of the previous row.
For example,
Consider the following matrix:
[
  [1,   3,  5,  7],
  [10, 11, 16, 20],
  [23, 30, 34, 50]
]
Given target = 3, return true.

---

Solution: Pretend that the 2D matrix is one linear array. Given an index i in the linear array, you can calculate the position of the corresponding element in the matrix. The row and column is given by: row = (i / cols), column = (i % cols). Perform an ordinary binary search to get the answer.
public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int rows = matrix.length;
        int cols = matrix[0].length;
        int lo = 0;
        int hi = (rows * cols) - 1;
        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            int m = matrix[mid / cols][mid % cols];
            if (m == target) {
                return true;
            }
            if (m < target) {
                lo = mid + 1;
            } else {
                hi = mid - 1;
            }
        }
        return false;
    }
}

Tuesday, June 16, 2015

Set Matrix Zeroes | Leetcode

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

 
Follow up: Did you use extra space?
A straight forward solution using O(mn) space is probably a bad idea.
A simple improvement uses O(m + n) space, but still not the best solution.
Could you devise a constant space solution?

---

Solution: Use two booleans, one for first row, one for first column. Check if first row and first column is zero. Then check all other rows and columns to see if that row and column is zero. Mark all rows other than the first row. Mark all columns other than the first column. Mark the first row and first column as needed.

Algorithm 1: Use for loops
public class Solution {
    public void setZeroes(int[][] matrix) {
        int numRows = matrix.length;
        int numCols = matrix[0].length;
        boolean isFirstRowZero = false;
        boolean isFirstColZero = false;
        
        // Check if first row is zero.
        for (int col = 0; col < numCols; col++) {
            if (matrix[0][col] == 0) {
                isFirstRowZero = true;
                break;
            }
        }
        
        // Check if first column is zero.
        for (int row = 0; row < numRows; row++) {
            if (matrix[row][0] == 0) {
                isFirstColZero = true;
                break;
            }
        }
        
        // Check if each row/column is zero by marking zero in first column/row.
        for (int row = 1; row < numRows; row++) {
            for (int col = 1; col < numCols; col++) {
                if (matrix[row][col] == 0) {
                    matrix[row][0] = 0;
                    matrix[0][col] = 0;
                }
            }
        }
        
        // Mark all rows except first.
        for (int row = 1; row < numRows; row++) {
            if (matrix[row][0] == 0) {
                for (int col = 1; col < numCols; col++) {
                    matrix[row][col] = 0;
                }
            }
        }
        
        // Mark all columns except first.
        for (int col = 1; col < numCols; col++) {
            if (matrix[0][col] == 0) {
                for (int row = 1; row < numRows; row++) {
                    matrix[row][col] = 0;
                }
            }
        }

        // Mark first row.
        if (isFirstRowZero) {
            for (int col = 0; col < numCols; col++) {
                matrix[0][col] = 0;
            }
        }
        
        // Mark first column.
        if (isFirstColZero) {
            for (int row = 0; row < numRows; row++) {
                matrix[row][0] = 0;
            }
        }
    }
}

Algorithm 2: Use Java 8 streams
public class Solution {
    private int[][] matrix;
        
    public void setZeroes(int[][] matrix) {
        this.matrix = matrix;
        
        boolean isFirstRowZero = rowHasZero(0);
        boolean isFirstColZero = colHasZero(0);
        
        rows(1).filter(row -> rowHasZero(row)).forEach(row -> matrix[row][0] = 0);
        cols(1).filter(col -> colHasZero(col)).forEach(col -> matrix[0][col] = 0);
        
        rows(1).filter(row -> matrix[row][0] == 0).forEach(row -> setRowToZeros(row));
        cols(1).filter(col -> matrix[0][col] == 0).forEach(col -> setColToZeros(col));

        if (isFirstRowZero) setRowToZeros(0);
        if (isFirstColZero) setColToZeros(0);
    }
    
    private IntStream rows(int start) {
        return IntStream.range(start, matrix.length);
    }
    
    private IntStream cols(int start) {
        return IntStream.range(start, matrix[0].length);
    }
    
    private boolean rowHasZero(int row) {
        return cols(0).anyMatch(col -> matrix[row][col] == 0);
    }

    private boolean colHasZero(int col) {
        return rows(0).anyMatch(row -> matrix[row][col] == 0);
    }

    private void setRowToZeros(int row) {
        cols(0).forEach(col -> matrix[row][col] = 0);
    }
    
    private void setColToZeros(int col) {
        rows(0).forEach(row -> matrix[row][col] = 0);
    }
}

Monday, June 15, 2015

Edit Distance | Leetcode

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)
You have the following 3 operations permitted on a word:
a) Insert a character
b) Delete a character
c) Replace a character

---

Solution: The only thing that works is dynamic programming on a 2D matrix. Great details available on wikipedia: https://en.wikipedia.org/wiki/Levenshtein_distance

Defining the edit distance function f(y,x):
For 1 <= y <= len(word1) and 1 <= x <= len(word2):
   f(y, x) = minimum {
                         f(y-1, x) + 1,
                         f(y, x-1) + 1,
                         f(y-1, x-1) + (word1[y] == word2[x] ? 0 : 1)
                     }
OR
   f(y, x) = minimum of:
                         DELETE_COST
                         INSERT_COST
                         (word1[y] == word2[x] ? NO_OP_COST : REPLACE_COST)

There are two different ways to implement the same algorithm:
1. Use a len1 x len2 matrix.
2. Use two arrays of the same length, either len1 or len2, depending on the direction of iteration.

The first algorithm is more straightforward to implement. The second algorithm is a space optimization of the first algorithm, and thus is a little more complex than the first algorithm. But the idea is identical in both cases. You probably should use the first algorithm in normal interview cases, but be prepared to also use the second algorithm if you do too well and the interviewer wants you to optimize for space. :-)

Algorithm 1: O(N^2) space
public class Solution {
    public int minDistance(String word1, String word2) {
        int len1 = word1.length();
        int len2 = word2.length();
        if (len1 == 0) return len2;
        if (len2 == 0) return len1;
        
        // For all y and x, m[y,x] will hold the edit distance between
        // the first y characters of word1 and the first x characters of word2.
        // Note that m has (len1 + 1) * (len2 + 1) values.
        int[][] m = new int[len1 + 1][];
        for (int y = 0; y <= len1; y++) {
            m[y] = new int[len2 + 1];
        }
        
        // Cost of dropping all characters from word1.
        // Note: we must include m[len1][0] also.
        for (int y = 1; y <= len1; y++) {
            m[y][0] = y;
        }
        
        // Cost of inserting all characters from word2.
        // Note: we must include m[0][len2] also.
        for (int x = 1; x <= len2; x++) {
            m[0][x] = x;
        }
        
        for (int y = 1; y <= len1; y++) {
            int char1 = word1.charAt(y - 1);

            for (int x = 1; x <= len2; x++) {
                int char2 = word2.charAt(x - 1);

                int leftCostPlusInsert = m[y][x - 1] + 1;
                int topCostPlusDelete = m[y - 1][x] + 1;
                int minCost = Math.min(leftCostPlusInsert, topCostPlusDelete);
                int replacementCostIfAny = (char1 == char2) ? 0 : 1;

                m[y][x] = Math.min(minCost, m[y - 1][x - 1] + replacementCostIfAny);
            }
        }
        
        return m[len1][len2];
    }
}

Algorithm 2: O(N) space
public class Solution {
    public int minDistance(String word1, String word2) {
        int len1 = word1.length();
        int len2 = word2.length();
        if (len1 == 0) return len2;
        if (len2 == 0) return len1;
        
        int[] a1 = new int[len2 + 1];
        int[] a2 = new int[len2 + 1];
        
        for (int x = 1; x <= len2; x++) {
            a1[x] = x;
        }

        for (int y = 1; y <= len1; y++) {
            a2[0] = y;
            int char1 = word1.charAt(y - 1);

            for (int x = 1; x <= len2; x++) {
                int char2 = word2.charAt(x - 1);

                int leftCostPlusInsert = a2[x - 1] + 1;
                int topCostPlusDelete = a1[x] + 1;
                int minCost = Math.min(leftCostPlusInsert, topCostPlusDelete);
                int replacementCostIfAny = (char1 == char2) ? 0 : 1;

                a2[x] = Math.min(minCost, a1[x - 1] + replacementCostIfAny);
            }
            
            // Swap a1 and a2.
            int[] tmp = a1;
            a1 = a2;
            a2 = tmp;
        }
        
        return a1[len2];
    }
}

Sunday, June 14, 2015

Two Sum | Leetcode

Given an array of integers, find two numbers such that they add up to a specific target number.

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.

You may assume that each input would have exactly one solution.

Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2

---

Solution: Store index of each sub-target number in the array into a hashmap. The sub-target number is equal to target - nums[i]. When we see a number that is equal to the sub-target number later, then return the answer. Note that the index is 1-based for this question.
public class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map subTargetToIndex = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int n = nums[i];
            if (subTargetToIndex.containsKey(n)) {
                return new int[] { subTargetToIndex.get(n), i + 1 };
            }
            subTargetToIndex.put(target - n, i + 1);
        }
        return null;
    }
}

Home

List of Leetcode's problems and solutions:

#TitleAcceptanceDifficultyStatus
256 Paint House38.8%Medium
255 Verify Preorder Sequence in Binary Search Tree27.5%Medium
254 Factor Combinations29.5%Medium
253 Meeting Rooms II26.4%Medium
252 Meeting Rooms34.0%Easy
251 Flatten 2D Vector25.6%Medium
250 Count Univalue Subtrees33.6%Medium
249 Group Shifted Strings23.0%Easy
248 Strobogrammatic Number III21.1%Hard
247 Strobogrammatic Number II22.4%Medium
246 Strobogrammatic Number31.1%Easy
245 Shortest Word Distance III41.2%Medium
244 Shortest Word Distance II33.2%Medium
243 Shortest Word Distance39.1%Easy
242 Valid Anagram34.0%Easy
241 Different Ways to Add Parentheses26.0%Medium
240 Search a 2D Matrix II28.1%Medium
239 Sliding Window Maximum22.2%Hard
238 Product of Array Except Self34.6%Medium
237 Delete Node in a Linked List44.7%Easy
236 Lowest Common Ancestor of a Binary Tree26.6%Medium
235 Lowest Common Ancestor of a Binary Search Tree37.4%Easy
234 Palindrome Linked List21.7%Easy
233 Number of Digit One19.9%Medium
232 Implement Queue using Stacks33.8%Easy
231 Power of Two29.8%Easy
230 Kth Smallest Element in a BST29.7%Medium
229 Majority Element II22.1%Medium
228 Summary Ranges18.6%Easy
227 Basic Calculator II18.6%Medium
226 Invert Binary Tree37.1%Easy
225 Implement Stack using Queues30.4%Easy
224 Basic Calculator16.6%Medium
223 Rectangle Area25.7%Easy
222 Count Complete Tree Nodes20.5%Medium
221 Maximal Square19.7%Medium
220 Contains Duplicate III15.5%Medium
219 Contains Duplicate II25.6%Easy
218 The Skyline Problem16.5%Hard
217 Contains Duplicate36.0%Easy
216 Combination Sum III28.7%Medium
215 Kth Largest Element in an Array27.3%Medium
214 Shortest Palindrome16.1%Hard
213 House Robber II26.6%Medium
212 Word Search II14.8%Hard
211 Add and Search Word - Data structure design20.3%Medium
210 Course Schedule II19.5%Medium
209 Minimum Size Subarray Sum23.2%Medium
208 Implement Trie (Prefix Tree)24.8%Medium
207 Course Schedule22.1%Medium
206 Reverse Linked List32.3%Easy
205 Isomorphic Strings24.6%Easy
204 Count Primes19.8%Easy
203 Remove Linked List Elements25.5%Easy
202 Happy Number31.8%Easy
201 Bitwise AND of Numbers Range25.1%Medium
200 Number of Islands22.6%Medium
199 Binary Tree Right Side View27.8%Medium
198 House Robber29.3%Easy
191 Number of 1 Bits37.9%Easy
190 Reverse Bits28.7%Easy
189 Rotate Array18.1%Easy
188 Best Time to Buy and Sell Stock IV18.4%Hard
187 Repeated DNA Sequences20.3%Medium
186 Reverse Words in a String II31.6%Medium
179 Largest Number16.1%Medium
174 Dungeon Game18.1%Hard
173 Binary Search Tree Iterator29.6%Medium
172 Factorial Trailing Zeroes29.1%Easy
171 Excel Sheet Column Number36.6%Easy
170 Two Sum III - Data structure design25.0%Easy
169 Majority Element35.5%Easy
168 Excel Sheet Column Title18.3%Easy
167 Two Sum II - Input array is sorted43.3%Medium
166 Fraction to Recurring Decimal13.0%Medium
165 Compare Version Numbers15.3%Easy
164 Maximum Gap24.5%Hard
163 Missing Ranges24.3%Medium
162 Find Peak Element31.9%Medium
161 One Edit Distance24.5%Medium
160 Intersection of Two Linked Lists28.9%Easy
159 Longest Substring with At Most Two Distinct Characters30.6%Hard
158 Read N Characters Given Read4 II - Call multiple times22.6%Hard
157 Read N Characters Given Read429.8%Easy
156 Binary Tree Upside Down34.2%Medium
155 Min Stack19.3%Easy
154 Find Minimum in Rotated Sorted Array II32.2%Hard
153 Find Minimum in Rotated Sorted Array33.5%Medium
152 Maximum Product Subarray19.6%Medium
151 Reverse Words in a String15.2%Medium
150 Evaluate Reverse Polish Notation21.4%Medium
149 Max Points on a Line12.8%Hard
148 Sort List22.3%Medium
147 Insertion Sort List26.7%Medium
146 LRU Cache15.1%Hard
145 Binary Tree Postorder Traversal32.6%Hard
144 Binary Tree Preorder Traversal36.3%Medium
143 Reorder List21.0%Medium
142 Linked List Cycle II31.4%Medium
141 Linked List Cycle36.4%Medium
140 Word Break II17.8%Hard
139 Word Break23.1%Medium
138 Copy List with Random Pointer25.4%Hard
137 Single Number II35.1%Medium
136 Single Number45.1%Medium
135 Candy20.7%Hard
134 Gas Station25.8%Medium
133 Clone Graph24.2%Medium
132 Palindrome Partitioning II19.9%Hard
131 Palindrome Partitioning27.0%Medium
130 Surrounded Regions14.8%Medium
129 Sum Root to Leaf Numbers30.3%Medium
128 Longest Consecutive Sequence29.6%Hard
127 Word Ladder19.4%Medium
126 Word Ladder II13.2%Hard
125 Valid Palindrome22.0%Easy
124 Binary Tree Maximum Path Sum21.6%Hard
123 Best Time to Buy and Sell Stock III24.0%Hard
122 Best Time to Buy and Sell Stock II38.5%Medium
121 Best Time to Buy and Sell Stock32.8%Medium
120 Triangle27.4%Medium
119 Pascal's Triangle II29.4%Easy
118 Pascal's Triangle30.1%Easy
117 Populating Next Right Pointers in Each Node II32.1%Hard
116 Populating Next Right Pointers in Each Node36.3%Medium
115 Distinct Subsequences26.6%Hard
114 Flatten Binary Tree to Linked List28.8%Medium
113 Path Sum II26.6%Medium
112 Path Sum29.6%Easy
111 Minimum Depth of Binary Tree28.9%Easy
110 Balanced Binary Tree31.9%Easy
109 Convert Sorted List to Binary Search Tree28.0%Medium
108 Convert Sorted Array to Binary Search Tree34.0%Medium
107 Binary Tree Level Order Traversal II31.0%Easy
106 Construct Binary Tree from Inorder and Postorder Traversal26.9%Medium
105 Construct Binary Tree from Preorder and Inorder Traversal26.4%Medium
104 Maximum Depth of Binary Tree45.1%Easy
103 Binary Tree Zigzag Level Order Traversal26.4%Medium
102 Binary Tree Level Order Traversal29.2%Easy
101 Symmetric Tree31.6%Easy
100 Same Tree41.4%Easy
99 Recover Binary Search Tree24.4%Hard
98 Validate Binary Search Tree20.3%Medium
97 Interleaving String20.8%Hard
96 Unique Binary Search Trees35.6%Medium
95 Unique Binary Search Trees II28.1%Medium
94 Binary Tree Inorder Traversal36.3%Medium
93 Restore IP Addresses21.1%Medium
92 Reverse Linked List II25.9%Medium
91 Decode Ways16.3%Medium
90 Subsets II27.8%Medium
89 Gray Code32.9%Medium
88 Merge Sorted Array29.1%Easy
87 Scramble String24.5%Hard
86 Partition List27.4%Medium
85 Maximal Rectangle22.1%Hard
84 Largest Rectangle in Histogram22.6%Hard
83 Remove Duplicates from Sorted List34.4%Easy
82 Remove Duplicates from Sorted List II25.0%Medium
81 Search in Rotated Sorted Array II31.2%Medium
80 Remove Duplicates from Sorted Array II30.4%Medium
79 Word Search20.5%Medium
78 Subsets28.2%Medium
77 Combinations31.0%Medium
76 Minimum Window Substring19.0%Hard
75 Sort Colors32.6%Medium
74 Search a 2D Matrix31.6%Medium
73 Set Matrix Zeroes31.5%Medium
72 Edit Distance26.4%Hard
71 Simplify Path20.1%Medium
70 Climbing Stairs34.4%Easy
69 Sqrt(x)23.2%Medium
68 Text Justification14.7%Hard
67 Add Binary24.6%Easy
66 Plus One30.3%Easy
65 Valid Number11.5%Hard
64 Minimum Path Sum32.3%Medium
63 Unique Paths II27.9%Medium
62 Unique Paths33.0%Medium
61 Rotate List21.6%Medium
60 Permutation Sequence22.8%Medium
59 Spiral Matrix II31.8%Medium
58 Length of Last Word27.6%Easy
57 Insert Interval21.6%Hard
56 Merge Intervals22.5%Hard
55 Jump Game26.9%Medium
54 Spiral Matrix20.8%Medium
53 Maximum Subarray34.4%Medium
52 N-Queens II36.1%Hard
51 N-Queens26.4%Hard
50 Pow(x, n)26.7%Medium
49 Group Anagrams24.3%Medium
48 Rotate Image32.0%Medium
47 Permutations II25.8%Hard
46 Permutations31.9%Medium
45 Jump Game II24.1%Hard
44 Wildcard Matching15.3%Hard
43 Multiply Strings21.1%Medium
42 Trapping Rain Water30.1%Hard
41 First Missing Positive22.8%Hard
40 Combination Sum II25.2%Medium
39 Combination Sum28.0%Medium
38 Count and Say25.3%Easy
37 Sudoku Solver22.1%Hard
36 Valid Sudoku27.2%Easy
35 Search Insert Position35.4%Medium
34 Search for a Range27.4%Medium
33 Search in Rotated Sorted Array28.7%Hard
32 Longest Valid Parentheses20.9%Hard
31 Next Permutation24.9%Medium
30 Substring with Concatenation of All Words19.6%Hard
29 Divide Two Integers14.9%Medium
28 Implement strStr()22.4%Easy
27 Remove Element31.8%Easy
26 Remove Duplicates from Sorted Array31.0%Easy
25 Reverse Nodes in k-Group25.3%Hard
24 Swap Nodes in Pairs32.3%Medium
23 Merge k Sorted Lists21.0%Hard
22 Generate Parentheses32.6%Medium
21 Merge Two Sorted Lists32.5%Easy
20 Valid Parentheses26.5%Easy
19 Remove Nth Node From End of List26.9%Easy
18 4Sum21.7%Medium
17 Letter Combinations of a Phone Number25.6%Medium
16 3Sum Closest26.8%Medium
15 3Sum16.9%Medium
14 Longest Common Prefix25.5%Easy
13 Roman to Integer34.3%Easy
12 Integer to Roman34.0%Medium
11 Container With Most Water31.8%Medium
10 Regular Expression Matching20.7%Hard
9 Palindrome Number28.4%Easy
8 String to Integer (atoi)12.8%Easy
7 Reverse Integer24.0%Easy
6 ZigZag Conversion21.5%Easy
5 Longest Palindromic Substring20.7%Medium
4 Median of Two Sorted Arrays17.1%Hard
3 Longest Substring Without Repeating Characters20.3%Medium
2 Add Two Numbers20.4%Medium
1 Two Sum17.7%Medium