Sunday, August 23, 2015

Tree algorithms review

August 23, 2015

Here is the list of tree questions worked on:

1. Lowest common ancestor in Binary Tree (January 6, 2016 - Leetcode question: 236 medium)

2. Leetcode 102: Binary tree level order traversal
a few of implementations:

3. C# files:
TreeDemo.cpp

  Pre Order Traversal
  In Order Traversal
  Post Order Traversal

  Breadth First Traversal
  Breadth First Traversal Iterative

 Pre Order Traversal Iterative
 Post Order Traversal Iterative*
 In Order Traversal Iterative (A, B two versions)

 Count One Child Node

 Recover Binary Tree

 Invert Binary Tree
 Invert Binary Tree Iterative

 --

Tree Post Order Iterative
Tree In order Iterative


4. Tree Max Path Sum


5. Linked List To Binary Search Tree


6. Zigzag order traversal of a binary Tree


7. Maximum Binary Tree Path Sum

How to come out the idea using max value cross root? Cannot recall the idea. 
Read the blog again (8/25/2015):
http://blog.unieagle.net/2012/12/09/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Abinary-tree-maximum-path-sum/

https://github.com/jianminchen/Leetcode_C-/blob/master/124BinaryTreeMaximumPathSum.cs

The problem can be extended to  a tree, not just a binary tree. The solution is here:
http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html

8. ININT5: tree maximum path sum


9. Binary Tree Maximum Distance, diameter of binary


10. Morris Inorder Traversal


11. Convert sorted List to binary search tree (I) (Leetcode question: No. 109)


12. Convert sorted list to binary search tree (II) (over 3 hours debugging to find a bug) (Leetcode question: No. 109)



August 23, 2015

It is so good to have chance to review post order traversal iterative solution. So, Julia had chance to read more about the problem, understand another solution using space O(log(n)), use a prev variable to keep track of the previously-traversed node. 

Also, she had chance to work out using two stacks solution for post order traversal iterative solution.
Like this, First stack,       root -> left child -> right child, the order of getting into first stack, 
however, second stack, root-> right child -> left child, the order of getting into second stack. 
since left, right child both get into the first stack, then, pop out two of them in reverse order. 


* Read the following blog to help understand post order traversal iterative

C# implementation of post order traversal iterative solution, using prev variable to help:

https://github.com/jianminchen/leetcode-tree/blob/master/TreePostOrderIterative_PrevVarirable.cs

August 24, 2015

13. Convert sorted list to binary search tree (No. 109)
Read the following blogs:
http://articles.leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html

C#, bottom up, time O(n), space O(log n) solution:
https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeB.cs

C#, top down, time O(n^2), space O(long n) solution:

worked on code 2 times, first time, the calculation is kind of messy, then, worked on Leetcode question 108, get the idea to make it more simple; tips like len/2 only shows once, afterwards, use m instead. Just need to improve coding, think to make it more abstract, simple.

https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeC.cs

14. Convert sorted array to binary search tree (No. 108)

https://github.com/jianminchen/Leetcode_C-/blob/master/108ConvertSortedArrayToBinarySearchTree.cs

August 27, 2015
Leetcode Tree questions (29 questions):

94
95
96
98
99
100
101
102
103
104
105
106
107
108
109
110
111
114
124
144
145
156
173
199
208
222
226
235
236
250


More practice using C#:
August 28, 2015
104
95
https://github.com/jianminchen/Leetcode_C-/blob/master/95UniqueBinarySearchTreeII.cs

98
Validate Binary Search Tree
Blogs to read: 
http://blog.csdn.net/likecool21/article/details/23271621
https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning

favorite blog about this problem:
http://huntfor.iteye.com/blog/2070278

solutions included in C# practice:
 1. recursive, time O(n), using beta-alpha pruning?
 2. recursive, use long Max value / min Value instead of int's to avoid the bug
 3. use inorder traversal output to help checking BST
 4. same as 3, value TreeNode variable
 5. sames as 3,
 6. same as 3,
 7. same as 3, but use iterative solution
 8. Great analysis, brute force solution, time complexity O(n^2) vs beta-alpha pruning time O(n)

