## Arrays Interview Questions

- 0of 2 votes

AnswersHow to design a multi key hash map ( key count can be dynamic. if there are two keys , initiallly which can be used to find the value , keys can be increased to three as well ex: consider school structure. Intially , consider , student id is key , later , should be searchable even with key name , later with grade.

- gopi.komanduri July 05, 2014 in India| Report Duplicate | Flag | PURGE

Analyst Algorithm Arrays C# C++ Coding Data Structures Dynamic Programming Experience Hash Table Large Scale Computing Linked Lists Problem Solving Sorting Trees and Graphs - 1of 3 votes

AnswersDesign a telephone directory for large ppl (he gave example like design for India). fields will be , first name , last name , number . this should be searchable with first name , last name , number as welll.

- gopi.komanduri July 04, 2014 in India

later added more complexity like do the same for organisation where even it contains designations. so this should be searchable with designations.| Report Duplicate | Flag | PURGE

Analyst Algorithm Arrays C C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Dynamic Programming Hash Table Ideas Large Scale Computing Linked Lists Object Oriented Design Problem Solving Trees and Graphs - 2of 2 votes

Answers(Bar Raiser Round)

- gdg June 26, 2014 in United States

Divide the array(+ve and -ve numbers) into two parts such that the average of both the parts is equal.

Input:

[1 7 15 29 11 9]

Output:

[15 9 1 7 11 29]

Explanation:

The average of first two elements is (15+9)/2 = 12, average of remaining elements is (1+7 +11 +29)/4 = 12| Report Duplicate | Flag | PURGE

Amazon Arrays - -4of 6 votes

AnswersYou have an array of integers(size N), such that each integer is present an odd number of time, except 3 of them(which are present even number of times). Find the three numbers.

- gdg June 21, 2014 in United States for Bing

Only XOR based solution was permitted.

Time Complexity: O(N)

Space Complexity: O(1)

Sample Input:

{1,6,4,1,4,5,8,8,4,6,8,8,9,7,9,5,9}

Sample Output:

1 6 8| Report Duplicate | Flag | PURGE

Google Developer Program Engineer Arrays - 2of 2 votes

AnswersCode a function that receives an array with duplicates and returns a new array keeping the original order of the elements but with the duplicates removed.

For example, if the input were`@[ @"dog", @"cat", @"dog", @"fish" ]`

the output would be

`@[ @"dog", @"cat", @"fish" ]`

Tell the complexity of the solution.

- diegum June 06, 2014 in United States for iOS| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Arrays - 0of 0 votes

AnswersYou are given an array of N elements. Each element in the range Min of int to Max of Int. You need to find the length of longest sequence in this array such that difference of largest and smallest element of that sequence is 1. The sequence need not be sequential.

- northernlight May 06, 2014 in United Kingdom

For e.g. array[]={6,10,6,7,8,9,0}

seq {6,10} = diff is 4 len 2

seq { 10,7,8} diff is 3 len 3

seq { 7,8,9} diff 2 len 3

seq {6,6,7} diff is 1 len 3

In this example the program should return 3 .

Complexity N*longN| Report Duplicate | Flag | PURGE

Amazon Algorithm Arrays C C++ - 1of 1 vote

AnswersYou are given a matrix where some pixels are white and some are black. Basically there are different disjoint images in the matrix.

- hulk April 20, 2014 in India

a) Expand/Shrink the images

b) Count the no of images

c) Color the images

d) Rotate the images| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Arrays - 6of 6 votes

AnswersThe input is a sequence x1,x2,...,xn of integers in an arbitrary order, and another sequence

- Coder April 17, 2014 in United States

a1,a2,..,an of distinct integers from 1 to n (namely a1,a2,...,an is a permutation of

1, 2,..., n). Both sequences are given as arrays. Design an 0(n logn) algorithm to order

the first sequence according to the order imposed by the permutation. In other words, for

each i, Xi should appear in the position given in ai. For example, if x = 17, 5, 1,9, and a =

3, 2, 4, 1, then the outcome should be x = 9, 5, 17, 1. The algorithm should be in-place, so

you cannot use an additional array.| Report Duplicate | Flag | PURGE

Google Software Engineer / Developer Arrays - 2of 2 votes

Answersgive me the code for :

Given a string say "I am a human being" the output should reverse all letters of each word but not the whole string as such.

Eg: O/p should be "I ma a namuh gnieb"

I somewhat wrote the code, but i was asked what if there are extra spaces etc.

(i am able to write the code sitting at my desktop at one short but there front of interviewer i am struggling. Need to build up my confidence)

let me know the best and optimised way of writing this code.

