## Arrays Interview Questions

- 0of 0 votes
You are given an N*N matrix. The matrix contains characters. Write a program to find a word in the matrix.The word can be found in either the rows or columns or the diagonals. The program should return true if the word is found and false if the word is not found.

- 1of 1 vote
You have a function rand5(). This function returns numbers between 1 and 5 randomly with equal probability. Implement a function rand7() which makes use of rand5 to return a number between 1 and 7 randomly with equal probability.

- 1of 1 vote
Consider the 52 cards of a deck. You generated a random sequence for these cards and want to send that sequence to a receiver. You want to minimize the communication between you and the receiver, i.e., minimize the number of bits required to send the sequence.

What is the minimum number of bits required to send the sequence?

Hint: It is not 6 x 52

- 1of 1 vote
Find a given element in sorted array.

arr= [1, 2, 3, 4, 5, 6]

follow up: If the sorted array is shifted left by unknown number, modify existing binary search to find a element in modified array

arr = [4, 5, 6, 1, 2, 3]

- 0of 0 votes
Given a number A, find the smallest number which has only 1s and 0s as its digits which divisible by the number A. For example: if the given number A is 4, the smallest number with 1s and 0s is which is divisible by 4 is 100.

- 0of 0 votes
Completely blew it on this question today.

1.) Given an array, find the maximum difference between two array elements given the second element comes after the first.

For example.

array = [1,2,3,4,5,6,7]

We can take the difference between 2 and 1 (2-1), but not the different between 1 and 2 (1-2).

This question is super easy, I solved it within minutes of getting of the phone. I came up with an O(n^2) solution over the phone. My improved solution was O(n).

- 0of 0 votes
Implement 2 stacks in a single array

- 1of 1 vote
Given two sorted arrays, mergesort them into 2nd array that has enough space to accommodate both.

- 0of 0 votes
Given two sorted arrays, merge sort in the 2nd array that has enough space to accommodate both

- -2of 2 votes
Having A List of int [1,1,1,3,1,2,1,1,4,1]

Output needed [1,5,6,3,7,2,8,9,4,10]

Note: Need not to change value of 3,2,4

- 1of 1 vote
Write code/ logic to count number of words in a string delimited by " ". Anything apart form " " are ignore for the counting. String could be very big as big as 5 GB of data. So add logic to handle such large strings..

ex: aaa b c ddd e = Count (5)

aaaaaaaaaaa = Count(1)

a

b

c

d

Count(1) as there are no spaces rather carriage returns are found.

PS: In case above question is not clear do let me know.

- 0of 0 votes
Given a array of positive integers, you have to find the smallest positive integer that can not be formed from the sum of numbers from array.

- 0of 0 votes
Given an array A and an array B. Sort all the elements of A in the order of B. Sort the remaining elements.

e.g.

A = {4,2,7,6,8,9,1,3,2,5,6}

B = {6,3,4,1}

Output= {6,6,3,4,1,2,3,5,7,8,9}

- 2of 2 votes
Given a large array of unsigned ints, quickly find two who's sum is 10

Then the interviewer asked me to write test cases.

Followed by how to implement this on a distributed system, where multiple systems can read/write simultaneously on a shared cache (HINT: It is ok if you do not return the first instance)

- 0of 0 votes
A parent array P is given where P[i] denotes the parent of the ith node in the tree(the tree is generic). Parent of root is indicated with -1. I need to find the height/depth of tree. (Best sol in O(n))

- 0of 0 votes
Given a sorted array with some sequenced numbers and some non-sequenced numbers. Write an algorithm that takes this array as an input and returns a list of {start, end} of all consecutive numbers. Consecutive numbers have difference of 1 only.

E.g. of array:

[4, 5, 6, 7, 8, 9, 12, 15, 16, 17, 18, 20, 22, 23, 24, 27]`public class Range { private int begin; private int end; public int begin { get; set; } public int end { get; set; } }`

- 1of 1 vote
Java: You're given a very large array of char's. Write a method to remove duplicates in the array, in place. Optimize for space complexity, not time complexity.

- 0of 0 votes
Input : {7,4,2,5,1,9,6}

Output :{1,4,6 ,9,7, 5, 2}

- 3of 5 votes
You're given an array of integers(eg [3,4,7,1,2,9,8]) Find the index of values that satisfy A+B = C + D, where A,B,C & D are integers values in the array.

Eg: Given [3,4,7,1,2,9,8] array

The following

3+7 = 1+ 9 satisfies A+B=C+D

so print (0,2,3,5)

- 0of 0 votes
find out the subset of an array of continuous positive numbers from a larger array whose sum of of the elements is larger in comparision to other subset. eg: {1,2 5 -7, 2 5} .The two subarrays are {1,2,5} {2,5} and the ans is {1,2, 5} as its sum is larger than{2,5}

- 0of 0 votes
write a program to return min value from an unsorted array of integers. How many assignment operations happen within the loop?

- 3of 3 votes
Suppose that each row of an n x n array A consists of 1's and D's such that, in any

row i of A, all the 1's come before any D's in that row. Suppose further that the

number of 1's in row i is at least the number in row i+ 1, for i= 0, 1, ... .n - 2.

Assuming A is already in memory, describe a method running in O(n) time (not

O(n2) time) for counting the number of 1's in the array A.

- 0of 0 votes
Given an array and a number, find two integers that sums to the given number.

- 5of 5 votes
Given three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|, |b-c| and |c-a| are minimum

Please provide as efficient code as you can.

Can you better than this ???

- 0of 0 votes
Given an array of positive and negative numbers(no zeroes),i have to arrange them in such a way that the positive and negative numbers should be arranged consecutively.The number of positive and negative numbers may not be equal i.e. if there is no positive number(or negative) left,then all the remaining negative numbers(or positive) are appended to the end of the array.The order is important i.e.if input array is { 2,-1,-3,-7,-8,9,5,-5,-7},then the output array should be {2,-1,9,-3,5,-7,-8,-5,-7}.The code is done in O(n) without using another array.I came up with a solution in which i chose 0 as pivot element and separate the numbers (using quicksort) but in this case the order is not preserved.

- 0of 0 votes
Given a sorted array of 0’s and 1’s. Find out the no. of 0’s in it. Write recursive, iterative versions of the code.

- 0of 0 votes
Write a function that accepts an n-dimension array and prints its values--For array of any dimension.

What is the layout of multi-dimensional array in the memory?

- 0of 0 votes
What does an iterator in C++ point to in case of a vector vs. list. Where would it point to if the prior links are deleted in the list? In case of a vector if it points to a specific index, where would it point to if the prior indexes are deleted?

- 0of 0 votes
Design a system like friend's functionality in facebook. should have all features of facebook's friends functionality. like for each person , he can have any number of friends , he will get suggestions for new firends , showing common friends if we visits any other profile . algo should be scalable , robust .

- 0of 0 votes
Design a phone book such that fields are searchable with name , with number. Later enhanced teh question asking searchable with address as well.