LeetCode 385 - Mini Parser


https://www.hrwhisper.me/leetcode-mini-parser/
Given a nested list of integers represented as a string, implement a parser to deserialize it.
Each element is either an integer, or a list -- whose elements may also be integers or other lists.
Note: You may assume that the string is well-formed:
  • String is non-empty.
  • String does not contain white spaces.
  • String contains only digits 0-9[- ,].
Example 1:
Given s = "324",

You should return a NestedInteger object which contains a single integer 324.
Example 2:

Given s = "[123,[456,[789]]]",

Return a NestedInteger object containing a nested list with 2 elements:

1. An integer containing value 123.
2. A nested list containing two elements:
    i.  An integer containing value 456.
    ii. A nested list with one element:
         a. An integer containing value 789.
X. Using Stack
https://discuss.leetcode.com/topic/54270/an-java-iterative-solution/
Actually instead of using substring() to parse the integer, we could iteratively construct the number. The other parts are the same.
https://segmentfault.com/a/1190000007394571
https://www.xiadong.info/2016/08/16/leetcode-385-mini-parser/
每次遇到一个“["就推进去一个nextedinteger,每次碰到一个数字,就在stack.peek().add(number)。每次碰到一个右括号,就把pop()出peek()的nexted integer,并将其压到栈顶的nestedinteger中。
public NestedInteger deserialize(String s) {
    // check the input string first;
    // .... if(s == null) return ..null 
    char[] arr = s.toCharArray();
    if(arr[0] != '[') return new NestedInteger(Integer.parseInt(s));
    Stack<NestedInteger> stack = new Stack<>();
    for(int i = 0; i < arr.length; i ++) {
        char ch = arr[i];
        if(ch == '[') {
            stack.push(new NestedInteger());
        }
        else if(ch == ']' && stack.size() > 1) {
            NestedInteger top = stack.pop();
            stack.peek().add(top);          
        }
        else if(Character.isDigit(ch) || ch == '-') {
            boolean pos = true;
            if(ch == '-') pos = false;
            int num = 0;
            while(i < arr.length && Character.isDigit(arr[i])) {
                num *= 10;
                num += arr[i] - '0';
                i ++;
            }
            // move i back to the integer, [788],
            // otherwise will skip the ']'
            i --;
            stack.peek().add(pos ? num : -num);
        }
    }
    return stack.pop();
}
https://discuss.leetcode.com/topic/54270/an-java-iterative-solution
This approach will just iterate through every char in the string (no recursion).
  • If encounters '[', push current NestedInteger to stack and start a new one.
  • If encounters ']', end current NestedInteger and pop a NestedInteger from stack to continue.
  • If encounters ',', append a new number to curr NestedInteger, if this comma is not right after a brackets.
  • Update index l and r, where l shall point to the start of a integer substring, while r shall points to the end+1 of substring.
public NestedInteger deserialize(String s) {
    if (s.isEmpty())
        return null;
    if (s.charAt(0) != '[') // ERROR: special case
        return new NestedInteger(Integer.valueOf(s));
        
    Stack<NestedInteger> stack = new Stack<>();
    NestedInteger curr = null;
    int l = 0; // l shall point to the start of a number substring; 
               // r shall point to the end+1 of a number substring
    for (int r = 0; r < s.length(); r++) {
        char ch = s.charAt(r);
        if (ch == '[') {
            if (curr != null) {
                stack.push(curr);
            }
            curr = new NestedInteger();
            l = r+1;
        } else if (ch == ']') {
            String num = s.substring(l, r);
            if (!num.isEmpty())
                curr.add(new NestedInteger(Integer.valueOf(num)));
            if (!stack.isEmpty()) {
                NestedInteger pop = stack.pop();
                pop.add(curr);
                curr = pop;
            }
            l = r+1;
        } else if (ch == ',') {
            if (s.charAt(r-1) != ']') {
                String num = s.substring(l, r);
                curr.add(new NestedInteger(Integer.valueOf(num)));
            }
            l = r+1;
        }
    }
    
    return curr;
}
Review
    public NestedInteger deserialize(String s) {
        if (!s.startsWith("[")) {
            return new NestedInteger(Integer.valueOf(s));
        }
        Stack<NestedInteger> stack = new Stack<>();
        NestedInteger res = new NestedInteger();
        stack.push(res);
        int start = 1;
        for (int i = 1; i < s.length(); i ++) {
            char c = s.charAt(i);
            if (c == '[') {
                NestedInteger ni = new NestedInteger();
                stack.peek().add(ni);
                stack.push(ni);
                start = i + 1;
            } else if (c == ',' || c == ']') {
                if (i > start) {
                    Integer val = Integer.valueOf(s.substring(start, i));
                    stack.peek().add(new NestedInteger(val));
                }
                start = i + 1;
                if (c == ']') {
                    stack.pop();
                }
            } 
        }
        return res;
    }
https://www.programcreek.com/2014/08/leetcode-mini-parser-java/
http://blog.csdn.net/yeqiuzs/article/details/52208388
public NestedInteger deserialize(String s) {
 
    Stack<NestedInteger> stack = new Stack<NestedInteger>();
    String temp = "";
 
    for(char c: s.toCharArray()){
        switch(c){
            case '[':
                stack.push(new NestedInteger()); //start a new NI
                break;
 
            case ']':
                if(!temp.equals("")){
                    stack.peek().add(new NestedInteger(Integer.parseInt(temp))); //add NI to parent
                    temp="";
                }
 
                NestedInteger top = stack.pop();
                if(!stack.empty()){
                    stack.peek().add(top);
                }else{
                    return top;
                }
 
                break;
 
            case ',':
                if(!temp.equals("")){
                    stack.peek().add(new NestedInteger(Integer.parseInt(temp)));//add NI to parent
                    temp="";
                }
 
                break;
 
            default:
                temp += c;
        }
    }
 
    if(!temp.equals("")){
        return new NestedInteger(Integer.parseInt(temp));
    }
 
    return null;
}


由于没有空格,所以第一个字母不是'[‘的说明只有一个数字。直接返回NestedInteger(int(s))
接下来,用一个栈来维护,对于左括号[的,当前的NestedInteger 进栈,对于右括号,当前数字放入NestedInteger 栈不为空则把栈顶的NestedInteger添加当前的NestedInteger,并且出栈。
http://bookshadow.com/weblog/2016/08/15/leetcode-mini-parser/
http://wisim.me/leetcode/2016/08/18/LeetCode_MinParser.html

Use StringBuilder
http://www.jianshu.com/p/4578be7c2270
    public NestedInteger deserialize(String s) {
        if (s == null || s.length() == 0) {
            return null;
        }

        if (s.charAt(0) != '[') {
            return new NestedInteger(Integer.parseInt(s));
        }

        Stack<NestedInteger> st = new Stack<NestedInteger>();
        String temp = "";
        for (int i = 0; i < s.length(); i++) {
            char curr = s.charAt(i);
            switch (curr) {
                case '[':
                    st.push(new NestedInteger());
                    break;
                case ']':
                    if (temp.length() != 0) {
                        st.peek().add(new NestedInteger(Integer.parseInt(temp)));
                        temp = "";
                    }               
                    if (st.size() > 1) {
                        NestedInteger node = st.pop();
                        st.peek().add(node);
                    }
                    break;
                case ',':
                    if (temp.length() != 0) {
                        st.peek().add(new NestedInteger(Integer.parseInt(temp)));
                        temp = "";
                    }
                    break;
                default:
                    temp = temp + curr;
                    break;
            }
        }

        return st.pop();
    }
http://buttercola.blogspot.com/2015/11/airbnb-mini-parser.html
http://yuanhsh.iteye.com/blog/2230314
  private static class NestedIntList {
    private int value;
    private boolean isNumber;
    private List<NestedIntList> intList;
     
    // Constructor to construct a number
    public NestedIntList(int value) {
      this.value = value;
      isNumber = true;
    }
     
    // Constructor to construct a list
    public NestedIntList() {
      intList = new ArrayList<>();
      isNumber = false;
    }
     
    public void add(NestedIntList num) {
      this.intList.add(num);
    }
     
    public NestedIntList miniParser(String s) {
      if (s == null || s.length() == 0) {
        return null;
      }
       
      // Corner case "123"
      if (s.charAt(0) != '[') {
        int num = Integer.parseInt(s);
        return new NestedIntList(num);
      }
       
      int i = 0;
      int left = 1;
      Stack<NestedIntList> stack = new Stack<>();
      NestedIntList result = null;
       
      while (i < s.length()) {
        char c = s.charAt(i);
        if (c == '[') {
          NestedIntList num = new NestedIntList();
          if (!stack.isEmpty()) {
            stack.peek().add(num);
          }
          stack.push(num);
          left = i + 1;
        } else if (c == ',' || c == ']') {
          if (left != i) {
            int value = Integer.parseInt(s.substring(left, i));
            NestedIntList num = new NestedIntList(value);
            stack.peek().add(num);
          }
          left = i + 1;
           
          if (c == ']') {
            result = stack.pop();
          }
        }
         
        i++;
      }
       
      return result;
    }
     
    public String toString() {
      if (this.isNumber) {
        return this.value + "";
      } else {
        return this.intList.toString();
      }
    }
  }

http://blog.csdn.net/yeqiuzs/article/details/52208388
用栈维护一个包含关系,类似于用栈维护带 '(' 的表达式。
思路不难想到,有个坑爹的细节要注意:添加一个数到list type的nestedInteger时 要将该数封装为integer type的NestedInteger,然后用add方法添加该nestedInteger,不能直接用setInteger,否则会把list type的nestedInteger定义为一个integer type,会出错。
还可以用递归来做,思路大致是:没处理完一个token,遇到 [  递归处理 返回该层list结尾下标。好像有点麻烦。。留坑日后待填。
  1. public NestedInteger deserialize(String s) {  
  2.     Stack<NestedInteger> stack = new Stack<NestedInteger>();  
  3.     String tokenNum = "";  
  4.   
  5.     for (char c : s.toCharArray()) {  
  6.         switch (c) {  
  7.         case '['://[代表一个list  
  8.             stack.push(new NestedInteger());  
  9.             break;  
  10.         case ']'://list结尾  
  11.             if (!tokenNum.equals(""))//前面token为数字   
  12.                 stack.peek().add(new NestedInteger(Integer.parseInt(tokenNum)));//将数字加入到本层list中  
  13.             NestedInteger ni = stack.pop();//本层list结束  
  14.             tokenNum = "";  
  15.             if (!stack.isEmpty()) {//栈内有更高层次的list  
  16.                 stack.peek().add(ni);  
  17.             } else {//栈为空,遍历到字符串结尾  
  18.                 return ni;  
  19.             }  
  20.             break;  
  21.         case ',':  
  22.             if (!tokenNum.equals("")) //将数字加入到本层list中  
  23.                 stack.peek().add(new NestedInteger(Integer.parseInt(tokenNum)));  
  24.             tokenNum = "";  
  25.             break;  
  26.         default:  
  27.             tokenNum += c;  
  28.         }  
  29.     }  
  30.     if (!tokenNum.equals(""))//特殊case: 如果字符串只包含数字的情况  
  31.         return new NestedInteger(Integer.parseInt(tokenNum));  
  32.     return null;  
  33. }  

我们也可以使用迭代的方法来做,这样就需要使用栈来辅助,变量start记录起始位置,我们遍历字符串,如果遇到'[',我们给栈中加上一个空的NestInteger,如果遇到的字符数逗号或者']',如果i>start,那么我们给栈顶元素调用add来新加一个NestInteger,初始化参数传入start到i之间的子字符串转为的整数,然后更新start=i+1,当遇到的']'时,如果此时栈中元素多于1个,那么我们将栈顶元素取出,加入新的栈顶元素中通过调用add函数
    NestedInteger deserialize(string s) {
        if (s.empty()) return NestedInteger();
        if (s[0] != '[') return NestedInteger(stoi(s));
        stack<NestedInteger> st;
        int start = 1;
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == '[') {
                st.push(NestedInteger());
                start = i + 1;
            } else if (s[i] == ',' || s[i] == ']') {
                if (i > start) {
                    st.top().add(NestedInteger(stoi(s.substr(start, i - start))));
                }
                start = i + 1;
                if (s[i] == ']') {
                    if (st.size() > 1) {
                        NestedInteger t = st.top(); st.pop();
                        st.top().add(t);
                    }
                }
            }
        }
        return st.top();
    }
X. Recursive Version
https://zhanghuimeng.github.io/post/leetcode-385-mini-parser/
    NestedInteger decomposeList(string s) {
        // s是一个数字
        // 好消息是,我感觉用了stoi之后,就不需要自己考虑-的问题了
        if (s.length() > 0 && s[0] != '[')
            return NestedInteger(stoi(s));
        // s是一个列表
        s = s.substr(1, s.length() - 2);
        NestedInteger nestedInteger;
        // 并不能简单地用,作为分隔,而是要找到一整个子列表
        int start = 0, leftBrackets = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == ',') {
                if (leftBrackets != 0)
                    continue;
                nestedInteger.add(decomposeList(s.substr(start, i - start)));
                start = i + 1;
            }
            if (s[i] == '[')
                leftBrackets++;
            if (s[i] == ']')
                leftBrackets--;
        }
        if (start < s.length())
            nestedInteger.add(decomposeList(s.substr(start, s.length() - start)));
        return nestedInteger;
    }