https://github.com/jianminchen/Leetcode_C-/blob/master/98ValidateBinarySearchTree.cs

99 Recover Binary Search Tree - August 30, 2015

read blogs:

http://www.lifeincode.net/programming/leetcode-recover-binary-search-tree-java/
http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html

C# implementations:

https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoverBinarySearchTree.cs

https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoverBinarySearchTreeB.cs

work on extracting small functions, and then, understand the algorithm better.
https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoveryBinarySearchTree_C.cs

100 same tree

blogs to read:

http://blog.csdn.net/linhuanmars/article/details/22839819

http://www.cnblogs.com/lautsie/p/3247097.html

http://www.cnblogs.com/TenosDoIt/p/3440753.html

julia's implementation in C#
https://github.com/jianminchen/Leetcode_C-/blob/master/100SameTree.cs

Sept. 5, 2015

Morris order post order traversal

blogs to read:
http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html


C# implementation:
https://github.com/jianminchen/MorrisOrder/blob/master/MorrisPostOrder.cs


Morris order in order traversal

https://github.com/jianminchen/MorrisInOrderTraverse/blob/master/Program.cs



Sept. 7, 2015

101 Symmetric Tree

this one is good to follow
use queue

LinkedList - as queue - Java

105 Construct binary tree from preorder and inorder traversal

106 Construct binary tree from inorder and postorder traversal


second implementation using C#:
https://github.com/jianminchen/Leetcode_C-/blob/master/106ConstructBTreeFromInOrderPostOrderTraversal_B.cs
Sept. 13, 2015

208 Implement Trie (prefix tree)

blogs:
http://pisxw.com/algorithm/Implement-Trie-(Prefix%20Tree).html
http://www.jyuan92.com/blog/leetcode-implement-trie-prefix-tree/

August 25, 2015
January 5, 2015
Preorder traversal of ternary tree
https://github.com/jianminchen/TreeAlgorithms/blob/master/ternaryTreeTraversal.cs

  More reading about ternary tree:
https://en.wikipedia.org/wiki/Ternary_search_tree




Saturday, August 22, 2015

Leetcode question 51 - 60

August 22, 2015

51 N-Queens

https://github.com/jianminchen/AlgorithmsPractice/blob/master/EightPuzzelQueen.cs
https://github.com/jianminchen/Leetcode_C-/blob/master/51NQueenProblems.cs

http://juliachencoding.blogspot.ca/2015/06/algorithm-eight-puzzle-queen.html

52 N-Queens II

53 Maximum Subarray

54 Spiral Matrix

55 Jump Game

56 Merge Intervals

57 Insert Intervals

C# implementation:

https://github.com/jianminchen/Leetcode_C-/blob/master/57InsertIntervals.cs

58 Length of Last Word

https://github.com/jianminchen/Leetcode_C-/blob/master/58LengthOfLastWord.cs

59 Spiral Matrix II

60 Permutataion Sequence


Leetcode questions 161 - 170

August 22, 2015

161 One Edit distance


162 Find Peak Element

http://juliachencoding.blogspot.ca/2015/06/leetcode-question-find-peak-element.html

need to write first C# implementation for this problem.


163 Missing Ranges


164 Maximum Gap

165 Compare Version Numbers


166 Fraction to Recurring Decimal


167 Two Sum II - Input array is sorted


168 Excel Sheet Column Title


169 Majority Element


170 Two Sum III - Data Structure Design


Leetcode question 151 - 160

August 22, 2015

151 Reverse words in a string

152 Maximum Product Subarray

http://juliachencoding.blogspot.ca/2015/08/leetcode-maximum-product-subarray.html

153 Find Minimum in Rotated Sorted Array

154 Find Minimum in Rotated Sorted Array II


155 Min Stack

156 Binary Tree Upside Down

157 Read N Characters Given Read 4

158 Read N Characters Given Read 4 II - Call multiple times

159 Longest Substring with At Most Two Distinct Characters

160 Intersection of Two Linked List





Leetcode question 140 - 150

August 22, 2015

