Загрузка страницы

GOOGLE CODING INTERVIEW QUESTION - CLIMBING STAIRS (LeetCode)

Climbing Stairs LeetCode coding solution. One of Google's most commonly asked interview questions according to LeetCode.

Coding Interviews Climbing Stairs (LeetCode) question and explanation.

This question is a commonly asked by the following companies: Google, Amazon, Goldman Sachs, Bloomberg, LinkedIn, Alibaba, Microsoft, and Walmart Labs.

Link to problem: https://leetcode.com/problems/climbing-stairs/description/

Problem description: 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?

Note: Given n will be a positive integer.

Example 1:
Input: 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

Example 2:
Input: 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step

Intuition behind solution: We are asked, how many ways there are to reach the nth step with the ability to climb either 1 or 2 stairs at a time. We can answer this question by first solving smaller subproblems like how many ways are there to reach the 3rd step, the 8th step, the nth step. By solving smaller subproblems of this large problem, we can create a solution to the original question. We start by realizing that there is 1 way to climb 0 steps (don't climb them). We then realize there is 1 way to climb 1 step (we climb 1 step. We can't climb two steps because we would miss our destination step). We can then iterate through the remaining subproblems, 2 through n and solve the ith subproblem by realizing that the number of ways to reach the ith step is the number of ways of reaching the i - 1 step plus the number of ways of reaching the i - 2 step (because those are the only two stairs we could have come from because we can only climb at most 2 steps). Once we have finished our loop, we have solved the number of ways to reach the nth step which is stored in dp[n]; therefore, we return dp[n].
My Desk Setup
Desk - https://bit.ly/3jfY195
Chair - https://amzn.to/2O9TM3r
Monitor - https://amzn.to/3rcSHGa
Webcam - https://amzn.to/2NUmwgi
Desktop - https://amzn.to/3tiySPL
Laptops - https://amzn.to/3aRoN3Z
iPad - https://amzn.to/2LlJzzJ
Keyboard - https://amzn.to/3jfbxdd
Mouse - https://amzn.to/36ElWtT
Wrist Rest - https://amzn.to/3trrHF4 (pls don't buy this)
Mouse Pad - https://amzn.to/2Myz2lt
Microphone - https://amzn.to/3atNyTA
Lamp - https://amzn.to/3jjfZYp
Headphones - https://amzn.to/3tvr0KU (new model)
Headphone Hook - https://amzn.to/3tr8uTC
Blue Light Glasses - https://amzn.to/3cDVUdK
Wireless Charger - https://amzn.to/39LY1uu
Keyboard cable - https://amzn.to/2O5p2R5
Mic arm - https://amzn.to/3cECZj8
Audio interface - https://amzn.to/36HdWIi
Cloudlifter - https://amzn.to/36VO6kf
Laptop dock - https://amzn.to/2O2DsBw
Motherboard - https://amzn.to/3rkiWuA
Solid state - https://amzn.to/3rk5vuo
CPU cooler - https://amzn.to/3tnwwPA
CableMod - https://amzn.to/3tqbtM8
CPU - https://amzn.to/3auG1ns
Power supply - https://amzn.to/3trsAxo
RAM - https://amzn.to/39JZcuf
Designing Data-Intensive Applications - https://amzn.to/2YK4ek1
Clean Code - https://amzn.to/3txqfB5
Meditations - https://amzn.to/3cDa4fi

Support me on Patreon: https://www.patreon.com/KevinNaughtonJr
Follow me on Twitter: https://twitter.com/KevinNaughtonJr
Follow me on Instagram: https://www.instagram.com/programeme
Follow me on GitHub: https://github.com/kdn251

Видео GOOGLE CODING INTERVIEW QUESTION - CLIMBING STAIRS (LeetCode) канала Kevin Naughton Jr.
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
11 октября 2018 г. 8:04:27
00:05:35
Яндекс.Метрика