Sunday, June 12, 2016

HackerRank: Sherlock and anagram - warmup practice after 3 months

June 12, 2016

Introduction 

First, software coding -> tennis sports -> gardening - a small talk 

Julia likes blossom of flowers, she enjoyed but does not have time to do any gardening work. She spends a lot of hours on tennis court to keep her physical fit, cheer her up, play social games to build up very good team sports spirit through her workout. 

She observes neighborhood gardeners watering the flower, grass every day in summer time, in the city of Vancouver,  it takes a lot of hard work. She enjoys the neighborhood gardening. 

So, to show some talent in software coding, she likes to learn from a patient gardener, watering, taking away weeds. In other words, read her own coding blog, learn to educate herself better through the short period of time.  

Today, she likes to bring back her favorite practice 3 months ago, an algorithm - "Sherlock and anagram", and then review them, write more practice. 

3 months is not long time, but those past 3 months, Julia found out that she is street-smart again. She starts to get more organized, more time-savvy, and know the importance to push herself to write her own words about experience. It does help. 

One example, she stops to check in C# file using github, she just uses gist to quickly create a link. She did create almost 300 gists, each gist saves 5 minutes compared to check in files using github, she saved 1500 minutes, close to 25 hours time. 

Another example, she tries to focus on reasoning and analysis, writing things to help her solve problem. One problem a time. So, she works on one problem, using more than 5 solutions - BFS, DFS, using Queue, using Stack, phone number problem, therefore, she can apply the problem solving to all other similar problems. 

Workout 

Now, work on the coding:

1. HackerRank: Sherlock and anagram - 7 blogs with practices
Practice on HackerRank is like to play tennis sports, you have to experience various hitting partners, good workout!

No. 1.
http://juliachencoding.blogspot.ca/2016/03/hackerrank-string-sherlock-and-anagrams.html

No. 2
http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlock-and-anagrams-ii.html

No. 3

http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlocks-and-anagram-ii.html

No. 4 Study 6 solutions - Julia chose from over 200 solutions
http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlock-and-anagrams-iv.html

Julia, work on this code, and put test case in, write your own C# practice:
study the code, order by values,  not by key, try it!
https://gist.github.com/jianminchen/ffcca0582b5f0d1d6a9b

study the blog: Dictionary OrderByDescending
https://goo.gl/6ZbTPz
baby step to learn C# Dictionary class API - Order by and distinct
https://gist.github.com/jianminchen/eff03bea08a95061deb4185af74fea18

No. 6
http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlock-and-anagram-vii.html

Warm up 12 solutions - "Sherlock and anagram" one by one. Each one for a blog. Focus on speed, correctness.

Saturday, June 11, 2016

Algorithms to study

June 11, 2016

Prepare to write some code. Find algorithms to work on.

1. Leetcode 76: Minimum Window Substring
Study the code:
http://blog.csdn.net/sunnyyoona/article/details/43925035

2. Leetcode 91: Decode the ways
https://github.com/jianminchen/puzzles/blob/master/decode_ways.cc

2D. Leetcode 128: Longest Consecutive Sequence in Array

2E. Leetcode 139, 140, Word break

2F. Leetcode 150 Evaluate Reverse Polish Notation

3A. Leetcode 289: Game of Life
3B. Leetcode 298: Longest Consecutive Sequence in BT

4. LeetCode 351 - Android Unlock Patterns

Study the code:
http://massivealgorithms.blogspot.ca/2016/06/leetcode-351-android-unlock-patterns.html

5. Read project Euler website:

https://projecteuler.net/archives

6.  Strobogrammatic number I, II, III (246, 247, 248)

Study code:
http://buttercola.blogspot.ca/2015/08/leetcode-strobogrammatic-number.html

https://tonycao.gitbooks.io/leetcode-locked/content/LeetCode%20Locked/c1.5.html

https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/246.strobogrammatic-number.java

https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/247.strobogrammatic-number-ii.java

https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/248.strobogrammatic-number-iii.java

7. One minute call 60 times at most

Leaky bucket algorithm
https://en.wikipedia.org/wiki/Leaky_bucket


8. Stock Maximization
https://www.hackerrank.com/challenges/stockmax

9.

http://www.careercup.com/question?id=5840928073842688

11. Leetcode: shortest word distance I, II, III
https://segmentfault.com/a/1190000003906667

study Leetcode solution:
https://github.com/MaskRay/LeetCode

