## Arrays Interview Questions

- 4of 4 votes

AnswersGiven an array of integers and a number. WAP to find the pairs which sum of upto given number.

- Nitin Gupta May 15, 2015 in India for Cloud & Enterprise team

I solved it. Then he asked about writing test cases for this function.

I wrote below test cases

1.) All the elements should be number.

2.) Length of array should not be 0.

3.) Array itself should not be null.

4.) Given number, arrayLength can be represented by 32bits or 64 bits.

5.) number should not be negative.

6.) Input does not has pair, It should return false

7.) Input has pair, It should return true

8.) Input has all negative values and pair exists, then function should return true

9.) Input has all negative values and pair does not exists, function should return false

He told that he is looking for more test cases. Can you guys think of some more complex test cases.| Report Duplicate | Flag | PURGE

Microsoft SDE-2 Algorithm Arrays C++ Data Structures - 0of 0 votes

AnswersIn a Formula-1 challenge, there are n teams numbered 1 to n. Each team has a car and a driver. Car’s specification are as follows:

- Nitin Gupta May 06, 2015 in India

– Top speed: (150 + 10 * i) km per hour

– Acceleration: (2 * i) meter per second square.

– Handling factor (hf) = 0.8

– Nitro : Increases the speed to double or top speed, whichever is less. Can be used only once.

Here i is the team number.

The cars line up for the race. The start line for (i + 1)th car is 200 * i meters behind the ith car.

All of them start at the same time and try to attain their top speed. A re-assessment of the positions is done every 2 seconds(So even if the car has crossed the finish line in between, you’ll get to know after 2 seconds). During this assessment, each driver checks if there is any car within 10 meters of his car, his speed reduces to: hf * (speed at that moment). Also, if the driver notices that he is the last one on the race, he uses ‘nitro’.

Taking the number of teams and length of track as the input, Calculate the final speeds and the corresponding completion times.| Report Duplicate | Flag | PURGE

Google SDE1 Algorithm Arrays Data Structures Java Object Oriented Design - 0of 0 votes

AnswersThis was a question asked to my cousin in a recent phone interview with Cisco.

- Jeanclaude April 25, 2015 in United States

You're given an array of integers (unsorted) and the length is really large (perhaps a million integers). Now you are required to write an efficient code to retrieve topN integers. If N is 10, return the top 10 integers from the array. You result may or may not be sorted, that's your call. For e.g. if given array is arr = { 2, 1, 20, 3, 6, 5, 4, 8, 11, 12 }; and given N value is 3, then your result should be either {20, 11, 12} (unsorted) or {11,12, 20} (sorted).| Report Duplicate | Flag | PURGE

Cisco Systems Development Support Engineer Arrays - 0of 0 votes

Answersgiven an array with elements check if just by exchanging two elements of the array we get a sorted array.

- sandeep.nie April 22, 2015 in United States

time restriction:

O(NlogN)

space restriction: 2N| Report Duplicate | Flag | PURGE

Amazon Software Developer Arrays - 0of 0 votes

AnswersFind the longest running positive sequence in an array -

- coderhacker April 15, 2015 in United States

Eg - [1,2,-3,2,3,4,-6,1,2,3,4,5,-8,5,6]

It should return 5, with start index : 8| Report Duplicate | Flag | PURGE

Amazon Quality Assurance Engineer Arrays - 0of 0 votes

AnswersI have an two arrays int[] 1 = {2,5,8,9}; and int[] 2={6,3,4,7,1};

- navishsahu April 03, 2015 in India for 5

I need to merge this two array in third array int[] 3 = new int[1.Length + 2.Length]; and give the output in sorted form.

Also I need to provide and optimized code with minimal complexity...

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

Plz Help...| Report Duplicate | Flag | PURGE

xyz Applications Developer Arrays - 0of 0 votes

AnswersA mechanical engineer is writing a design specification for two gears to transmit motion between two parts, A and B, in a machine she is designing.

- nik.cse2005 March 13, 2015 in United States

the distance between A and B is equal to D.

There are n types of gears, Agear type of i has a radius Rj and cost Cj.

The two gears specified, i and j , must have Ri+Rj >= D, inorder for there to be a way of placing them so that they touch and work togeather. The objective is

to find the pair which costs the least.

You need to produce a design table that gives the most suitable match for every gear type in the list. For every gear type 'i', you need to consider its description (Ri,Ci)

and list the gear type 'j' to pair with 'i' in table position T[i]. The best map might be the same type(Ti=i). if there are multiple solutions with the same cost,

choose the gear with the largest radius.If both the cost and radius you need are found in more than one gear type, choose the type with the smallest index j.

If no radius can be found that allow the distance D to be covered, table should contain 0.

Input

n D

R1 R2 ... Rn

C1 C2 ... Cn

Output

T1 T2 ... Tn| Report Duplicate | Flag | PURGE