Also i suggest people to aviod using inbuilt functions as much as possible

My Answer is as below in perl

- i_learn April 11, 2014 in India`#i want the reverse of the letters of all words in a string #eg Input is "I am a human being" then o/p shud be "I ma a namuh gnieb" $str="I am a human being"; @arr=split(' ',$str); print @arr; for($i=@arr-1;$i>=0;$i--) { $_=@arr[$i]; ####intead of above for loop if we use foreach(@arr) then it will reverse the whole string @word=split('',$_); { foreach $n (@word) { unshift(@final,$n); } } } print "\n @final \n";`

| Report Duplicate | Flag | PURGE

Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays Automata Coding Data Structures Dynamic Programming Perl - 0of 0 votes

Answersgive me a code to find all anagrams or combnations of a given work.

- i_learn April 11, 2014 in India

Say if the word given was "hello"

then

hel

he

hell

leho

lleho

and so on| Report Duplicate | Flag | PURGE

Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays test Testing - 0of 2 votes

AnswersGiven an array say [0,1,2,3,5,6,7,11,12,14,20]

- i_learn April 11, 2014 in India

given a number say 5.

Now find the sum of elements which sum to 5

eg:2+3=5, 0+5=5 etc.

I guess the interviewer wanted all possible combinations eg 0+2+3=5, etc| Report Duplicate | Flag | PURGE

Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays Coding Data Structures Dynamic Programming Perl Sorting test Testing - 0of 0 votes

AnswersArray of Integers with even number of same Integers. Find the Integer that is an odd number of times. Compare efficiency between different approaches.

- georgiosziazopoulos April 03, 2014 in Luxembourg| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Arrays - 0of 0 votes

AnswersGiven a couple of integer arrays A = {2, 4, 3, 5, 6, 8} & B = {9, 2, 7, 6} - Return the intersection of these arrays.

- Jeanclaude March 19, 2014 in United States

Once I provided a solution (which was n squared -O (n^2)) he followed up by asking me if I could make it linear (O(n)).| Report Duplicate | Flag | PURGE

Adobe Software Engineer / Developer Arrays - 0of 0 votes

AnswersGiven a larger integer buffer/array (say size, x), now given a window size (say, n) and a number (say, k). Windows starts from the 1st element and keeps shifting right by one element. The objective is to find the minimum k numbers present in each window.

- nemesis07 March 14, 2014 in India| Report Duplicate | Flag | PURGE

Amazon Arrays - -3of 3 votes

AnswersHaving trouble with this array pair difference problem (NOT array pair sum) because of a certain edge case.

Example is: k = 4 a = [ 1, 1, 5, 6, 9, 16, 27] output: 3 (Due to 2x [1, 5], and [5, 9])

So, find the difference that equals to k. I used this code in my interview but realized it was wrong hours later unfortunately. It only gives 2.`public static int arrayPairDifference(int[] a, int k) { HashMap<Integer, Integer> hashMap = new HashMap<>(); int count = 0; for (int i = 0; i < a.length; i++) { if (hashMap.containsValue(a[i] - k)) { count++; } hashMap.put(i, a[i]); } return count; }`

How to account for the edge case of the 2x [1, 5] ?

- Johnb March 12, 2014 in United States| Report Duplicate | Flag | PURGE

Algorithm Arrays Hash Table - 1of 1 vote

AnswersMove the first n numbers in a 10 element array to the end.

- FrickenHamster March 03, 2014 in United States for Lync

I think the way to do it was to reverse the array and then reverse the first 10-n and then the last n.| Report Duplicate | Flag | PURGE

Microsoft Software Engineer Intern Arrays - 2of 2 votes

AnswersYou are given an array with numbers - [11, 3, 11, 11, 3, 2, 0, -2, 2]

- KevinK February 27, 2014 in United States

You are supposed to write a function that returns the number that appears "odd" number of times.

The solution is obviously using HashMap. But that takes O(n) to create the HashMap and O(n) to lookup. How can one eliminate the second O(n) yet keeping the HashMap?

Hint: Do you really need to count frequency of occurrence of each digit?| Report Duplicate | Flag | PURGE

Amazon Principal Software Engineer Arrays - 1of 1 vote

AnswersGiven a number in an array form, Come up with an algorithm to push all the zeros to the end.

- kiranpm86 February 24, 2014 in India

Expectation : O(n) solution| Report Duplicate | Flag | PURGE

Amazon Quality Assurance Engineer Algorithm Arrays C++ Coding - -1of 1 vote

AnswersGive 2 arrays of size 7 and 3 which are sorted such that the last 3 blocks in first array are empty, merge the arrays in a sorted manner in the most efficient way.