public:
    NestedInteger deserialize(string s) {
        // 刚看到这个的时候我很懵逼
        // 原来是让我们利用这个interface来做题啊……
        return decomposeList(s);
    }
https://discuss.leetcode.com/topic/54277/short-java-recursive-solution/2
    public NestedInteger deserialize(String s) {
        NestedInteger ret = new NestedInteger();
        if (s == null || s.length() == 0) return ret;
        if (s.charAt(0) != '[') {
            ret.setInteger(Integer.parseInt(s));
        }
        else if (s.length() > 2) {
            int start = 1, count = 0;
            for (int i = 1; i < s.length(); i++) {
                char c = s.charAt(i);
                if (count == 0 && (c == ',' || i == s.length() - 1)) {
                    ret.add(deserialize(s.substring(start, i)));
                    start = i + 1;
                }
                else if (c == '[') count++;
                else if (c == ']') count--;
            }
        }
        return ret;
    }
https://discuss.leetcode.com/topic/54407/java-recursive-solution-one-scan-clean-easy-to-understand
  1. if '[', construct a new NestedInteger;
  2. if ']', add the number before ']' if it exists, the character before ']' must be a number or ']';
  3. if ',', add the number before ',' if it exists, the character before ',' must be a number or ']';
  4. if a number, just add the right pointer.
    public NestedInteger deserialize(String s) {
        if (s.charAt(0) != '[') return new NestedInteger(Integer.parseInt(s));
        NestedInteger result = new NestedInteger();
        helper(s, 1, result);
        return result;
    }

    private int helper(String s, int idx, NestedInteger parent) {
        int l = idx, r = idx;
        while (r < s.length()) {
            String num = s.substring(l, r);//don't do here
            if (s.charAt(r) == '[') {
                NestedInteger child = new NestedInteger();
                parent.add(child);
                r = helper(s, r + 1, child);
                l = r;
            } else if (s.charAt(r) == ']') { // get num here
                if (!num.isEmpty()) parent.add(new NestedInteger(Integer.valueOf(num)));
                return r + 1;
            } else if (s.charAt(r) == ',') {//get num here
                if (!num.isEmpty()) parent.add(new NestedInteger(Integer.valueOf(num)));
                r++;
                l = r;
            } else {
                r++;
            }
        }
        return s.length();
    }
