LeetCode - Restore IP Addresses


Given a string containing only digits, restore it by returning all possible valid IP address combinations.
For example: given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
Note: according to the feedback from the test cases, any part that is in the form of '0x' or '0xx' is not valid.
Recursion: Using DFS
from http://blog.csdn.net/u011095253/article/details/9158449
0-255的数字,转换成字符,即每个Part 可能由一个字符组成,二个字符组成,或者是三个字符组成。那这又成为组合问题了,dfs便呼之欲出
所以我们写一个For循环每一层从1个字符开始取一直到3个字符,再加一个isValid的函数来验证取的字符是否是合法数字,如果是合法的数字,我们再进行下一层递归,否则跳过。
Maybe we can convert String to list first.
https://discuss.leetcode.com/topic/24184/backtracking-solution-in-java-easy-to-understand/2
public List<String> restoreIpAddresses(String s) {
    List<String> res = new ArrayList<>();
    if(s == null || s.length() == 0 || s.length() > 12) {
        return res;
    }
    helper(s, res, new StringBuilder(), 0, 0);
    return res;
}

private void helper(String s, List<String> res, StringBuilder sb, int pos, int count) {
    if(pos == s.length() && count == 3) {
        res.add(sb.toString());
        return;
    }
    if(count == 3 || pos == s.length()) {
        return;
    }
    for(int i = pos; i < s.length(); i++) {
        String t = s.substring(pos, i+1);
        if(t.length() > 3 || t.length() > 1 && t.charAt(0) == '0' || Integer.valueOf(t) > 255) {
            break;
        }
        int len = sb.length();
        
        sb.append(t);
        if(i+1 != s.length()) {
            sb.append(".");
            helper(s, res, sb, i+1, count+1);
        } else {
            helper(s, res, sb, i+1, count);
        }
        sb.setLength(len);
    }
}
https://discuss.leetcode.com/topic/34366/java-recursive-backtracking-easy-to-read
public List<String> restoreIpAddresses(String s) {
    List<String> ret = new LinkedList<>();
    int[] path = new int[4];
    helper(ret, s, 0,  path, 0);
    return ret;
}

void helper(List<String> acc, String s, int idx, int[] path,  int segment){
    if(segment == 4 && idx == s.length() ){
        acc.add(path[0] + "." + path[1] + "."+ path[2] + "." + path[3]);
        return ;
    }else if(segment == 4 || idx == s.length() ){
        return ;
    }
    
    for(int len = 1; len <= 3 && idx + len <= s.length() ; len ++){
        int val = Integer.parseInt(s.substring(idx, idx + len));// not good
        // range check, no leading 0.
        if(val > 255 || len >= 2  && s.charAt(idx) == '0') 
            break; 
            
        path[segment] = val;
        helper(acc, s, idx + len, path, segment + 1);
        path[segment] = -1; // for debug. 
    }
}
https://discuss.leetcode.com/topic/41384/simple-java-solution-beating-100-of-java-submissions
private static final char DOT = '.';

public List<String> restoreIpAddresses(String s) {
    List<String> result = new ArrayList<String>();
    
    char[] digits = s.toCharArray();
    int len = s.length();
    char[] currIpAddr = new char[len+3];
    int pos = 0;
    generateIpAddresses(digits, 4, 0, len, currIpAddr, pos, result);
    
    return result;
}