140 Word Break II


141 Linked List Cycle

142 Lined List Cycle II

143 Reorder List

144 Binary Tree Preorder Traversal

http://juliachencoding.blogspot.ca/2015/06/leetcode-binary-tree-preorder-traversal.html

145 Binary Tree Postorder Traversal

http://juliachencoding.blogspot.ca/2015/06/leetcode-post-order-binary-tree.html


146 LRU Cache

147 Insertion Sort List

148 Sort List

149 Max Points on a Line

150 Evaluate Reverse Polish Notation


Leetcode question 130 - 140

August 22, 2015

130 Surrounded Regions


131 Palindrome Partitioning


132 Palindrome Partitioning II


133 Clone Graph


134 Gas Station

135 Candy

http://juliachencoding.blogspot.ca/2015/06/leetcode-candy_9.html


136 Single Number

137 Single Number II

138 Copy List with Random Pointer


139 Word Break

140 Word Break II


Leetcode questions 120 - 130

August 22, 2015

120 Triangle

write a blog, need to write C# code.
http://juliachencoding.blogspot.ca/2015/06/leetcode-triangle.html


121 Best  Time to Buy and Sell Stock


122 Best  Time to Buy and Sell Stock  II

123 Best  Time to Buy and Sell Stock  II I


124 Binary Tree Maximum Path Sum

http://juliachencoding.blogspot.ca/2015/07/leetcode-maximum-binary-tree-path-sum.html

Tree Maximum Path Sum
http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html

Tree maximum path sum:


125 Valid Palindrome


126 Word Ladder II


127 Word Ladder

http://juliachencoding.blogspot.ca/2015/06/leetcode-word-ladder.html

128 Longest Consecutive Sequence


129 Sum Root to Leaf Numbers


130 Surrounded Regions

--
Question No: 124

C# implementation:
https://github.com/jianminchen/Leetcode_C-/blob/master/124BinaryTreeMaximumPathSum.cs

Maybe, similar problem: ITINT5 Tree Maximum Path Sum

http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html




Leetcode question 111 - 120

August 22, 2015

 111 Minimum Depth of Binary Tree

112 Path Sum

113 Path Sum II

114 Flatten Binary Tree to Linked List


115 Distinct Subsequences

116 Populating Next Right Pointers in Each Node

117 Populating Next Right Pointers in Each Node II


118 Pascal's Triangle

119 Pascal's Triangle II

120 Triangle


Leetcode questions 100 - 110

August 22, 2015

100 Same Tree

101 Symmetric Tree

102 Binary Tree Level Order Traversal

103 Binary Tree Zigzag Level Order Traversal

104 Maximum Depth of Binary Tree

105 Construct Binary Tree from Preorder and Inorder Traversal

106 Constructu Binary Tree from Inorder and Postorder Traversal

107 Binary Tree level Order Traversal II

108 Convert Sorted Array To Binary Search Tree

109 Convert Sorted List to Binary Search Tree

110 Balanced Binary Tree

--


101 Symmetric Tree (Sept. 8, 2015)

102 Binary Tree Level Order Traversal
6 different solutions:


103 Binary Tree Zigzag Level Order Traversal

104 Maximum Depth of Binary Tree
108  Convert sorted array to binary search tree (No. 108)


109 Convert sorted list to binary search tree (No. 109)

8/25/2015
Read the following blogs:

C#, bottom up, time O(n), space O(log n) solution - best solution:
C#, top down, time O(n^2), space O(long n) solution - naive solution:

worked on code 2 times, first time, the calculation is kind of messy, then, worked on Leetcode question 108, get the idea to make it more simple; tips like len/2 only shows once, afterwards, use m instead. Just need to improve coding, think to make it more abstract, simple.

https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeC.cs

9/21/2015
Review the best solution, and then, totally forgot the bottom up solution idea. So, update the code with more comment.

Need to review more about bottom up/ top down solution in tree problems. Get more experience on bottom-up solution, read some articles about it. 

Leetcode questions 90 - 100

August 22, 2015

90 subsets II

91 Decode ways

92 Reverse Linked List II