http://www.cnblogs.com/grandyang/p/5771434.html
我们可以先用递归来做,思路是,首先判断s是否为空,为空直接返回,不为空的话看首字符是否为'[',是的话说明s为一个整数,我们直接返回结果。如果首字符是'[',且s长度小于等于2,说明没有内容,直接返回结果。反之如果s长度大于2,我们从i=1开始遍历,我们需要一个变量start来记录某一层的其实位置,用cnt来记录跟其实位置是否为同一深度,cnt=0表示同一深度,由于中间每段都是由逗号隔开,所以当我们判断当cnt为0,且当前字符是逗号或者已经到字符串末尾了,我们把start到当前位置之间的字符串取出来递归调用函数,把返回结果加入res中,然后start更新为i+1。如果遇到'[',计数器cnt自增1,若遇到']',计数器cnt自减1
    NestedInteger deserialize(string s) {
        if (s.empty()) return NestedInteger();
        if (s[0] != '[') return NestedInteger(stoi(s));
        if (s.size() <= 2) return NestedInteger();
        NestedInteger res;
        int start = 1, cnt = 0;
        for (int i = 1; i < s.size(); ++i) {
            if (cnt == 0 && (s[i] == ',' || i == s.size() - 1)) {
                res.add(deserialize(s.substr(start, i - start)));
                start = i + 1;
            } else if (s[i] == '[') ++cnt;
            else if (s[i] == ']') --cnt;
        }
        return res;
    }

