Example 1: Input: 2 Output: 2 Explanation: There Are Two Ways To Climb To The Top
Example 1: Input: 2 Output: 2 Explanation: There Are Two Ways To Climb To The Top
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Example 1:
Input: 2
Output: 2
1. 1 step + 1 step
2. 2 steps
Example 2:
Input: 3
Output: 3
2. 1 step + 2 steps
3. 2 steps + 1 step
Q2. Given two sequences, find the length of the longest subsequence present in both of them.
Example
S1 = “AGGTAB”
S2 = “GXTXAYB”
Q3. Given n non-negative integers representing the histogram's bar height where the width of each
bar is 1, find the area of largest rectangle in the histogram.
Example:
The largest rectangle is shown in the shaded area, which has area = 10 unit.
Input: [2, 1, 5, 6, 2, 3]
Output: 10
Q4.Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is
surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may
assume all four edges of the grid are all surrounded by water.
Example 1:
Input:
11110
11010
11000
00000
Output: 1
Example 2:
Input:
11000
11000
00100
00011
Output: 3