private void generateIpAddresses(char[] digits, int remSegs, int start, int len, 
                                 char[] currIpAddr, int pos, List<String> result) {
        if(start == len && remSegs == 0) {
            result.add(String.valueOf(currIpAddr));
            return;
        }   
    
   //1. Checks for length of s too small
   //2. Maximum Length of the remaining segments. Since a sgemnt can be upto 3 digits
   // Length can not exceed 3x the remaining segments.
   //3. Minimum Length of s. Each segment has to be atleast 1 digit
    if((start > len) || ((len - start) > (3 * remSegs)) || ((len - start) < remSegs))
        return;
    
    if(remSegs < 4)
        currIpAddr[pos++] = DOT;
    
    int num = 0;
    
    for(int i = 0; i < Math.min(len-start, 3);i++) {
        num = (10*num) + (int)(digits[start+i] - '0');//\\
        
        if(i > 0 && num < 10)// leading 0 cases i = 1, then the number should be > 10.
            return;
        
        ////"010010"
        //Valid: ["0.10.0.10","0.100.1.0"]
        //Invalid: ["0.1.0.010","0.1.00.10","0.1.001.0","0.10.0.10","0.10.01.0","0.100.1.0",
        //"01.0.0.10","01.0.01.0","01.00.1.0","010.0.1.0"]
        
        if(num <= 255) {
            currIpAddr[pos+i] = digits[start+i];
            generateIpAddresses(digits, remSegs-1, start+i+1, len, currIpAddr, pos+i+1, result);
        }
    }
  }  

http://www.shuatiblog.com/blog/2014/05/24/Restore-IP-Addresses/
public ArrayList<String> restoreIpAddresses(String s) {
    ArrayList<String> res = new ArrayList<String>();  
    if (s.length()<4||s.length()>12) return res;  
    dfs(s,"",res,0);  
    return res;  
}  

public void dfs(String s, String tmp, ArrayList<String> res, int count){  
    if (count == 3 && isValid(s)) {  
        res.add(tmp + s);  
        return;  
    }  
    for(int i=1; i<4 && i<s.length(); i++){  
        String substr = s.substring(0,i);  
        if (isValid(substr)){  
            dfs(s.substring(i), tmp + substr + '.', res, count+1);  
        }  
    }  
}  

public boolean isValid(String s){  
    if (s.charAt(0)=='0') return s.equals("0");  
    int num = Integer.parseInt(s);  
    return num<=255 && num>0;  
}  
https://discuss.leetcode.com/topic/4742/very-simple-dfs-solution

http://www.jyuan92.com/blog/leetcode-restore-ip-addresses/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public List<String> restoreIpAddresses(String s) {
    List<String> res = new LinkedList<String>();
    if (null == s || s.length() < 4 || s.length() > 12) {
        return res;
    }
    helper(res, s, new LinkedList<String>(), 0);
    return res;
}
private void helper(List<String> res, String s, List<String> list, int count) {
    if (list.size() == 4) {
        if (count == s.length()) {
            StringBuilder sb = new StringBuilder();
            for (String ip : list) {
                sb.append(ip);
                sb.append(".");
            }
            sb.deleteCharAt(sb.length() - 1);
            res.add(sb.toString());
        }
        return;
    }
    for (int i = count; i <= count + 3 && i < s.length(); i++) {
        String temp = s.substring(count, i + 1);
        if (isValid(temp)) {
            list.add(temp);
            helper(res, s, list, i + 1);
            list.remove(list.size() - 1);
        }
    }
}

  1. Here, we should realise that there is no need to do Backtracking after recursive, because every time when you do operation on String, it will create a new String rather than the original one.
  2. after recurive the first three part, we can just using the remain string to check for the fourth part