X. Recursive version 2
https://discuss.leetcode.com/topic/59029/short-and-clean-java-recursive-solution-with-explanation
Using the "lvl" variable to track if we are inside an inner integer.
Using lIndex to track the leftmost start position.
Every time the program hit the "[" increase lvl, and decrease lvl when hit "]"
When the program meets ","
If lvl != 0, ignore the "," since we are inside a nested integer
else do recursive call ,add the result to the current list and move lIndex.
[ [abc, [xy]] , def, [qqq] ]
ni.add(myDeserialize("[abc, [xy]]"));
ni.add(myDeserialize("def");
ni.add(myDeserialize("[qqq]");
public NestedInteger deserialize(String s) {
    if (s.length() == 0)    return new NestedInteger();
    return myDeserialize(s, 0, s.length()-1);
}

private NestedInteger myDeserialize(String s, int start, int end) {
    if (s.charAt(start) != '[') 
        return new NestedInteger(Integer.valueOf(s.substring(start, end+1)));

    NestedInteger ni = new NestedInteger();
    int lvl = 0, lIndex = start+1;

    for (int i=start+1 ; i<=end-1 ; ++i) {
        char ch = s.charAt(i);
        if (ch == '[')  ++lvl;
        else if (ch == ']') --lvl; 
        else if (ch == ',' && lvl == 0) {
            ni.add(myDeserialize(s, lIndex, i-1));
            lIndex = i + 1;
        }
    }
    if (lIndex <= end-1) {
        ni.add(myDeserialize(s, lIndex, end-1));
    }
    return ni;        
}
https://discuss.leetcode.com/topic/54277/short-java-recursive-solution
Just for people who try this approach instead of stack. This takes much more time than stack as the depth of elements grow. If you would like to reduce time complexity, use stack as a space trade-off for time.
    public NestedInteger deserialize(String s) {
        NestedInteger ret = new NestedInteger();
        if (s == null || s.length() == 0) return ret;
        if (s.charAt(0) != '[') {
            ret.setInteger(Integer.parseInt(s));
        }
        else if (s.length() > 2) {
            int start = 1, count = 0;
            for (int i = 1; i < s.length(); i++) {
                char c = s.charAt(i);
                if (count == 0 && (c == ',' || i == s.length() - 1)) {
                    ret.add(deserialize(s.substring(start, i)));
                    start = i + 1;
                }
                else if (c == '[') count++;
                else if (c == ']') count--;
            }
        }
        return ret;
    }
https://discuss.leetcode.com/topic/55872/very-short-recursive-solution
    NestedInteger parse(string& s, int& i) {
      if(s[i]=='[') {
          ++i;
          NestedInteger list;
          while(s[i] != ']') {
              list.add(parse(s,i));
              if(s[i] ==',') ++i;
          }
          ++i;
          return list;
      } else {                       
        int sum = 0;
        int sign=1;
        if(s[i] == '-'){ sign = -1; ++i;}
        while(isdigit(s[i])) { sum *= 10; sum+= s[i]-'0'; ++i;}
          return NestedInteger(sum*sign);
      }
    }
    NestedInteger deserialize(string s) {
        int i = 0;
        return parse(s, i);
    }
https://discuss.leetcode.com/topic/54274/java-10-ms-while-loop-recursion-one-scan

https://discuss.leetcode.com/topic/54268/straightforward-java-solution-with-explanation-and-a-simple-implementation-of-nestedinteger-for-your-ease-of-testing
class NestedInteger {
    private List<NestedInteger> list;
    private Integer integer;
    
    public NestedInteger(List<NestedInteger> list){
        this.list = list;
    }
    
    public void add(NestedInteger nestedInteger) {
        if(this.list != null){
            this.list.add(nestedInteger);
        } else {
            this.list = new ArrayList();
            this.list.add(nestedInteger);
        }
    }

    public void setInteger(int num) {
        this.integer = num;
    }

    public NestedInteger(Integer integer){
        this.integer = integer;
    }

    public NestedInteger() {
        this.list = new ArrayList();
    }

    public boolean isInteger() {
        return integer != null;
    }

    public Integer getInteger() {
        return integer;
    }

    public List<NestedInteger> getList() {
        return list;
    }
    
    public String printNi(NestedInteger thisNi, StringBuilder sb){
        if(thisNi.isInteger()) {
            sb.append(thisNi.integer);
            sb.append(",");
        }
        sb.append("[");
        for(NestedInteger ni : thisNi.list){
            if(ni.isInteger()) {
                sb.append(ni.integer);
                sb.append(",");
            }
            else {
                printNi(ni, sb);
            }
        }
        sb.append("]");
        return sb.toString();
    }
}


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