93 Restore IP Addresses

94 Binary Tree Inorder Traversal

95 Unique Binary Search Trees II

96 Unique Binary Search Trees

97 Interleaving String

98 Validate Binary Search Trees

99 Recover Binary Search Tree

100 Same Tree

-- Julia's practice:

94 Binary Tree Inorder Traversal

Julia's C# implementation:
https://github.com/jianminchen/leetcode-tree/blob/master/TreeDemo.cs

95 Unique Binary Search Trees II

https://github.com/jianminchen/Leetcode_C-/blob/master/95UniqueBinarySearchTreeII.cs


97 Interleaving String
the blog containing reading list:
http://juliachencoding.blogspot.ca/2015/06/leetcode-interleave-string.html

Need to write first C# implementation.

99 Recover Binary Search Tree

blogs:

http://www.lifeincode.net/programming/leetcode-recover-binary-search-tree-java/
http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html

C# implementations:

https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoverBinarySearchTree.cs

https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoverBinarySearchTreeB.cs

work on extracting small functions, and then, understand the algorithm better.
https://github.com/jianminchen/Leetcode_C-/blob/master/99RecoveryBinarySearchTree_C.cs

100 same tree
 Two implementations,one recursive, one iterative solution.
https://github.com/jianminchen/Leetcode_C-/blob/master/100SameTree.cs

Leetcode question 80-90

August 22, 2015

80  Remove duplicates from Sorted Array II


81 Search in Rotated Sorted Array II

82 Remove Duplicates from Sorted List II

83 Remove Duplicates from Sorted List

84 Largest Rectangle in Histogram

http://juliachencoding.blogspot.ca/2015/06/leetcode-largest-rectangle-in-histogram.html

85 Maximal Rectangle

86 Partition List

87 Scramble String

http://juliachencoding.blogspot.ca/2015/06/leetcode-scramble-string.html

need to write first C# implementation for the problem.

88 Merge Sorted Array

89 Gray Code

90 Subsets II


Leetcode questions: 70 - 80

August 22, 2015


70 climbing stairs

71 Simplify Path

72 Edit Distance

http://juliachencoding.blogspot.ca/2015/06/leetcode-edit-distance.html

73 Set Matrix Zeroes

74 Search a 2D Matrix

75 Sort Colors

76 Minimum Window Substring

77 Combinations

78 Subsets


79 Word Search

http://juliachencoding.blogspot.ca/2015/07/leetcode-word-search.html

Leetcode questions from 41 - 50

August 22, 2015

41 Frist Missing Positive

42 Trapping Rain Water

43 Multiply Strings


44 Wildcard Matching

45 Jump Game II

46 Permutations

47 Permutations II

48 Rotate Image

49 Anagrams

50 Pow(x, n)

http://juliachencoding.blogspot.ca/2015/06/leetcode-powerxn.html

C# implementation:

https://github.com/jianminchen/powerOfN/blob/master/Program.cs







Leetcode questions 11 - 20

August 22, 2015


11 Container with Most water
blog:
http://www.cnblogs.com/TenosDoIt/p/3812880.html

C#:
https://github.com/jianminchen/Leetcode_C-/blob/master/11ContainerWithMostWater.cs

12. Integer to Roman


13 Roman to Integer

https://github.com/jianminchen/Leetcode_C-/blob/master/13RomanToInteger.cs

14. LOngest Common Prefix

https://github.com/jianminchen/Leetcode_C-/blob/master/LongestCommonPrefix_No14.cs

15. 3Sum

16 3 Sum Closest

https://github.com/jianminchen/Leetcode_C-/blob/master/3sumCloset.cs

17 Letter Combinations of a phone number (DFS)

http://www.cnblogs.com/grandyang/p/4452220.html
Analysis from the above blog:
这道题让我们求电话号码的字母组合,即数字2到9中每个数字可以代表若干个字母,然后给一串数字,求出所有可能的组合,相类似的题目有 Path Sum II 二叉树路径之和之二,Subsets II 子集合之二,Permutations 全排列,Permutations II 全排列之二,Combinations 组合项, Combination Sum 组合之和和 Combination Sum II 组合之和之二等等。我们用递归Recursion来解,我们需要建立一个字典,用来保存每个数字所代表的字符串,然后我们还需要一个变量level,记录当前生成的字符串的字符个数,实现套路和上述那些题十分类似,