public List<String> restoreIpAddresses2(String s) {
    List<String> res = new LinkedList<String>();
    if (null == s || s.length() < 4 || s.length() > 12) {
        return res;
    }
    helper2(res, s, "", 0);
    return res;
}
private void helper2(List<String> res, String s, String str, int count) {
    if (count == 3 && isValid(s)) {
        res.add(str + s);
        return;
    }
    for (int i = 0; i < s.length() - 1 && i <= 3; i++) {
        String temp = s.substring(0, i + 1);
        if (isValid(temp)) {
            helper2(res, s.substring(i + 1), str + temp + ".", count + 1);
        }
    }
}
http://www.jiuzhang.com/solutions/restore-ip-addresses/
    public ArrayList<String> restoreIpAddresses(String s) {
        ArrayList<String> result = new ArrayList<String>();
        ArrayList<String> list = new ArrayList<String>();
        
        if(s.length() <4 || s.length() > 12)
            return result;
        
        helper(result, list, s , 0);
        return result;
    }
    
    public void helper(ArrayList<String> result, ArrayList<String> list, String s, int start){
        if(list.size() == 4){
            if(start != s.length())
                return;
            
            StringBuffer sb = new StringBuffer();
            for(String tmp: list){
                sb.append(tmp);
                sb.append(".");
            }
            sb.deleteCharAt(sb.length()-1);
            result.add(sb.toString());
            return;
        }
        
        for(int i=start; i<s.length() && i<= start+3; i++){
            String tmp = s.substring(start, i+1);
            if(isvalid(tmp)){
                list.add(tmp);
                helper(result, list, s, i+1);
                list.remove(list.size()-1);
            }
        }
    }
    
    private boolean isvalid(String s){
        if(s.charAt(0) == '0')
            return s.equals("0"); // to eliminate cases like "00", "10"
        int digit = Integer.valueOf(s);
        return digit >= 0 && digit <= 255;
    }


http://www.programcreek.com/2014/06/leetcode-restore-ip-addresses-java/

public List<String> restoreIpAddresses(String s) {
    ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
    ArrayList<String> t = new ArrayList<String>();
    dfs(result, s, 0, t);
 
    ArrayList<String> finalResult = new ArrayList<String>();
 
    for(ArrayList<String> l: result){
        StringBuilder sb = new StringBuilder();
        for(String str: l){
            sb.append(str+".");
        }
        sb.setLength(sb.length() - 1);
        finalResult.add(sb.toString());
    }
 
    return finalResult;
}
 
