Showing posts sorted by relevance for query climbing stairs. Sort by date Show all posts
Showing posts sorted by relevance for query climbing stairs. Sort by date Show all posts

Tuesday, July 28, 2015

Leetcode Question No 70: climbing stairs

July 28, 2015

Problem statement:
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

The problem is most popular question in the algorithm, so I do like to spend time to find out all sorts of solution, and get myself comfortable to all kinds of ideas, and figure out which one is best, and all concerns we can have in the discussion of climbing stairs:

1. Recursion solution vs. DP problem solution (Dynamic Programming solution)
2. Time complexity solution: O(2^n) vs O(n) solution
3. The space O(N) vs O(1), in other words: array of N or 2 variable, and another tmp variable
4. The base case discussion: f(0) = 1 or f(0) =1, math question?
5. Math formula - closed form solution vs DP problem solution
6. Use Memoization DP vs. no memoization DP
7. Programming skills, how to make code easy to follow, more readable, more abstract. 

The investment of time on the problem is well done. Go over 16 implementation one by one using C# programming language. 

C# code:

其实, 我觉得题目越容易, 越值得投入时间去学习; 看看大家有没有不同的理解, 打开思路; 如果自己没有训练过这道题, 可能会紧张; 即使训练过, 但是, 有的想法, 可能自己从来没有思考过, 一时还不能判断好坏, 但是, 多看网上的博客, 向每一个人取取经. 谦虚, 才能有提高.

我编网站后台, C#程序自己写; 自己训练的题目太少; 这次选择用Leetcode来提高C#编程, 又可以提高算法和数据结构的知识, 网站后台靠平时训练.  

January 3, 2016
Review the leetcode question 70, climbing stairs. 
Read the blog:
http://blog.csdn.net/kenden23/article/details/17377869
http://yucoding.blogspot.ca/2012/12/leetcode-question-15-climbing-stairs.html

http://www.cnblogs.com/springfor/p/3886576.html

http://www.cnblogs.com/springfor/p/3886576.html

http://siddontang.gitbooks.io/leetcode-solution/content/dynamic_programming/climbing_stairs.html

https://github.com/zwxxx/LeetCode/blob/master/Climbing_Stairs.cpp



Saturday, July 28, 2018

weekend planning - easy dynamic programming algorithm

July 28, 2018

Introduction


It is my job to make life easy as a software programmer. So I like to do training in the weekend. One of great ideas is to train easy level algorithms first. I like to build up problems solved in quantity first.

I really enjoy the problem solving of dynamic programming.

Easy level dynamic programming algorithms


I like to list easy level dynamic programming algorithms and think about how to learn from those algorithms this weekend.

Problems solved: 303, 198, 121

879 N/AEasy
303 33.4%Easy
276 35.2%Easy
198 40.3%Easy
53 40.8%Easy
70 41.7%Easy
746 43.8%Easy
121 43.8%Easy
256 46.6%Easy

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


Sunday, October 30, 2016

HackerRank - WarmartLabs Codesprint (Algorithms) - Interesting Fibonacci Sum

Oct. 30, 2016

Introduction


Julia changed the practice to attend the contest, she chose to take some risk; aim most difficult algorithm, last of 6 algorithm - Hard level. Total score is 100, she knew about Fibonacci algorithm very well, dynamic programming, memorization, bottom up; she also spent over 2 hours to read the problem statement, try to work on the mathematics part of the algorithm.

Until 4:00am, she gave up. She thought about last hour, if she can make this algorithm work, then, she can score 120, rank will be 120/ 2600; She could get into top 10%.

Problem Statement


Summary of practices


Worked on the algorithm from 11:am - 4:00am, near 15 hours, score 0 out of 100.

Submission 17 times. First work on memory issue, remove out-of-memory issue; and then, worked on timeout issue, could not get rid of range sum query O(n2) issue, n is O(n5).

1. First submission:
Fibonacci sum - first submission - line 183 - line 196 function fibo - array declaration on line 187 - 109 * 4 bytes = 4000MB.

If there is no memory limit, timeout issue, the algorithm will work. Cannot scale, timeout 2 issues.

2. 8th submission, out-of-memory, should be less than 512MB; but it is over 4GB for an array

3. 9th submission

4. 10th submission

5. 17th submission

Until last hour of 15 hours, Julia read discussion. "Segment Tree" may be the idea to avoid O(n2), range sum query classical problem.

Encouraging notes for Julia


Julia likes to celebrate her 15 hour effort to work on a hard algorithm problem on HackerRank; focus on the hard algorithm, therefore, she can figure out later what she should put her training next. 

Instead of working on medium/ advanced level algorithm, Julia likes to solve first hard algorithm first. This is the first time she did in 24 hours contest, push herself to the limit, try to solve one hard algorithm. She does not have time to read 3 medium algorithms problem statement in the codesprint. 

3 kinds of people, do not know what is happening, one is to make thing happen. Julia chose the last one. One day, She can solve hard problem on HackerRank contest. Make things happen. Fail fast, fail quick. Just do it.


Previous blogs about Fibonacci algorithm