- kiranpm86 February 24, 2014 in India

E.g:-

a[7] = [4, 10, 11, 20__, __, __]

b[3] = [1,3,7]| Report Duplicate | Flag | PURGE

Amazon Quality Assurance Engineer Algorithm Arrays C++ Coding - 0of 0 votes

Answerspublic interface InfluencerFinder {

- Anon February 19, 2014 in United States

/**

* Given a matrix of following between N LinkedIn users (with ids from 0 to N-1):

* followingMatrix[i][j] == true iff user i is following user j

* thus followingMatrix[i][j] doesn't imply followingMatrix[j][i].

* Let's also agree that followingMatrix[i][i] == false

*

* Influencer is a user who is:

* - followed by everyone else and

* - not following anyone himself

*

* This method should find an Influencer by a given matrix of following,

* or return -1 if there is no Influencer in this group.

*/

int getInfluencer(boolean[][] followingMatrix)| Report Duplicate | Flag | PURGE

Linkedin Software Engineer / Developer Arrays - 0of 0 votes

Answersif you are given 2 arrays

- chugh.rachita February 15, 2014 in India

one has n elements and another has n+2 elements

and the elements in the array are same except the 2 elements

find those two extra elements..

give the optimal solution.| Report Duplicate | Flag | PURGE

Intern Arrays - 0of 2 votes

AnswersGiven an array of n distinct integers sorted in ascending order. Find an index i s.t ar[i] = i. Return -1 if no such index exists. Note that integers in array can be negative.

- gdg February 02, 2014 in United States| Report Duplicate | Flag | PURGE

Arrays - 1of 1 vote

AnswersWrite a program for finding a minimum element in rotated sorted array(either ascending or descending ) and array contains duplicates.

- kesar February 02, 2014 in United States| Report Duplicate | Flag | PURGE

Algorithm Arrays C Sorting C# - 0of 0 votes

Answersgiven 2 Dimensional array

- xyz January 30, 2014 in United States

I/P -- String[][] input = { { "abc", "def", "gh" },

{ "f", "g" },

{ "qrt","xyz","pqr" } };

Program shd return a 2-D Array with

O/P -- { { "abcfqrt", "abcfxyz", "abcfpqr" ,abcgqrt and so on ..| Report Duplicate | Flag | PURGE

Google SDE-2 Arrays - 1of 1 vote

AnswersGiven a 3-D array, if any m[r][c][d] is <=0 mark all the cells in the entire row,col and depth as zero and return the o/p array

- juny January 22, 2014 in United States for Traffic| Report Duplicate | Flag | PURGE

Ebay SDE-2 Arrays - 0of 0 votes

Answers

- aryan January 17, 2014 in United States`suppose u r given a 4*3 rectangle like (take these values from user)Now u have to calculate the no. of squares in this rectangle like:No. of squares of dimension 1 is 12No. of squares of dimension 2 is 6No. of squares of dimension 3 is 2No. of squares of dimension 4 is 0Total no. of squares are 2`

| Report Duplicate | Flag | PURGE

Arrays - 0of 0 votes

Answerssuppose u r given a 4*3 rectangle like (take these values from user)Now u have to calculate the no. of squares in this rectangle like:No. of squares of dimension 1 is 12No. of squares of dimension 2 is 6No. of squares of dimension 3 is 2No. of squares of dimension 4 is 0Total no. of squares are 2

- aryan January 17, 2014 in United States| Report Duplicate | Flag | PURGE

Arrays - 1of 1 vote

Answers

- Srigopal Chitrapu January 15, 2014 in United States`In given array find zero and replace the entire row and column with zeros E.g Input: 1 2 3 4 5 6 7 8 9 10 0 11 12 13 14 15 Output: 1 2 0 4 5 6 0 8 0 0 0 0 12 13 0 15`

| Report Duplicate | Flag | PURGE

Microsoft SDE-2 Arrays Coding Matrix - 0of 0 votes

AnswersHow to find the adjacent elements of an single dimensional array whose difference is 1; What is the Time Complexity & Auxiliary Space you use ? What type of efficiency can be achieved?

- soul January 08, 2014 in India for Chennai| Report Duplicate | Flag | PURGE

Amazon Software Engineer in Test Arrays - 0of 0 votes

AnswersHow to sort an single dimensional array whose elements are {4,5,6,4,5,6}; What is the Time Complexity & Auxiliary Space you use ? What type of efficiency can be achieved?

- soul January 08, 2014 in India for Chennai| Report Duplicate | Flag | PURGE

Amazon Software Engineer in Test Arrays

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window