Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Hippo Video Assessment ​ (Round 1)

Ques1. Balanced Brackets


A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {)
occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type.

There are three types of matched pairs of brackets: [], {}, and ().

A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
For example, {[(])} is not balanced because the contents in between { and } are not balanced.
The pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of
parentheses encloses a single, unbalanced closing square bracket, ].

Given a string of brackets, determine whether each sequence of brackets is balanced. If a


string is balanced, print YES otherwise, print NO.

INPUT

[]{}()

OUTPUT

YES

Ques2. Connected Cell in a grid


Consider a matrix where each cell contains either a 0 or a 1 and any cell containing a 1 is
called a filled cell. Two cells are said to be connected if they are adjacent to each other
horizontally, vertically, or diagonally.

If one or more filled cells are also connected, they form a region. Note that each cell in a
region is connected to at least one other cell in the region but is not necessarily directly
connected to all the other cells in the region.

Given an n x m matrix, find and print the number of cells in the largest region in the matrix.

n - no of rows

m - no of columns
Sample Input:

1 1 0 0

0 1 1 0

0 0 1 0

1 0 0 0

Sample Output:

Ques3. Common Child

A string is said to be a child of another string if it can be formed by deleting 0 or more


characters from the other string. Given two strings of equal length, what's the longest string
that can be constructed such that it is a child of both?

For example, ABCD and ABDC have two children with maximum length 3, ABC and ABD.
They can be formed by eliminating either the D or C from both strings. Note that we will not
consider ABCD as a common child because we can't rearrange characters and ABCD is not
equal to ABDC

Sample Input:

HARRY

SALLY

Sample Output:

2
Ques4. Stock

You have been given stock prices for next N days. Find out the maximum profit that can be
obtained by buying and selling the stocks.

Conditions:

Stock must be sold any day after the buying date

You can buy and sell multiple times, but cannot hold more than 1 stock at a time.

You can only perform a single transaction on a day. i.e. can only either buy or sell on a single
day

For example:

Share price in thousands

5146784379

Max benefit:

1. Buy share on day 2 at the cost of 1

2. Sell share on day 6 when the price rises to 8

3. Buy a share again on day 8 at the cost of 3

4. Sell share on day 10 when the price rises to 9

Total: (8 - 1) + (9 - 3) = 13

INPUT

Number of days followed by an array of positive integers.

Sample:

10

5146784379

OUTPUT

13

You might also like