I solved the algorithm called climbing stairs


Julia, remember the phrase: The hard makes it great! Enjoy the journey.

Thursday, September 13, 2018

Leetcode discuss

Sept. 13, 2018

Introduction

The following content is the copy of my page on github. The link is here. 
It takes a village to raise a child.
I like to adapt the culture to learn and contribute to Leetcode discuss community. It is so easy to learn from so many ideas, but it takes me more than 3 years five months to understand that I also should learn to contribute to the community.
I like to see if I adopt the value "It takes a village to raise a child", as a programmer, I think that in order to get smart, I have to learn to contribute Leetcode discuss. Since I find that it is so easy to learn the algorithm on leetcode discuss, I like to be one of them to work hard and share the thoughts and hard work.
This page is dedicated to show my effort to provide a feature to review all my past practice, all my sharing on Leetcode discuss.
It is time for me to share my practice on Leetcode.com discussion panel.
I like to encourage myself to share my code on Leetcode discussion. I learn so many things from those people sharing on Leetcode discussion panel. I like to be one of them.
Leetcode discuss
I will share more practice later. I also will add those links I shared before.
Sept. 9, 2018
Leetcode.com does not provide product feature to look up discuss shared by a player. Google search result will only show at most 20 results of my discuss.
Google search: Leetcode leetcode jianmin.chen.39
Here is the link.
Sept. 13, 2018
I like to list all my sharings on Tree easy level algorithms, Array easy level algorithms, Math easy level algorithms.
Tree easy level algorithms (solved 30)

Hard level (solved 33)

239. Sliding Window Maximum
optimal solution using LinkedList
My own blogs

Saturday, August 22, 2015

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

Thursday, August 30, 2018

Leetcode 746: Min cost climbing stairs

August 30, 2018

Introduction


It is an easy level algorithm and I wrote a solution using dynamic programming.

My practice


I need to write a few sentences to summarize my approach and then share the code. Here is my sharing on Leetcode discuss.

Sunday, November 29, 2020

Happygirlzt: LeetCode入门(漫谈常见题型与解法)

 Here is the link. 

I will spend 30 minutes to watch the video Sunday morning. I will do that first thing in the morning. 


Arrays

  • Two pointers (sliding window)
  • Binary search ( sorted, search space)
  • Combined with Map 
  • Prefix sum ( DP )
  • Quick select (kth ...)

Stacks

   familiar with some monotonic stack questions

  • Maximum rectangle
  • Next greater elements
  • Trapping rain water - optimal, two pointers

   

   Next 

Queue  BFS

Graphs   BFS, DFS, Dijkstra's

Backtracking 

  • permutation - all possibilities
  • subsets
  • combination sum
  • partition equal
  • subset sum
  • N-Queen
  • Sudoku


Dynamic programming

  •  total ways
  • True/ False
  • max/ min

  • 0/1 Knapsack
  • perfect squares
  • Coin changes - total ways, minimum
  • climbing stairs 
  • decode ways
  • string related
    • regular expression matching
    • wildcard matching
    • Edit distance
    • LIS / LCS
  • 2D matrix
    • maximum square
    • range sum query
    • bomb enemy
    • unique paths, total ways
  • greedy  Heap (sort)  
    • Top K
    • Campus bikes
    • merge k sorted lists



Saturday, July 28, 2018

weekend planning - easy level array algorithm

July 28, 2018

Introduction


It is time for me to solve as many easy level algorithms as possible. So I can review my last two week practice and I will be so happy to know that I solve 50 algorithms in last two weeks, and also I work full time 80 hours last weeks.

It is not easy to move on next algorithm quickly. In order to do that, I have to train myself focus on analysis and coding. Cut emotional baggage for each algorithm, how I feel, what my concerns, I should learn quickly and move forward with another problem solving.

Easy level array algorithms


I like to list those algorithms here. I like to solve 10 easy level array algorithms this weekend. The number of easy level array algorithms is around 45 to 50.


665 19.9%Easy
189 26.3%Easy
414 28.2%Easy
532 28.4%Easy
581 29.4%Easy
605 30.0%Easy
88 32.8%Easy
219 33.3%Easy
840 34.3%Easy
624 35.8%Easy
26 37.3%Easy
643 37.8%Easy
849 38.1%Easy
1 38.6%Easy
724 39.2%Easy
119 39.3%Easy
66 39.9%Easy
35 40.0%Easy
747 40.4%Easy
53 40.8%Easy
118 41.3%Easy
27 41.5%Easy
674 42.7%Easy
746 43.8%Easy
121 43.8%Easy
628 44.8%Easy
268 45.7%Easy
830 46.7%Easy
661 46.8%Easy
697 47.0%Easy
167 47.4%Easy
217 48.1%Easy
122 48.6%Easy
169 49.0%Easy
717 49.0%Easy
448 51.3%Easy
283 52.1%Easy
695 52.2%Easy
485 53.8%Easy
243 54.2%Easy
566 57.7%Easy
766 58.2%Easy
561 66.8%Easy
867 66.8%Easy
832 69.2%Easy