This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| Design an algorithm and write code to serialize and deserialize a binary tree. | |
| Writing the tree to a file is called 'serialization' | |
| and reading back from the file to reconstruct | |
| the exact same binary tree is 'deserialization'. | |
| There is no limit of how you deserialize or serialize a binary tree, | |
| you only need to make sure you can serialize a binary tree to a string | |
| and deserialize this string to the original structure. | |
| Have you met this question in a real interview? Yes | |
| Example | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <div class="github-widget pull-left" | |
| data-toggle="github-widget" | |
| data-user="UserId" | |
| data-widget="gists" | |
| data-body="auto" | |
| data-footer="auto" | |
| data-limit="4"> | |
| </div> | |
| <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css" /> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <div class="github-card" data-user="UserID"></div> | |
| <script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <script src="https://cdn.rawgit.com/moski/gist-Blogger/master/public/gistLoader.js" type="text/javascript"></script> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Packer: | |
| delimiter = '#|#' | |
| @staticmethod | |
| def pack(string_list): | |
| packed = '' | |
| for s in string_list: | |
| mlist = list(s) | |
| for i, char in enumerate(mlist): | |
| if char == '#': | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| Use serveral ways to compress string `everyday is awesome!` | |
| 1. use simple bits to replace ASCII value | |
| 2. use huffman coding | |
| """ | |
| def get_rate(compressed_binary, uncompressed_bits): | |
| return len(compressed_binary) * 100 / uncompressed_bits | |
| class SimpleCompression: | |
| def __init__(self, string): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # helpers start | |
| class Tree: | |
| def __init__(self, val): | |
| self.val = val | |
| self.left = self.right = None | |
| def __repr__(self): | |
| return '[ %d ]' % self.val | |
| def get_tree(): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def print_spiral(matrix): | |
| m, n = len(matrix), len(matrix[0]) | |
| top, down = 0, m - 1 | |
| left, right = 0, n - 1 | |
| while True: | |
| for j in xrange(left, right + 1): | |
| print(matrix[top][j]) | |
| top += 1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ## | |
| # Trie Solution | |
| import collections | |
| class Trie: | |
| class TrieRoot: | |
| def __init__(self): | |
| self.children = {} | |
| self.shortest_word = None | |
| class TrieNode: | |
| def __init__(self, char=''): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| Dropbox | |
| Question: Given root directory, search all directories and return duplicate files | |
| input: root path | |
| output: list[list[]] | |
| """ | |
| import os | |
| import collections |