https://github.com/jianminchen/Leetcode_C-/blob/master/LetterCombinationOfAPhoneNumber.cs

18 4 sum

19 Remove Nth Node From End of List

20 Valid Parentheses

http://blog.csdn.net/fightforyourdream/article/details/13011825

C# code:
https://github.com/jianminchen/Leetcode_C-/blob/master/20ValidParentheses.cs
January 20, 2016
https://github.com/jianminchen/Leetcode_C-/blob/master/20ValidParentheses_B.cs

favorite blogs to read: January 20, 2016
http://bangbingsyb.blogspot.ca/2014/11/leetcode-valid-parentheses.html

http://www.acmerblog.com/leetcode-solution-valid-parentheses-6316.html

http://blog.csdn.net/foreverling/article/details/49685177?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

http://segmentfault.com/a/1190000003481208

http://harrifeng.github.io/algo/leetcode/valid-parentheses.html

http://www.jiuzhang.com/solutions/valid-parentheses/

So, ready to work on the next algorithm about parentheses:
Leetcode 32: longest valid parentheses -
http://codeganker.blogspot.ca/2014/03/longest-valid-parentheses-leetcode.html


Friday, August 21, 2015

Leetcode questions from 61 - 69

August 21, 2015

Speed up study leetcode questions, 10 question a time, in 2-3 hours. And see if I can learn something quickly.

61 Rotate List

62 Unique Paths



DP algorithm in detail, time complexity and space complexity analysis is great in the following blog:





63 Unique Paths II

64 Minimum Path Sum

discussion of using 2 dimension array or using one dimension array, still not clear.

understand this blog on DP solutions, one is space O(n^2), one is space O(n).


65 Valid number

ideas for the solution from the following blog: 
3 flags are set: num, exp, dot, and then,
1. if there is e flag, then there is a digit before e flag, cannot have any e.
Also, there is a digit followed.
2. if . shows up, then it is a small fraction number, so neither . nor e is before .
3. if +, -, then it must be first one, or the previous on is e,
for example: "005047e+6".
The above summary is from the following blog:

code is here:



66 Plus number

67 Add Binary

Totally forget I did this implementation. So, I have to learn everything about this problem again, read more blogs this time.

https://github.com/jianminchen/addBinary/blob/master/Program.cs

my favorite solution is the following blog:
http://fisherlei.blogspot.ca/2013/01/leetcode-add-binary.html

julia's C# code:
https://github.com/jianminchen/Leetcode_C-/blob/master/67AddBinary2.cs

http://bangbingsyb.blogspot.ca/2014/11/leetcode-add-binary.html

the code should be more short, but the discussion and idea in the code is very clear.
http://siddontang.gitbooks.io/leetcode-solution/content/string/add_binary.html

Good quality code, try it myself later.
http://www.jiuzhang.com/solutions/add-binary/

julia's c# implementation:
https://github.com/jianminchen/Leetcode_C-/blob/master/67AddBinary.cs



68 Text Justification


70 Climbing Stairs

http://juliachencoding.blogspot.ca/2015/07/leetcode-climbing-stairs.html


Tuesday, August 18, 2015

Leetcode question 20 - 30

August 18, 2015

Work on those ten questions quickly, spend 20 minutes on each question; Do not over analyze the problem, try to get basic idea and implementation tips through blogs first.

22 Generate Parentheses

https://github.com/jianminchen/Leetcode_C-/blob/master/GenerateParentheses_No22.cs

23 Merge K Sorted Lists

https://github.com/jianminchen/Leetcode_C-/blob/master/MergeKSortedLists_A_No23.cs

https://github.com/jianminchen/Leetcode_C-/blob/master/MargeKSortedLists_B_No23.cs

24 Swap nodes in pairs

https://github.com/jianminchen/Leetcode_C-/blob/master/24SwapNodesInPairs.cs


