X

# Arrays  Questions

View By:

Q1 Find the path in 2 Dimensional array which has the most 1

You have a m*n size 2 Dimensional Array filled with either 0 or 1. You have to figure out the path which contains the most 1 when starting from arr[0][0]. You can only traverse down or right.

For ex: If array has values

1 1 0 1 0 1 1 0 1 0 0 1

So here the path containing max 1 is arr[0][0], arr[0][1], arr[1][1], arr[1][2], arr[1][3] and arr[2][3]

Q2 Number of occurrences of a number in a sorted array.

Given a sorted array, find the number of occurrences of an element in the array. Give a O(logn) time solution.

Q3 Sort array of 3 distinct integers

Sort an array that contains multiple occurrences of 3 integers (1,2,3).

For example input: 121221123323

output: 111122222333

Q4 Rotate an array to the left or right by a given number.

Given an array, rotate it to the left or right by a given number of steps.

Q5 Find out non repeating numbers

Given an array having numbers from 1 to N in random order such that all numbers except two are repeating twice, find out the two numbers.

Q6 Copy sub-array within an array

Given an array, a start index, length and a dest index, copy the sub-array of given length from starting index to destination index.

Q7 Given a sorted, shifted array find the minimum element

Given a sorted, shifted array find the minimum element. For example in 34512 the minimum is 1, in 45123 the minimum is 1.

Q8 Find an element in a rotated sorted array.

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). How do you find an element in the rotated array efficiently

Q9 How to manipulate a matrix with 0s and 1s?

Given a NxN matrix with 0s and 1s. now whenever you encounter a 0 make the corresponding row and column elements 0. Flip 1 to 0 and 0 remains as they are.

Example

1 0 1 1 0

0 1 1 1 0

1 1 1 1 1

1 0 1 1 1

1 1 1 1 1

results in

0 0 0 0 0

0 0 0 0 0

0 0 1 1 0

0 0 0 0 0

0 0 1 1 0

Q10 Given sorted arrays of length n and 2n with n elements each, merge first array into second array

Given sorted arrays of length n and 2n with n elements each, merge first array into second array.