public void dfs(ArrayList<ArrayList<String>> result, String s, int start, ArrayList<String> t){
    //if already get 4 numbers, but s is not consumed, return
    if(t.size()>=4 && start!=s.length()) 
        return;
 
    //make sure t's size + remaining string's length >=4
    if((t.size()+s.length()-start+1)<4) 
        return;
 
    //t's size is 4 and no remaining part that is not consumed.
    if(t.size()==4 && start==s.length()){
        ArrayList<String> temp = new ArrayList<String>(t);
        result.add(temp);
        return;
    }
 
    for(int i=1; i<=3; i++){
        //make sure the index is within the boundary
        if(start+i>s.length()) 
            break;
 
        String sub = s.substring(start, start+i);
        //handle case like 001. i.e., if length > 1 and first char is 0, ignore the case.
        if(i>1 && s.charAt(start)=='0'){
            break;    
        }
 
        //make sure each number <= 255
        if(Integer.valueOf(sub)>255)
            break;
 
        t.add(sub);
        dfs(result, s, start+i, t);
        t.remove(t.size()-1);
    }
http://bangbingsyb.blogspot.com/2014/11/leetcode-restore-ip-addresses.html
于以s[i]开头的数字有3种可能:
1. s[i]
2. s[i : i+1],s[i] !=0时
3. s[i : i+2],s[i] != 0,且s[i : i+2] <= 255
    bool isValidNum(string s) {
        if(s.empty() || s.size()>3) return false;
        if(s[0]=='0' && s.size()!=1) return false;
        if(s.size()==3 && stoi(s)>255) return false;
        return true;
    }
https://leetcode.com/discuss/80435/java-recursive-backtracking-easy-to-read
public List<String> restoreIpAddresses(String s) { List<String> ret = new LinkedList<>(); int[] path = new int[4]; helper(ret, s, 0, path, 0); return ret; } void helper(List<String> acc, String s, int idx, int[] path, int segment){ if(segment == 4 && idx == s.length() ){ acc.add(path[0] + "." + path[1] + "."+ path[2] + "." + path[3]); return ; }else if(segment == 4 || idx == s.length() ){ return ; } for(int len = 1; len <= 3 && idx + len <= s.length() ; len ++){ int val = Integer.parseInt(s.substring(idx, idx + len)); // range check, no leading 0. if(val > 255 || len >= 2 && s.charAt(idx) == '0') break; path[segment] = val; helper(acc, s, idx + len, path, segment + 1); path[segment] = -1; // for debug. not needed } }
X. Iterative Version:
https://discuss.leetcode.com/topic/6304/my-concise-ac-java-code
the basic idea is to make three cuts into the string, separating it into four parts, each part contains 1~3 digits and it must be <255.
you don't need the fourth for loop with d. since d = len - (a+b+c) and
//java int D= Integer.valueof(s.substr(a+b+c)))
static List<String> restoreIpAddresses(String s) {
 List<String> ans = new ArrayList<String>();
 int len = s.length();
 for (int i = 1; i <=3; ++i){  // first cut
  if (len-i > 9) continue;    //  
  for (int j = i+1; j<=i+3; ++j){  //second cut
   if (len-j > 6) continue;   //    
   for (int k = j+1; k<=j+3 && k<len; ++k){  // third cut
    int a,b,c,d;                // the four int's seperated by "."
    a = Integer.parseInt(s.substring(0,i));  
    b = Integer.parseInt(s.substring(i,j)); // notice that "01" can be parsed into 1. Need to deal with that later.
    c = Integer.parseInt(s.substring(j,k));
    d = Integer.parseInt(s.substring(k));
    if (a>255 || b>255 || c>255 || d>255) continue; 
    String ip = a+"."+b+"."+c+"."+d;
    if (ip.length()<len+3) continue;  // this is to reject those int's parsed from "01" or "00"-like substrings
    ans.add(ip);
   }
  }
 }
 return ans;
}

https://discuss.leetcode.com/topic/3919/my-code-in-java
3-loop divides the string s into 4 substring: s1, s2, s3, s4. Check if each substring is valid. In isValid, strings whose length greater than 3 or equals to 0 is not valid; or if the string's length is longer than 1 and the first letter is '0' then it's invalid; or the string whose integer representation greater than 255 is invalid.
-- not efficient as the one below. - if s1 is not valid, no need to continue
public List<String> restoreIpAddresses(String s) { List<String> res = new ArrayList<String>(); int len = s.length(); for(int i = 1; i<4 && i<len-2; i++){ for(int j = i+1; j<i+4 && j<len-1; j++){ for(int k = j+1; k<j+4 && k<len; k++){ String s1 = s.substring(0,i), s2 = s.substring(i,j), s3 = s.substring(j,k), s4 = s.substring(k,len); if(isValid(s1) && isValid(s2) && isValid(s3) && isValid(s4)){ res.add(s1+"."+s2+"."+s3+"."+s4); } } } } return res; } public boolean isValid(String s){ if(s.length()>3 || s.length()==0 || (s.charAt(0)=='0' && s.length()>1) || Integer.parseInt(s)>255) return false; return true; }

public ArrayList<String> restoreIpAddresses(String s) {
    ArrayList<String> res = new ArrayList<String>();  
    if (s.length() > 12 || s.length() < 4) return res;
    for (int i = 1; i < 4; i ++) {
        String first = s.substring(0, i);
        if (! isValid(first)) continue;
        for (int j = 1; i + j < s.length() && j < 4; j ++) {
            String second = s.substring(i, i + j);
            if (! isValid(second)) continue;
            for (int k = 1; i + j + k < s.length() && k < 4; k ++) {
                String third = s.substring(i + j, i + j + k);
                String fourth = s.substring(i + j + k);
                if (isValid(third) && isValid(fourth)) 
                    res.add(first + "." + second + "." + third + "." + fourth);
            }
        }
    }
    return res;
}
https://leetcode.com/discuss/19296/my-concise-ac-java-code
static List<String> restoreIpAddresses(String s) { List<String> ans = new ArrayList<String>(); int len = s.length(); for (int i = 1; i <=3; ++i){ // first cut if (len-i > 9) continue; for (int j = i+1; j<=i+3; ++j){ //second cut if (len-j > 6) continue; for (int k = j+1; k<=j+3 && k<len; ++k){ // third cut int a,b,c,d; // the four int's seperated by "." a = Integer.parseInt(s.substring(0,i)); b = Integer.parseInt(s.substring(i,j)); // notice that "01" can be parsed into 1. Need to deal with that later. c = Integer.parseInt(s.substring(j,k)); d = Integer.parseInt(s.substring(k)); if (a>255 || b>255 || c>255 || d>255) continue; String ip = a+"."+b+"."+c+"."+d; if (ip.length()<len+3) continue; // this is to reject those int's parsed from "01" or "00"-like substrings ans.add(ip); } } } return ans; }
http://www.darrensunny.me/leetcode-restore-ip-addresses/
Alternatively, we can consider each part iteratively by explicitly determining the positions of the dots.
public ArrayList<String> restoreIpAddresses(String s) {
        ArrayList<String> result = new ArrayList<String>();
        if (s == null)
            return result;
        int n = s.length();
        if (n < 4 || n > 12)
            return result;
        // For each possible first part
        for (int i = 1; i <= 3; i++) {      // At most three digits at each part
            if (n-i > 9)    // The number of digits for remaining three parts should not exceed 9
                continue;
            if (s.charAt(0) == '0' && i > 1)    // 0x or 0xx is not allowed
                break;
            String first = s.substring(0, i);   // String before the first dot
            if (Integer.parseInt(first) <= 255) {   // The first part is within proper range
                // For each possible second part given the first part
                for (int j = i+1; j <= i+3 && j < n; j++) {
                    if (n-j > 6)    // The number of digits for remaining two parts should not exceed 6
                        continue;
                    if (s.charAt(i) == '0' && j > i+1)
                        break;
                    String second = s.substring(i, j);  // String after the first dot and before the second
                    if (Integer.parseInt(second) <= 255) {  // The second part is within proper range
                        // For each possible third part given the second part
                        for (int k = j+1; k <= j+3 && k < n; k++) {
                            if (n-k > 3)    // The number of digits for remaining part should not exceed 3
                                continue;
                            if (s.charAt(j) == '0' && k > j+1)
                                break;
                            String third = s.substring(j, k);   // String after the second dot and before the third
                            if (Integer.parseInt(third) <= 255) {   // The third part is within proper range
                                // If the fourth part is a single digit, or it does not begin with a '0' and
                                // it is within proper range, we have got a valid IP address
                                if (k == n-1 || s.charAt(k) != '0' && Integer.parseInt(s.substring(k)) <= 255)
                                    result.add(first+'.'+second+'.'+third+'.'+s.substring(k));
                            }
                        }
                    }
                }
            }
        }
        return result;
    }
https://leetcode.com/discuss/88736/who-can-beat-this-code
vector<string> restoreIpAddresses(string s) { vector<string> ret; string ans; for (int a=1; a<=3; a++) for (int b=1; b<=3; b++) for (int c=1; c<=3; c++) for (int d=1; d<=3; d++) if (a+b+c+d == s.length()) { int A = stoi(s.substr(0, a)); int B = stoi(s.substr(a, b)); int C = stoi(s.substr(a+b, c)); int D = stoi(s.substr(a+b+c, d)); if (A<=255 && B<=255 && C<=255 && D<=255) if ( (ans=to_string(A)+"."+to_string(B)+"."+to_string(C)+"."+to_string(D)).length() == s.length()+3) ret.push_back(ans); } return ret; }
Also refer to http://yucoding.blogspot.com/2013/04/leetcode-question-83-restore-ip.html
Read full article from LeetCode - Restore IP Addresses | Darren's Blog

Labels

LeetCode (1432) GeeksforGeeks (1122) LeetCode - Review (1067) Review (882) Algorithm (668) to-do (609) Classic Algorithm (270) Google Interview (237) Classic Interview (222) Dynamic Programming (220) DP (186) Bit Algorithms (145) POJ (141) Math (137) Tree (132) LeetCode - Phone (129) EPI (122) Cracking Coding Interview (119) DFS (115) Difficult Algorithm (115) Lintcode (115) Different Solutions (110) Smart Algorithm (104) Binary Search (96) BFS (91) HackerRank (90) Binary Tree (86) Hard (79) Two Pointers (78) Stack (76) Company-Facebook (75) BST (72) Graph Algorithm (72) Time Complexity (69) Greedy Algorithm (68) Interval (63) Company - Google (62) Geometry Algorithm (61) Interview Corner (61) LeetCode - Extended (61) Union-Find (60) Trie (58) Advanced Data Structure (56) List (56) Priority Queue (53) Codility (52) ComProGuide (50) LeetCode Hard (50) Matrix (50) Bisection (48) Segment Tree (48) Sliding Window (48) USACO (46) Space Optimization (45) Company-Airbnb (41) Greedy (41) Mathematical Algorithm (41) Tree - Post-Order (41) ACM-ICPC (40) Algorithm Interview (40) Data Structure Design (40) Graph (40) Backtracking (39) Data Structure (39) Jobdu (39) Random (39) Codeforces (38) Knapsack (38) LeetCode - DP (38) Recursive Algorithm (38) String Algorithm (38) TopCoder (38) Sort (37) Introduction to Algorithms (36) Pre-Sort (36) Beauty of Programming (35) Must Known (34) Binary Search Tree (33) Follow Up (33) prismoskills (33) Palindrome (32) Permutation (31) Array (30) Google Code Jam (30) HDU (30) Array O(N) (29) Logic Thinking (29) Monotonic Stack (29) Puzzles (29) Code - Detail (27) Company-Zenefits (27) Microsoft 100 - July (27) Queue (27) Binary Indexed Trees (26) TreeMap (26) to-do-must (26) 1point3acres (25) GeeksQuiz (25) Merge Sort (25) Reverse Thinking (25) hihocoder (25) Company - LinkedIn (24) Hash (24) High Frequency (24) Summary (24) Divide and Conquer (23) Proof (23) Game Theory (22) Topological Sort (22) Lintcode - Review (21) Tree - Modification (21) Algorithm Game (20) CareerCup (20) Company - Twitter (20) DFS + Review (20) DP - Relation (20) Brain Teaser (19) DP - Tree (19) Left and Right Array (19) O(N) (19) Sweep Line (19) UVA (19) DP - Bit Masking (18) LeetCode - Thinking (18) KMP (17) LeetCode - TODO (17) Probabilities (17) Simulation (17) String Search (17) Codercareer (16) Company-Uber (16) Iterator (16) Number (16) O(1) Space (16) Shortest Path (16) itint5 (16) DFS+Cache (15) Dijkstra (15) Euclidean GCD (15) Heap (15) LeetCode - Hard (15) Majority (15) Number Theory (15) Rolling Hash (15) Tree Traversal (15) Brute Force (14) Bucket Sort (14) DP - Knapsack (14) DP - Probability (14) Difficult (14) Fast Power Algorithm (14) Pattern (14) Prefix Sum (14) TreeSet (14) Algorithm Videos (13) Amazon Interview (13) Basic Algorithm (13) Codechef (13) Combination (13) Computational Geometry (13) DP - Digit (13) LCA (13) LeetCode - DFS (13) Linked List (13) Long Increasing Sequence(LIS) (13) Math-Divisible (13) Reservoir Sampling (13) mitbbs (13) Algorithm - How To (12) Company - Microsoft (12) DP - Interval (12) DP - Multiple Relation (12) DP - Relation Optimization (12) LeetCode - Classic (12) Level Order Traversal (12) Prime (12) Pruning (12) Reconstruct Tree (12) Thinking (12) X Sum (12) AOJ (11) Bit Mask (11) Company-Snapchat (11) DP - Space Optimization (11) Dequeue (11) Graph DFS (11) MinMax (11) Miscs (11) Princeton (11) Quick Sort (11) Stack - Tree (11) 尺取法 (11) 挑战程序设计竞赛 (11) Coin Change (10) DFS+Backtracking (10) Facebook Hacker Cup (10) Fast Slow Pointers (10) HackerRank Easy (10) Interval Tree (10) Limited Range (10) Matrix - Traverse (10) Monotone Queue (10) SPOJ (10) Starting Point (10) States (10) Stock (10) Theory (10) Tutorialhorizon (10) Kadane - Extended (9) Mathblog (9) Max-Min Flow (9) Maze (9) Median (9) O(32N) (9) Quick Select (9) Stack Overflow (9) System Design (9) Tree - Conversion (9) Use XOR (9) Book Notes (8) Company-Amazon (8) DFS+BFS (8) DP - States (8) Expression (8) Longest Common Subsequence(LCS) (8) One Pass (8) Quadtrees (8) Traversal Once (8) Trie - Suffix (8) 穷竭搜索 (8) Algorithm Problem List (7) All Sub (7) Catalan Number (7) Cycle (7) DP - Cases (7) Facebook Interview (7) Fibonacci Numbers (7) Flood fill (7) Game Nim (7) Graph BFS (7) HackerRank Difficult (7) Hackerearth (7) Inversion (7) Kadane’s Algorithm (7) Manacher (7) Morris Traversal (7) Multiple Data Structures (7) Normalized Key (7) O(XN) (7) Radix Sort (7) Recursion (7) Sampling (7) Suffix Array (7) Tech-Queries (7) Tree - Serialization (7) Tree DP (7) Trie - Bit (7) 蓝桥杯 (7) Algorithm - Brain Teaser (6) BFS - Priority Queue (6) BFS - Unusual (6) Classic Data Structure Impl (6) DP - 2D (6) DP - Monotone Queue (6) DP - Unusual (6) DP-Space Optimization (6) Dutch Flag (6) How To (6) Interviewstreet (6) Knapsack - MultiplePack (6) Local MinMax (6) MST (6) Minimum Spanning Tree (6) Number - Reach (6) Parentheses (6) Pre-Sum (6) Probability (6) Programming Pearls (6) Rabin-Karp (6) Reverse (6) Scan from right (6) Schedule (6) Stream (6) Subset Sum (6) TSP (6) Xpost (6) n00tc0d3r (6) reddit (6) AI (5) Abbreviation (5) Anagram (5) Art Of Programming-July (5) Assumption (5) Bellman Ford (5) Big Data (5) Code - Solid (5) Code Kata (5) Codility-lessons (5) Coding (5) Company - WMware (5) Convex Hull (5) Crazyforcode (5) DFS - Multiple (5) DFS+DP (5) DP - Multi-Dimension (5) DP-Multiple Relation (5) Eulerian Cycle (5) Graph - Unusual (5) Graph Cycle (5) Hash Strategy (5) Immutability (5) Java (5) LogN (5) Manhattan Distance (5) Matrix Chain Multiplication (5) N Queens (5) Pre-Sort: Index (5) Quick Partition (5) Quora (5) Randomized Algorithms (5) Resources (5) Robot (5) SPFA(Shortest Path Faster Algorithm) (5) Shuffle (5) Sieve of Eratosthenes (5) Strongly Connected Components (5) Subarray Sum (5) Sudoku (5) Suffix Tree (5) Swap (5) Threaded (5) Tree - Creation (5) Warshall Floyd (5) Word Search (5) jiuzhang (5)

Popular Posts