C# implementation:
https://github.com/jianminchen/Leetcode_C-/blob/master/24SwapNodesInPairs.cs

25 Reverse Nodes in k-Group

26 Remove Duplicates from Sorted Array

27 Remove Element

28 Implement strStr()

29 Divide Two Integers

30 Substring with Concatenation of All Words



Thursday, August 13, 2015

Leetcode: questions and favorite blogs

August 13, 2015, 

Go over the leetcode questions one by one, find one blog/ more to help me fully understand the problem. 改变学习方法, 广度优先, 多做题, 保持一定速度, 接触新的题目; 先看题解, 直接看代码; 一个小时学习二道题的速度. 

23 Merge k Sorted Lists hard  

22 Generate Parentheses  (fight for dream) http://blog.csdn.net/fightforyourdream/article/details/14159435
http://blog.csdn.net/linhuanmars/article/details/19873463   (more easy to understand) (one line error)

21 Merge two sorted lists 
http://www.cnblogs.com/springfor/p/3862040.html    (show how to optimize the code! Very good. )

22 valid parentheses   easy

19 remove Nth node from End of List

http://www.cnblogs.com/springfor/p/3862219.html (very clever tip for faster pointer)

Here are C# code folder:
https://github.com/jianminchen/Leetcode_C-





Wednesday, August 12, 2015

Blogging benefits

Julia likes to keep her own research on writing benefits as a software programmer. So, she keeps the log of her research.

August 12, 2015

Read two articles about benefits about blogging as a software programmer. Great ideas in the blog.


http://kb.cnblogs.com/page/517038/

http://kb.cnblogs.com/page/526625/

Dec. 17, 2015
Take some notes from above blogs:

提高自己对知识的掌握层次

  美国教育心理学家Bloom将知识认知分为了两个维度,其中认知历程维度又分为6个层次, 由低到高,分别为:记忆、理解、应用、分析、评鉴、创造。层次越高,表示对知识的掌握程度越深。

提高表达和沟通的能力

接受读者的沟通和反馈

影响力

January 3, 2015

Thomas Friedman: Lessons Learned After 20 Years of Writing Columns

https://www.youtube.com/watch?v=dxXx3XvNVWA&list=PLxq_lXOUlvQAwaY_9K4ZFH9Xdar9WzCaL&index=19

Note:
1. Learn to listen; person can sense if you listen, respect him/her; wait until he/she finishes the talking.
2. Always be a big tipper. Sign of respect. Always be nice to helper.
3. Always call your mother. I wish I can call mine.

January 12, 2015


Hiring Rockstars by Roger Philby

https://www.youtube.com/watch?v=R22dJ7bn-pU&list=PLgYNPs-V9YFPqcnEvbIy5hFE40BjxMbjw&index=2

A person loves to write, then the person must love to read, and then, the person must be intellect curious. That is one of 5 things in the talk:

1. intellect value
     - how we judge people - how we collaborate - highly collaborate - not collaborate - collaboration -  need to know that, how to measure

fast/decisive - consensus - relationship - seek colloaborate

value in your business - big company

3. conformity -

4. Motivation -

5. Experience -

High performance -

March 23, 2016

http://onstartups.com/tabid/3339/bid/14208/Why-Every-Entrepreneur-Should-Write-and-9-Tips-To-Get-Started.aspx

http://www.c-sharpcorner.com/article/why-every-developer-should-write/



Julia's reading list of CSS, html, Java Script

CSS/ Jquery/ Html  reading list
Julia read several articles to expand knowledge about CSS, html, Java Script, and here is her reading list compiled on August 12, 2015:
  1. August 28, 2013
Read the article web standards curriculum
  1. May 9, 2013, read the article, and then memorize the selectors.
  1. Visual formatting model (August 26, 2013):
  1. CSS 2.1 primer
  1. Cascading Style Sheets articles and tutorials (August 28, 2013)
  1. Inheritance and cascade (Nov. 18, 2013): (learning specificity calculation in detail)
  1. Basic Structures of a web page (Nov. 27, 2013):
  1. CSS absolute and fixed positioning (Nov. 20, 2013)
  1. Javascript Guide (Mozzila Foundation US)
  1. CSS pocket book: (March 24, 2015)