Myntra SDE-2 Arrays - 0of 0 votes

AnswersYou 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.

- alregith March 03, 2015 in United States| Report Duplicate | Flag | PURGE

Epic Systems Software Engineer / Developer Arrays - 2of 2 votes

AnswersYou 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.

- reddygokul.i7 February 27, 2015 in India| Report Duplicate | Flag | PURGE

Intern Algorithm Arrays Java Python - 2of 2 votes

AnswersConsider 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.

- eng.ahmed.moustafa February 23, 2015 in United States

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

Hint: It is not 6 x 52| Report Duplicate | Flag | PURGE

Google Software Engineer Arrays - 3of 3 votes

AnswersFind a given element in sorted array.

- tazo February 10, 2015 in United States

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]| Report Duplicate | Flag | PURGE

Linkedin Software Engineer / Developer Arrays - 0of 0 votes

AnswersGiven 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.

- xyz_coder February 06, 2015 in United States| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm Arrays Coding - 0of 0 votes

AnswersCompletely blew it on this question today.

- jsdude January 28, 2015 in United States

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).| Report Duplicate | Flag | PURGE

Facebook Software Engineer Arrays - 0of 0 votes

AnswersImplement 2 stacks in a single array

- helphand2015 January 22, 2015 in India| Report Duplicate | Flag | PURGE

McAfee SDET Arrays - 1of 1 vote

AnswersGiven two sorted arrays, mergesort them into 2nd array that has enough space to accommodate both.

- JSDUDE January 21, 2015 in United States| Report Duplicate | Flag | PURGE

Clean Power Research Software Engineer / Developer Algorithm Arrays - 0of 0 votes

AnswerGiven two sorted arrays, merge sort in the 2nd array that has enough space to accommodate both

- JSDUDE January 21, 2015 in United States| Report Duplicate | Flag | PURGE

Clean Power Research Software Engineer / Developer Algorithm Arrays - -5of 5 votes

AnswersHaving A List of int [1,1,1,3,1,2,1,1,4,1]

- NullVoid December 31, 2014 in India for ERP

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

Note: Need not to change value of 3,2,4| Report Duplicate | Flag | PURGE

N/A Software Engineer / Developer Arrays Java Linked Lists - 1of 1 vote

AnswersWrite 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..

- Jai December 12, 2014 in United States

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.| Report Duplicate | Flag | PURGE

SDE-2 Arrays - 0of 0 votes

AnswersGiven 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.

- hacker123 December 07, 2014 in India| Report Duplicate | Flag | PURGE

Amazon SDE-2 Arrays - 0of 0 votes

AnswersGiven an array A and an array B. Sort all the elements of A in the order of B. Sort the remaining elements.

- Guest December 05, 2014 in India

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}| Report Duplicate | Flag | PURGE

Monotype Senior Software Development Engineer Arrays - 2of 2 votes

AnswersGiven a large array of unsigned ints, quickly find two who's sum is 10

- JSDUDE November 22, 2014 in United States for Software Developer, Infrastructure Planning, Analysis and Optimization

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)| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm Arrays - 0of 0 votes

AnswersA 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))

- gopi.komanduri October 30, 2014 in India| Report Duplicate | Flag | PURGE

ADP Analyst Algorithm Arrays C# Data Structures Trees and Graphs - 0of 0 votes

AnswersGiven 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]

- JSDUDE October 27, 2014 in United States`public class Range { private int begin; private int end; public int begin { get; set; } public int end { get; set; } }`

| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Arrays - 1of 1 vote

AnswersJava: 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.

- davelee71047 October 24, 2014 in United States| Report Duplicate | Flag | PURGE

Microsoft Software Engineer Intern Arrays - 0of 0 votes

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

- kirann October 16, 2014 in India

Output :{1,4,6 ,9,7, 5, 2}| Report Duplicate | Flag | PURGE

Java Developer Arrays - 3of 5 votes

AnswersYou'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.

- omair.ahmed08 October 09, 2014 in United States

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)| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm Arrays Data Structures - 0of 0 votes

Answersfind 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}

- hydabckumar October 04, 2014 in India| Report Duplicate | Flag | PURGE

makemytrip Senior Software Development Engineer Arrays - 0of 0 votes

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

- determinedgal89 October 01, 2014 in United States| Report Duplicate | Flag | PURGE

Microsoft Software Engineer / Developer Arrays - 3of 3 votes

AnswersSuppose that each row of an n x n array A consists of 1's and D's such that, in any

- inevitablekris September 21, 2014 in United States

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.| Report Duplicate | Flag | PURGE

Arrays - 0of 0 votes

AnswersGiven an array and a number, find two integers that sums to the given number.

- alregith September 20, 2014 in United States for Marketplace Team| Report Duplicate | Flag | PURGE

Amazon SDE1 Arrays

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

Open Chat in New Window