0% found this document useful (0 votes)
39 views3 pages

Zoho Practice Set 7

The document contains problems involving rotated sorted arrays, partitioning multisets into equal sums, counting matrix paths, finding words in matrices, and printing matrices in a clockwise spiral. Solutions are to be implemented as functions.

Uploaded by

subashbosss2000
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)
39 views3 pages

Zoho Practice Set 7

The document contains problems involving rotated sorted arrays, partitioning multisets into equal sums, counting matrix paths, finding words in matrices, and printing matrices in a clockwise spiral. Solutions are to be implemented as functions.

Uploaded by

subashbosss2000
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/ 3

1.

An sorted array of integers was rotated an unknown number of


times.

Given such an array, find the index of the element in the array in
faster than linear time. If the element doesn't exist in the array,
return null.

For example, given the array [13, 18, 25, 2, 8, 10] and the element
8, return 4 (the index of 8 in the array).

You can assume all the integers in the array are unique.

2.

Given a multiset of integers, return whether it can be partitioned into


two subsets whose sums are the same.

For example, given the multiset {15, 5, 20, 10, 35, 15,
10}, it would return true, since we can split it up into {15, 5, 10,
15, 10} and {20, 35}, which both add up to 55.

Given the multiset {15, 5, 20, 10, 35}, it would return false,
since we can't split it up into two subsets that add up to the same
sum

3.There is an N by M matrix of zeroes. Given N and M, write a


function to count the number of ways of starting at the top-left
corner and getting to the bottom-right corner. You can only move
right or down.

For example, given a 2 by 2 matrix, you should return 2, since there


are two ways to get to the bottom-right:

• Right, then down


• Down, then right
Given a 5 by 5 matrix, there are 70 ways to get to the bottom-right.
4.Given a 2D matrix of characters and a target word, write a
function that returns whether the word can be found in the matrix by
going left-to-right, or up-to-down.

For example, given the following matrix:

[['F', 'A', 'C', 'I'],

['O', 'B', 'Q', 'P'],

['A', 'N', 'O', 'B'],

['M', 'A', 'S', 'S']]

and the target word 'FOAM', you should return true, since it's the
leftmost column. Similarly, given the target word 'MASS', you should
return true, since it's the last row.

5.

Given a N by M matrix of numbers, print out the matrix in a


clockwise spiral.

For example, given the following matrix:

[[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]]
You should print out the following:

1
2
3
4
5
10
15
20
19
18
17
16
11
6
7
8
9
14
13
12

You might also like