Monday, August 10, 2015

Java Script book reading and videos

August 10, 2015
Spent 12 months starting from January 2014 to study Java Script, it is most challenging language I learned and finally get used to this functional language, dynamic, loosely type language. Enjoy reading the Java Script code and play with the code.
Here are some resources most helpful to my personal experience:
Books I read, some of them only a few pages here and there:
  1. [O`Reilly] - JavaScript. The Definitive Guide, 6th ed. - [Flanagan]
Only read 200 pages of the book (total pages: around 1000 pages), spent 2-3 months to read, practice
  1. JavaScript for PHP Developers
Tried examples in the book, and practiced some. Focused on first 3 chapters. Great book!
  1. JavaScript Patterns
  2. Javascript cookbook
  3. [Manning] - Secrets of the JavaScript Ninja - [Resig]
  4. O'reilly - Head First Javascript
  5. Maintainable JavaScript
  6. Java Script good parts
  7. Testable JavaScript (one of my favorite books)
Videos I watched:
  1. Douglas Crokford: The Javascript Programming language and most of the videos from him on Youtube.com
  1. Learning to love Javascript and a lot of other google videos about Javascript

Leetcode: Maximum product subarray

August 10, 2015
Find the contiguous subarray within an array (containing at least one number)
which has the largest product.
For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest product = 6.
Two approaches, one is dynamic programming DP implementation, another is the greedy method.
DP solution:
Greedy algorithm:
read the blog first,
http://fmarss.blogspot.ca/2014/10/leetcode-solution-maximum-product.html

and then, convert it to C# programming language, 

Saturday, August 8, 2015

Leetcode 239: sliding window maximum

August 7, 2015
Julia spent 20-30 minutes to think about solution first, and read the following blogs, write some code as well. She practised three time using C# and here are the details.

C# practices


Here are 3 practice Julia did using LinkedList, List and SortedList. 

1. C# LinkedList

C# code implementation

2. C# List<int>

3. C# SortedList


More detail

Double ended queue is implemented using C# LinkedList class, here is Julia's C# practice code: C# code implementation

Julia chose to study the blog on Leetcode: sliding window maximum

C# code implementation (C# does not have deque class, so using C# List<int>, 
convert Python code implementation to C#, time limit exceeded)

Good workout on C# List<int>, Julia experienced different style on removing head element if out of sliding window. 

Julia chose to read the blog on geekforgeek.com called "maximum of all subarrays of size k". 

Method A: naive solution, time complexity O(nw)
C# practice code is here. 

Method B: using Self-Balancing Tree (Time complexity: O(nk), need to write c# code)

C# practice code is here. 


4. blog:

http://n00tc0d3r.blogspot.ca/2013/04/sliding-window-maximum.html

Good comment about Deque:

We can use a Deque which allow insertions/deletions on both ends. For a Deque implemented by Circular Array/Buffer or Double Linked List, the basic insert/delete operations run in constant time.

discussion of using heap: 
 The first thought might be heap.
By maintaining a heap for all numbers in the window can give us a O(nlogw)-time solution, where
  • building up a heap for initial window takes time O(wlogw)
  • when window moves to the next number, each insertion and deletion take time O(logw) and there are n-w moves in total.
  • after updating the heap, findMax only takes time O(1) since we know the top of heap is the largest.
  •  
So, if w << n, the performance of this solution is good, close to O(n); but if w is not that small, say w = n/3 or n/4, the running time goes up to O(nlogn).

5. blog:   C++ code 
using C++ multiset in the above solution, so try to convert it to C# class using SortedList

C# practice code

6. blog:
http://www.mamicode.com/info-detail-927510.html

Convert Java Script code to C#; I spent over 12 months to try to be expert on Java Script, so much fun to read the Java Script code again, and enjoyed the blog about the analysis. 

Others:
https://github.com/jianminchen/slidingWindowMaximum/blob/master/slidingWindowMaximu5.cs