0% found this document useful (0 votes)
28 views2 pages

Example 1: Input: 2 Output: 2 Explanation: There Are Two Ways To Climb To The Top

The document contains 4 questions about algorithms: 1) Finding the number of ways to climb a staircase by taking 1 or 2 steps at a time. 2) Finding the length of the longest common subsequence between two strings. 3) Finding the area of the largest rectangle under a histogram. 4) Counting the number of islands in a grid where 1's represent land and 0's represent water. Examples and sample inputs/outputs are provided for each problem.

Uploaded by

shubham jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Example 1: Input: 2 Output: 2 Explanation: There Are Two Ways To Climb To The Top

The document contains 4 questions about algorithms: 1) Finding the number of ways to climb a staircase by taking 1 or 2 steps at a time. 2) Finding the length of the longest common subsequence between two strings. 3) Finding the area of the largest rectangle under a histogram. 4) Counting the number of islands in a grid where 1's represent land and 0's represent water. Examples and sample inputs/outputs are provided for each problem.

Uploaded by

shubham jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1. You are climbing a staircase. 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

Q2. Given two sequences, find the length of the longest subsequence present in both of them.

Example

S1 = “AGGTAB”

S2 = “GXTXAYB”

GTAB is the longest subsequence.

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

You might also like