12. Leetcode 53: Maximum Subarray
https://github.com/jianminchen/Leetcode_C-/blob/master/53MaximumSubArray1.cs
https://github.com/jianminchen/Leetcode_C-/blob/master/53MaximumSubArray2.cs

http://juliachencoding.blogspot.ca/2015/07/dp-problem-kadanes-algorithm-maximum.html

13. Leetcode 352 - Data Stream as Disjoint Intervals  (Hard - 34% passing rate)
http://www.cnblogs.com/grandyang/p/5548284.html

14. Leetcode 174 Dungeon game



15. Leetcode 247 H-index



16. Leetcode 269 Alien dictionary

17. Leetcode 142 Linked List Cycle II

17B. Leetcode 286 Walls and Gates

18. Leetcode 329 Longest increasing path in matrix
19. Leetcode 345 Reverse Vowels of a string
20. Leetcode 354 Russian Doll Envelopes

Flatten Linked List
http://www.geeksforgeeks.org/flattening-a-linked-list/

Blogs: Learn system design:
https://www.quora.com/How-should-I-prepare-for-my-Google-interview-if-I-have-1-month-left

80 questions to think about:
https://www.educative.io/collection/5642554087309312/5679846214598656

有O(N*M)的算法,思路是转换成直方图然后维护一个栈。
一个矩阵里,里面元素是0或者1,要你找一个面积最大的全1的子矩阵。
如果不要求是矩形只要求是一块任意形状的区域的话,可以使用FloodFill,O(N*M). 然后这里是矩阵,然后我们转换。
brute force:
枚举左上和右下两个点,然后判断是否全1,这样是 O(N*N*M*M)的算法,因为判断是否全1可以用sum数组来减一下,O(1)就够了。
(detail discussion: https://zhuanlan.zhihu.com/p/19873823?refer=qinchao)
http://poj.org/problem?id=3494
FloodFill
https://en.wikipedia.org/wiki/Flood_fill


blog:
Leetcode 269
C++ solution:
http://www.cnblogs.com/jcliBlogger/p/4758761.html

Discussion about the problem description:
https://leetcode.com/discuss/53997/the-description-is-wrong

C++ solution:

https://leetcode.com/discuss/54024/straightforward-c-solution?show=54024#q54024


Java solution to study:

https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/269.alien-dictionary.java

http://www.cnblogs.com/yrbbest/p/5023584.html

study C# code:
https://gist.github.com/jianminchen/07546625d828f63e762ba03b463fe8aa

Leetcode 329:
http://gaocegege.com/Blog/algorithm/leetcode329

http://blog.csdn.net/sbitswc/article/details/50707203

http://basics.sjtu.edu.cn/~xiaojuan/algo16/

June 20, C# practice:
https://gist.github.com/jianminchen/b984ccba8dabbb0bb78160c6e5c6e8b4

Top 10 Sales techniques for Entrepreneurs

June 11, 2016

 Learn to sell! Spend 1 - 2 hours to do some research on how to sell. Being a software programmer, how to sell the skills/ problem solving skills/ 45 minutes coding in a sprint.



https://www.youtube.com/watch?v=PwwgGOBw1oE

1. Motivation Speaker: Jordan Belfort,

https://en.wikipedia.org/wiki/Jordan_Belfort

2. Advice from Tim Ferriss
   https://en.wikipedia.org/wiki/Tim_Ferriss

   Practicing is only way to get better. Speaking ..., but that is the reason why written word is so powerful. Writing on a crispy paper and then can be reviewed. It is very difficult to do that for the speech. That is the reason I recommend to hold on skills on writing.

  Take time to do study ads, printout etc. Then go back to review, what he falls for, this, or that. What is pushed  you for the edge. And then, sell to people like you.

   Book to read outside business books:
   Recommendation 1:
   Sales -> go to "On Writing Well"
   On Writing Well  by: William Zinsser
   https://books.google.ca/books/about/On_Writing_Well.html?id=USd6AAAAIAAJ&redir_esc=y&hl=en

On Writing Well, which grew out of a course that William Zinsser taught at Yale, has been praised for its sound advice, its clarity, and for the warmth of its style. It is a book for anybody who wants to learn how to write or who needs to do some writing to get through the day, as almost everybody does. Whether you want to write about people or places, science and technology, business, sports, the arts, or about yourself in the increasingly popular memoir genre, On Writing Well offers you both fundamental principles as well as the insights of a distinguished practitioner. How to Write a Memoir tells you how to write the story of your life. Everyone has a story - whether you're a professional writer or just want to validate your personal and family reminiscences, William Zinsser explains how to do it, and do it well.

   Recommendation 2: 
  Bird by Bird   by: Anne Lamott

  Good at writing, improving communication - 
  https://books.google.ca/books/about/Bird_by_Bird.html?id=LISjPwAACAAJ&redir_esc=y

  This volume presents the author's offbeat wisdom about how to write. She recounts her personal experiences to reveal her writing techniques and how she overcomes obstacles that interfere with the writing flow. The author offers concrete suggestions about character, plot, setting, and other topics of interest to writers. She also offers irreverent advice about how to navigate through the dark underbelly feelings of self-doubt, inadequacy, and jealousy that are inevitable parts of any writer's experience. Her humorous advice is based on her own experience and honest self-analysis which provides writers the necessary perspective to keep writing through the difficult times that all writers encounter.

  Recommendation 3: 
  Ogilvy on Advertising   by: David Ogilvy
https://books.google.ca/books?id=FIguPyk2w6YC&q=ogilvy+on+advertising+book&dq=ogilvy+on+advertising+book&hl=en&sa=X&ved=0ahUKEwiXyOqo2aDNAhUMzGMKHSKoChgQ6AEIJDAA   
  An advertising authority updates his analysis of the elements of successful advertising and assesses the advertising environment that has emerged during the past twenty years

3. Gary Vaynerchuk
https://en.wikipedia.org/wiki/Gary_Vaynerchuk

4. Brian Tracy - Life long learning. Quality of thinking -

http://www.briantracy.com/
http://www.briantracy.com/blog/time-management/3-underrated-tips-to-achieve-work-life-balance/

http://www.briantracy.com/blog/category/sales-success/

5. Guy Kawasaki
https://en.wikipedia.org/wiki/Guy_Kawasaki

Follow him on twitter, and find this twitter and an article:
http://www.npr.org/sections/ed/2016/06/01/479335421/practice-makes-possible-what-we-learn-by-studying-amazing-kids

6. Eben Pagan
https://www.facebook.com/Eben-Pagan-135028473246104/

Package info to Ebooks to sell them.

Market them and sell them. Better to learn market and sales themselves.

Best sell method is to have a conversation with them, and try to fit in. Learn a new word today: Consultative sales

7. Mohnish Pabrai

https://en.wikipedia.org/wiki/Mohnish_Pabrai


8. Grant Cardone

https://en.wikipedia.org/wiki/Grant_Cardone

Author of book: Sell To Survive

9. Peter Sage

https://en.wikipedia.org/wiki/Grant_Cardone

10. Zig Ziglar
https://en.wikipedia.org/wiki/Zig_Ziglar

More to study:
Keith Ferrazzi
https://en.wikipedia.org/wiki/Keith_Ferrazzi

http://knowledge.wharton.upenn.edu/article/keith-ferrazzi-relationships-crucial-success/

People relationship:
Invite people in, be generous to the people around me. Universal currency.

Athlete has more than 1 coaches.
Relationship coach -
Professional currency -
3rd layer - some one cares about

Read the script of interview - write down main points:



Learn to lose - my favorite verse to study

June 11, 2016

Learn to lose, I like the teaching from sprinter, most marketable athelete - Usain Bolt.

Like the video, remind me over hundreds of hours on tennis court, play sports in order to get rid of waist bubble, excess body fat, build some muscle and also learn some sports - team spirit, mental toughness, and a lot of fun.

https://www.youtube.com/watch?v=QL5mCN-TTBs

Reading:
1. https://en.wikipedia.org/wiki/Usain_Bolt

2. http://www.runnersworld.co.uk/interview/im-still-here-and-im-still-the-best-rw-talks-to-usain-bolt/13333.html   (10 minute reading, excellent to know how athlete keeps working hard)

copy some sentences Julia likes to read:
I no longer think about what the fans want, or who is running what times and who I need to be on the lookout for. I just think about me, and doing my job. Legacy is the main word in my life now and that means if I’m five meters ahead with 10 to go I won’t be slowing down and beating my chest. I’ll be pushing to get the best time I can, every time.

Julia's comment: 

Sprinter is much hard compared to software coding in 45 minutes range or system design. Julia, you can do it. Learn to lose.  

Friday, June 10, 2016

C# Hashtable vs Dictionary

June 10, 2016

Spend 2 - 3 hours to look into this topic: C# Hashmap Hashtable vs Dictionary class

Reading always helps to think deeper, and expand the knowledge. Write down notes:




Plan to go over each function in Dictionary class in C#, understand them; get familiar with Dictionary class like SQL statement, slice and dice gets easy to use Dictionary class APIs. 

Code to study:
study the code, use Dictionary class, "Sherlock and anagram" - hackerRank, 
https://gist.github.com/jianminchen/ffcca0582b5f0d1d6a9b

Solution 2:
use Dictionary class, string key for anagram string, use getHashCode() call to turn key as Int.

https://gist.github.com/jianminchen/ffcca0582b5f0d1d6a9b

Read about getHashCode() webpage:
https://msdn.microsoft.com/en-us/library/system.object.gethashcode(v=vs.110).aspx

Solution 3:
https://gist.github.com/jianminchen/8f6bd4631f0b5f0bdee7


Solution 4.
use Dictionary class, sort the key string, then anagram strings will be the same.

https://gist.github.com/jianminchen/59e326cbd1d8910c01c7

30 minutes to practice: 
study the blog: Dictionary OrderByDescending
https://goo.gl/6ZbTPz
baby step to learn C# Dictionary class API - Order by and distinct
https://gist.github.com/jianminchen/eff03bea08a95061deb4185af74fea18



Review a few of terms:

1. generic type - 
2. boxing and unboxing - Hashtable stores Object, need boxing and unboxing

3. thread safe - all memebers vs. only public static memebers
4. speed concern - Dictionary is faster than Hashtable 


Actionable items:

1. Read all dictionary classes: 

  • ConcurrentDictionary - thread safe (can be safely accessed from several threads concurrently)
  • HybridDictionary - optimized performance (for few items and also for many items)
  • OrderedDictionary - values can be accessed via int index (by order in which items were added)
  • SortedDictionary - items automatically sorted
  • StringDictionary - strongly typed and optimized for strings

Motivation talk: 

1. Julia likes to use Dictionary class instead of Hashtable, since Dictionary uses explicit type checking to match its declaration, and it is in compile time. Much better than run time Hashtable box/ unbox - type conversion. 

2. Julia likes to use Dictionary class because it is easy to complete task like order by feature. She likes to find O(N) solution to sort, but in reality, O(nlogn) is fine, just call orderBy API. 


3. Read article extension method:
Extension Methods:
https://msdn.microsoft.com/en-CA/library/bb383977.aspx




Content marketing - ideas to write blogs

June 10, 2016

Spend 1 - 2 hours to do some research on content marketing. It takes some preparation to be able to write a good coding blog, the basic content marketing techniques are helpful.


Mark the ideas Julia likes:

16. Look through your analytics to see your top three blog posts, then write a follow up post for each one. (rank 8 of 10)

28. Create category pages on your website or blog that can make finding your content easier for your visitors. ( 7 out of 10)

32. Try using Quora to find questions people are asking in your niche or industry.

33. Compile Top 10 resource lists for your niche: Top 10 blogs; top 10 companies; top 10 tools, etc. ( 10 out of 10).


Some blogs:

user-focused content strategies that will stand the test of time, while winning approval from users as well as Google.

Julia's comment: 
   Learning takes time; share personal coding experience, and encourage others to work hard as well.





Tuesday, June 7, 2016

A small research on RestAPI, SOA, AWS, AZURE

June 7, 2016

Read the article:
https://www.linkedin.com/pulse/rest-vs-rpc-soa-showdown-joshua-hartman?trk=hp-feed-article-title-hpm

About complaints:
http://www.nytimes.com/2015/07/29/business/linkedin-notorious-for-sending-too-many-emails-cuts-back.html?_r=0

https://azure.microsoft.com/en-us/campaigns/azure-vs-aws/

Amazon AWS:
http://blog.hackerrank.com/how-amazon-web-services-surged-out-of-nowhere/

https://aws.amazon.com/resources/gartner-storage-mq-2014-learn-more/?tag=viglink121898-20

AWS provides durable, low cost cloud storage solutions for their backup, storages and achiving needs. (Pinterest, Dropbox, Adobe, ASANA, etc. )

Actionable items: plan to study 2 hours
Study Amazon Kinesis, most innovative service. Julia, can you name 3 services in AWS? 

https://aws.amazon.com/kinesis/streams/
https://aws.amazon.com/kinesis/streams/details/

Leveling up your JavaScript: - plan to spend at least 30 minutes to read
http://goo.gl/0mDASd

plan to read the article 30 minutes
http://www.cs.cmu.edu/~pavlo/courses/fall2013/static/papers/11730-atc13-bronson.pdf



Top 10 ranking algorithm and practice in June, 2016 (II)

June 7, 2016

Put together her favorite 10 algorithm and practice in the following:


1. HackerRank: Sherlock and anagram - 7 blogs with practices
Practice on HackerRank is like to play tennis sports, you have to experience various hitting partners, good workout!

No. 1.
http://juliachencoding.blogspot.ca/2016/03/hackerrank-string-sherlock-and-anagrams.html

No. 2
http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlock-and-anagrams-ii.html

No. 3

http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlocks-and-anagram-ii.html

No. 4 Study 6 solutions - Julia chose from over 200 solutions
http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlock-and-anagrams-iv.html

Julia, work on this code, and put test case in, write your own C# practice:
study the code, order by values,  not by key, try it!
https://gist.github.com/jianminchen/ffcca0582b5f0d1d6a9b

study the blog: Dictionary OrderByDescending
https://goo.gl/6ZbTPz
baby step to learn C# Dictionary class API - Order by and distinct
https://gist.github.com/jianminchen/eff03bea08a95061deb4185af74fea18

No. 6
http://juliachencoding.blogspot.ca/2016/03/hackerrank-sherlock-and-anagram-vii.html

Warm up 12 solutions - "Sherlock and anagram" one by one. Each one for a blog. Focus on speed, correctness.


Back to top 10 Ranking - top 2 ...
2. Leetcode 208 course schedule - warm up the algorithm, practice again in short future.
http://juliachencoding.blogspot.ca/2016/04/leetcode-208-course-schedule.html

3. HackerRank: Two strings - C# 15 solutions
http://juliachencoding.blogspot.ca/2016/03/hacker-rank-two-strings.html

4. Leetcode 312 - Burst Balloons -  Julia, please practice it using C# and post here later.

http://juliachencoding.blogspot.ca/2016/02/leetcode-312-burst-balloons.html


5. Binary Tree Post Order Traversal - Iterative solution
http://juliachencoding.blogspot.ca/2016/05/binary-tree-post-order-traversal.html

6. Leetcode 215: find kth largest element - Julia, please practice it using C# and post here later.
http://juliachencoding.blogspot.ca/2016/05/leetcode-215-find-kth-largest-element.html

Study the solution implemented in Java:
https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/215.kth-largest-element-in-an-array.java


7. Connect nodes at same level in binary tree - Julia, please practice it using C# and post here later.
http://juliachencoding.blogspot.ca/2016/05/connect-nodes-at-same-level-in-binary.html


8. Leetcode 15: 3 sum
http://juliachencoding.blogspot.ca/2016/05/leetcode-17-3-sum.html

9. Check number is power of 2
http://juliachencoding.blogspot.ca/2016/05/algorithm-check-if-number-is-power-of-2.html

10. Radix sort and practice:
http://juliachencoding.blogspot.ca/2016/05/radix-sort-distribution-sort.html

11. Leetcode: Maximum Gap
http://juliachencoding.blogspot.ca/2015/06/leetcode-distribution-sort-algorithm.html
http://juliachencoding.blogspot.ca/2015/06/leetcode-maximum-gap-no-164.html

 I know what it takes to win, first arrive, last to leave.

Sunday, June 5, 2016

Study on failing - a small research starts a learning Sunday

June 5, 2016

Julia thought about coding on this Sunday, and then, she decided to do some research first. The topic is called "study on failing".

1. Kevin O'Lery - Failing is Good
https://www.youtube.com/watch?v=1c6OoOHXz0k

1. Fail once, learn and move on
2. 36 months does not make money, then shoot it. It is not a business, it is a hobby.
3. Lose job - Mistakes
2. Kids in school, remove  grades system, allow to fail? Kevin: Fail in early age, learn quickly. Let them prepare early.
    Life is tough out there. Do not make life too easy for kids, let them learn.
3. Learn from Shark Tank TV show,
    ask about Marks for failure:

    Fall apart in talking about numbers.
 
4. Relationship failure - tell the truth.

2. Kevin O'Leary on how to get adhead in the workplace
https://www.youtube.com/watch?v=bG6L5z7fMxE

1. Complete job, and this is a must.
2. Great employee gets the job done; and do not make too much  noise.
3. Make money, not make friends.
4. Work alone vs work in team.
5. Dress for work you want?
    Code ethics - People do not remember what you wear yesterday, that is good.
6. Woman in leadership role?
    Kevin: focus, do not take huge risk; Canada is very open.

3. Kevin O'Leary tips on Negotiating
https://www.youtube.com/watch?v=0TUvuHRRLCA

1. Hesitate to negotiate: tell the truth, take the heat, do not lie.
2. Set goals to live with, have some flexibility
3. How to teach kids to negotiate?
Kevin: teach kids starting from 5 years old. Give them everything they want, you never teach kids anything about negotiate.

Remember a saying: you do not get your deserving, you get what you are negotiating.

4. Process of negotiating:
   3 quotes of changing cars, some one will tell the truth. Spend time to get 3 quotes.

5. Kevin O'Leary's Story
https://www.youtube.com/watch?v=mnCmmHs_XO8

Strict advice: put down guitar, pick up books.
Step father tried to help him out in his teenager.
Play music, take picture, doing nothing. But, step father does not like him do that.

A story, the owner asked him to take off a gum stick on the floor.

7.  ABC 20/20 says Kevin O'Leary is a Bosshole!
https://www.youtube.com/watch?v=Y-SDadRCUug

Respect the boss and trust from the employer.
Sell software billions, at the beginning from her mom's money $10,000 level.
Dad is not sharing his wealth. Only pay his children's education up to their need. Go figure out, go fix it.

8. Kevin O'Leary: Seteve Jobs was the "toughest bastard" ever
https://www.youtube.com/watch?v=eIYDUhLdF3I

Questions:
Respectable vs Fearful
Concept: Work with people never being friends.
Great sales people - a little of bit arts, science
Both are unhappy -> good deal
Fear vs greed
Stock trade -
Transparency of stock trade
Sales are born or made - great sales - Sales manager is different from sales people
Never invest in salesman to run sales -


9. Book:
Kevin O'Leary Book:
Cold hard truth on business money and life.
2 minutes video - the process to write the book, funny and so funny:
https://www.youtube.com/watch?v=u_-ppODHfSk

See if I can take down the words to a note correctly 80% in 20 minutes, again and again. English, vocabulary:
First try:
It is dark and contamin (?) night, the enemy is everywhere.
How to turn a few m
And also I
And also my softside
By my book, ..., a lot of books. Why? Because it is about money, cold hard truth.
mm. Beautiful

Second try:
It is a dk and strm nigt. compt everyhwer, tk out. Too soft.
Compt evh, probly kill them all.
writ bk -> a b dollar empire
Scratch . I am not doing that.
Where was I ? Buy book, a lot, mom, even your dog? Why? Money.
Eat that cold h truth.

Third try:
buddy, kitchen, heat
book worms

typing..
it is dk strmy nigt. compt looks evhe, take them out. Too soft?
Crush them, anngli them, ptu boiling water,
Few tho -> bill, soft side?
scrtach, tearning paper.
Where was I ?
Buy book, for evehwehre, for money, eat that for cold hard truth.

beautful at end with wine.

Fourth try: speed typing.
Buddy-> kitchen -> heat
book worms, with music
typing:
It is dk and stmy nt; Cpt evy, tkae them out -> too soft!
Crusht hem , ana, boiling wta, that is what i like.
Too may , also revealing soft side. a lot of per on flr
buy my bks, a lot of bks, cat even u dog. Why? money
Cold hard truth.

Here is the notes: 
So, it is the dark and stormy night, competitors are everywhere. Take them out. Too soft?
Crush them like croches, annihilate them, put boiling water, ..., kill them all.
Two thousand to a billionaire dollar empire.
Where was I ?
Buy my books, buy a lot of books, for ...

Cold hard truth.

The research just starts from "study on failing", and then, catch up more on outside world.

Video:
Eben Pagan's Top 10 Rules For Success
https://www.youtube.com/watch?v=IOjfqU-ngwM

Michael Gerber's Top 10 Rules For Success
https://www.youtube.com/watch?v=cjy0shpSh60



Thursday, June 2, 2016

Top 10 Ranking Algorithm problems - June 2016

June 2, 2016

 Julia likes to rank her favorite algorithms and also her practice, then she has to chance to dig into more and develop some skills through the practice.

 Here are top 10 practice she likes most:

1. LRU cache - Leetcode 146 - third practice:
http://juliachencoding.blogspot.ca/2016/06/leetcode-146-lru-cache-practice-makes_2.html

http://juliachencoding.blogspot.ca/2016/06/leetcode-146-lru-cache-practice-makes_45.html

 Practice a few more times.

2. Leetcode 126 - Word Ladder II (hard)  - fifth practice
http://juliachencoding.blogspot.ca/2016/05/leetcode-126-word-ladder-ii-using-bfs.html


3. HackerRank: String - Reverse Shuffle Merge (advanced) 5 practices
https://gist.github.com/jianminchen/7572e92ea48211d3d05c557d97601dbf

4. Serialize and Deserialize Tree - 2 study cases
http://juliachencoding.blogspot.ca/2016/05/leetcode-297-serialize-and-deserialize.html

5. Binary Tree Maximum Path sum - second practice
http://juliachencoding.blogspot.ca/2016/05/leetcode-124-binary-tree-maximum-path.html

6. Binary Tree Preorder Traversal - Iterative solution -
http://juliachencoding.blogspot.ca/2016/05/binary-tree-preorder-traversal.html

7. Leetcode 159 - longest substring with at most two distinct characters
http://juliachencoding.blogspot.ca/2016/05/leetcode-159-longest-substring-with-at.html

8. Leetcode 236 - Binary Tree Lowest Common Ancestor - Recursive, Backtracking 
First blog: (5 practices)
http://juliachencoding.blogspot.ca/2016/05/leetcode-236-lowest-common-ancestor.html
Second blog:
http://juliachencoding.blogspot.ca/2016/05/leetcode-236-lowest-common-ancestor_21.html

Third blog:
http://juliachencoding.blogspot.ca/2016/05/leetcode-236-lowest-common-ancestor_22.html

Fourth blog:
http://juliachencoding.blogspot.ca/2016/05/leetcode-236-binary-tree-lowest-common.html

9. Binary Tree Post Order Traversal - Iterative solution
http://juliachencoding.blogspot.ca/2016/05/binary-tree-post-order-traversal.html

10. Leetcode 17: Phone Number Combination
http://juliachencoding.blogspot.ca/2016/04/window-sum.html

There are so many algorithms to list here. But just keep 10 a time.

small talk on code interview

June 2, 2016

Still try to learn something about white board/ code interview.

Study articles, and then write down some notes:
1. https://blog.devmastery.com/how-to-win-the-coding-interview-71ae7102d685#.3ilg3h6vb

Whiteboard and Coding:
Look for a developer who can think on her feet, under pressure, in a room with others.

1. Verbalize your assumptions and seek to confirm them.
Think about assumptions you might be making, and ask me about them.

2. Think out loud.
Show your thought process.
Knowing that you understand how to reason about a problem is far more valuable to me than knowing that you've memorize the name of some built-in function.

Julia's comment:
Draw a diagram to prepare a test case for the problem, at least show some complexity of problem.
Like brute force discussion - how to solve them.

3. Don't be afraid to ask for help
It is very expensive to hire someone who refuses to ask for help when he is stuck?

If you are stuck or don't know something, ask me.

Julia's comment:
Julia has to learn how to communicate, learn a new word: Speak concise with some detail. Stop, and then ask if I answer your question. Do not speak more, showing no confidence. People will ask you more if you stop. Do not volunteer information, do not change topic.

4. Represent your skills and experience honestly

There is a threshold for questions and commentary.

Julia's comment: 
Always be humble. And open to learn.

Part 2 - Coding on a computer

1. Code to spec -

Ask good questions -

2. How well you can follow instructions.

3. Assume that this code will be put into a real production system and write accordingly.

    Your code should be commented.
    You should have error handling or at least logging.
    Your code show avoid breaking at all costs.
    You should have a test harness.
    Your code should be easy-to-read and self-explanatory. (clear variable names, good formatting, ideally "lint free" code).

   suggestions: check JavaScript, jQuery codebase on GitHub.

  "efficient" in production:
  Run fast/  Doesn't take up more memory than it needs to / is stable and easy to maintain.

Part 3: Algorithms
  Khan Academy - https://www.khanacademy.org/computing/computer-science/algorithms

Part 4 - Passing without solving the problem
1. Do not give up too easily.
Put in a real effort.

Julia's comment: Usually there are over 10 solutions working out for a problem. Julia saw hackerRank submissions, so many creative ideas out there.

2. Pseudo-code it.
Julia's comment: call your own function, write a few small functions to support your algorithm. Do not interrupt your main function, write small functions afterwards.

3. List your Know Unknowns

Part 5 - Practice, Practice, Practice

If you practice enough, and really work at it, you'll even be able to handle a question you've never seen before. You'll have confidence and you'll be able to relate it to something else you've probably tried. 


2. https://medium.com/@evnowandforever/f-you-i-quit-hiring-is-broken-bb8f3a48d324#.ydj3j7n2m

How the hashtable is implemented?
https://en.wikipedia.org/wiki/Hash_table

Questions in interview
1. Hash function, key -> index value in associated array
Load factor
Collision
Open addressing

2. Two sum
3. Palindrome





Leetcode 146: LRU Cache - a practice makes difference (III)

June 2, 2016

First two practices:

Warm up the algorithm: (a lot of hurdles, just read source code and then add a lot of comments)

The third practice:

Statistics:
Time spent: 3+ hours

Leetcode 146: LRU cache - a practice makes difference (II)

June 2, 2016


Previous blog:

Warm up the algorithm: (a lot of hurdles to go through)

Questions and answers:

How to design LRU? Data structure? What for?

LRU

One of the most common cache systems is LRU (least recently used). In fact, another common interview question is to discuss data structures and design of an LRU cache. Let’s start with this approach.
The way LRU cache works is quite simple. When the client requests resource A, it happens as follow:
  • If A exists in the cache, we just return immediately.
  • If not and the cache has extra storage slots, we fetch resource A and return to the client. In addition, insert A into the cache.
  • If the cache is full, we kick out the resource that is least recently used and replace it with resource A.
The strategy here is to maximum the chance that the requesting resource exists in the cache. So how can we implement a simple LRU?


LRU design

An LRU cache should support the operations: lookup, insert and delete. Apparently, in order to achieve fast lookup, we need to use hash. By the same token, if we want to make insert/delete fast, something like linked list should come to your mind. Since we need to locate the least recently used item efficiently, we need something in order like queue, stack or sorted array.
To combine all these analyses, we can use queue implemented by a doubly linked list to store all the resources. Also, a hash table with resource identifier as key and address of the corresponding queue node as value is needed.
Here’s how it works. when resource A is requested, we check the hash table to see if A exists in the cache. If exists, we can immediately locate the corresponding queue node and return the resource. If not, we’ll add A into the cache. If there are enough space, we just add a to the end of the queue and update the hash table. Otherwise, we need to delete the least recently used entry. To do that, we can easily remove the head of the queue and the corresponding entry from the hash table.


Eviction policy

When the cache is full, we need to remove existing items for new resources. In fact, deleting the least recently used item is just one of the most common approaches. So are there other ways to do that?
As mentioned above, The strategy is to maximum the chance that the requesting resource exists in the cache. I’ll briefly mention several approaches here:
  • Random Replacement (RR) – As the term suggests, we can just randomly delete an entry.
  • Least frequently used (LFU) – We keep the count of how frequent each item is requested and delete the one least frequently used.
  • W-TinyLFU – I’d also like to talk about this modern eviction policy. In a nutshell, the problem of LFU is that sometimes an item is only used frequently in the past, but LFU will still keep this item for a long while. W-TinyLFU solves this problem by calculating frequency within a time window. It also has various optimizations of storage.
Skip concurrency and distributed cache in this design. 
Next, talk about coding part - data structure and algorithm using her own words:

C# implementation. 

int capacity - specify the size of cache, cache should be with limited size, since resource is limited, specially for high speed access. source code on line 24.

int size - current size of cache - track current size of cache to determine  if eviction is needed or not.
source code on line 24.

Design a double linked list, so ListNode class is defined with two pointers, prev, next
source code from line 10 - line 22.

every entry has key, value. Use int to simplify the coding. Source code, line 12.
line 12   public int key, val; 

Also, we need to add two more variables: dummy head, dummy tail to help maintain the double linked list. source code on line 25.

Also, we need to be able to find the key in O(1) since it is in cache. Extra space is used, maintain a hash map using Dictionary class in C#:
line 27    Dictionary(int key, ListNode)

Let us count how many variables inside the class LRUCache:
6 variables:    - memorize the variable count - 6 - Try to recall. 

private int capacity, size; 
private ListNode dummyHead, dummyTail; 
private Dictionary<int, ListNode> map; 

ListNode class as a node in a double linked list: 
 public int key, value; 
 publie ListNode prev, next; 

4 variables. 

Statistics: 
Time spent: 2 hours +

Research paper:    feel so good to read a research paper after some coding 

Reading blog: (June 30, 2016)