Arrays Interview Questions
- 2of 2 votes
AnswersLength is given as input.Print all possible permutations of numbers between 0-9.
- bhavanisankara March 17, 2013 in United States
Eg: if input length=4
all possible combinations can be 0123, 1234, 5678,9864,...etc all combinations of length from in all numbers between 0-9| Report Duplicate | Flag | PURGE
Epic Systems Arrays - 0of 0 votes
AnswersWhich one is faster and why?
- audi March 15, 2013 in United States
1. Array
2. Link List.
If we just want to iterate in for loop and print it.| Report Duplicate | Flag | PURGE
Qualcomm Arrays Linked Lists - 2of 2 votes
AnswersArrange 1 to N in random order with no duplication.
- codomania March 07, 2013 in United States for Windows Phone| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 1of 1 vote
AnswersSuppose we have r lists with integers from 1 to n. The sum of the lengths of the lists is n. The lists can be different lengths and the same integer may appear in more than one list. Sort all the lists in O(n) time.
- anonuser March 06, 2013 in United States| Report Duplicate | Flag | PURGE
Algorithm Arrays - 0of 2 votes
Answersgiven a string in form of an array find an expanded string
- krish March 04, 2013 in India
e.g. A2B3C4 => AABBBCCCC
also, size of given array is exactly same as expanded string. so return the same array with expanded string.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 3of 3 votes
AnswersWrite a function to sum up two polynomials. Design the data structure for polynomial.
- styx.han February 25, 2013 in United States| Report Duplicate | Flag | PURGE
Arrays - 0of 0 votes
AnswersGiven an array sort all the elements in even positions in ascending order and odd positions in descending order
- bcsandy.1982 February 17, 2013 in India for Kindle| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
AnswersGiven an array elements, Find the maximum number which can be formed by the array elements
- bcsandy.1982 February 17, 2013 in India for Kindle
Eg input – a[ ] = {9,6,8,1]
Output - 9861| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 2 votes
AnswersGiven an infinite sequence of integers which are repeated many times. WAP to print "beep" if an integer appears ODDth time else print "no beep".
- learner February 10, 2013 in United States
example: input: a[] = { 1,4,2,4,3,2,4}
output: beep, beep, beep, no beep, beep, no beep, beep
Space complexity - O(1)| Report Duplicate | Flag | PURGE
Microsoft Intern Arrays - 1of 1 vote
AnswersYou are given an unsorted integer array of size N. This array contains integer from range 0 - N (not necessarily distinct and same integer can appear multiple time in an array).
- Rajat January 30, 2013 in India
You need to find pair of all the elements in array which sum up to N.
First i gave a solution using an extra array of size N to keep count of each integer in original array and was able to give solution in O(n) Time complexity and O(n) space complexity.
Then interviewer asked me to decrease space complexity, for which i gave solution as sorting the given array (in nlogn time) and then find the pairs in O(n) time, and hence total time complexity was O(nlogn) and space complexity as O(1).
But interviewer kept pressing for a better time complexity (than O(nlogn)) with O(1) space complexity.
How is it possible, i could not think of any way.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm Arrays - 1of 1 vote
AnswersGiven a 2D array of chars and a raw list of valid words.
1) Find all the valid words from the array. From each element in the array, you can traverse up, down, right or left.
Eg,g o d b o d y t a m o p r n u i r u s m p
valid words from the above 2D array -> god, goat, godbody, amour,....
- hari January 28, 2013 in India
2) Also, find a suitable DS to store the raw words list.
I used a recursive approach to solve the problem in exponential time. Can't think of any better approach.| Report Duplicate | Flag | PURGE
Amazon Algorithm Amazon Arrays - 0of 0 votes
AnswersGiven a two dimensional matrix of booleans, there is a function that returns the number of "true regions".
A region is a group of True values aligned vertically or horizontally.T T <= 1 region T F T F <= 2 regions F T
Question 1: How would you test a function that solve this problem, but is written by another developer. How many tests cases do you see?
- hnrqbaggio January 24, 2013 in United States for Office
Question 2: Now write the code to solve this problem. What are the time and space complexities?| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm Arrays Data Structures Debugging Microsoft Testing - 1of 1 vote
AnswersGiven two arrays of ints that are sets, create a function to merge them to create a new set.
- hnrqbaggio January 24, 2013 in United States for Office
A set must pass on these three conditions:
- All values are positive
- Sorted
- Non-duplicates| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm Arrays Data Structures Debugging Microsoft - 0of 0 votes
AnswersTell me if a array of integers is a set.
- hnrqbaggio January 24, 2013 in United States for Office
A set must pass on these three conditions:
- All values are positive
- Sorted
- Non-duplicates
After the first solution, I was asked about time and space complexity and to create 5 test cases for my function.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm Arrays Data Structures Debugging Microsoft - 0of 0 votes
AnswersWe are given a matrix of MxN elements with each element either being 0 or 1.Find the shortest path between a given source cell to a destination cell.
- beginner99 January 22, 2013 in India
An element value of 0 means we cannot create a path out of that cell| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Amazon Arrays Matrix - 0of 0 votes
AnswersAn array of size N is given. Array is sub divided into sub array of size K. Find maximum value of each sub array.
- Crazy Tesla January 20, 2013 in India
My ans-
While traversing the array keep on adding values to max heap of size K and keeping a virtual window of size K on array.
When element leaves the window then remove the leaving element from heap too and reheapify the heap. And max element of that window will be again on top in heap.
Any better approach?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays - 0of 0 votes
AnswersGiven two arrays of integer, print out the values from first array which are not present in second array. Time complexity should be O(n)
- ravigupt January 19, 2013 in India| Report Duplicate | Flag | PURGE
United HealthGroup Java Developer Arrays - 0of 0 votes
AnswersGive a min and max of an integer array, write a function to randomly return a number inside of this range, but not in the list. Also write a class that contains this function.
- cqyanbo January 05, 2013 in United States for Google New York City| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Arrays - 0of 0 votes
Answersgiven an array of size n, it holds distinct integers from 1 to n. Give an algorithm to sort the array? one way is to just assign a[i]=i in the array. how to sort the array using the elements of the array and not just assigning directly
- isha January 03, 2013 in United States| Report Duplicate | Flag | PURGE
Arrays - 0of 0 votes
AnswersArrayList A, B, C are sorted int arraylists.
- hboy December 29, 2012 in United States
When A[i] + B[j] = C[k], you need to remove C[k] from ArrayList C.
Please implement code with O(N^2). Note that you are not allowed to use additional data structures such as arrays, hash tables, etc.| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer Arrays - 0of 2 votes
AnswersA log file which has user details(user ID,timestamp) and pages visited in a particular day by that user.The next day -the same kind of log file gets generated.How do you find the probability of users who logged in consecutive days out of the second day - logged in users? The question is simple,but they look for the efficient data structure and time complexity.
- sriramMS December 20, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Application / UI Design Arrays Assembly Automata Behavioral Bit Manipulation Brain Teasers C C# C++ Cache Coding Data Mining Data Structures - 1of 1 vote
AnswersGiven two arrays of integers, unsorted. Write a program to find the common elements within the two.
- bhosale.praful November 13, 2012 in United States for Eikon| Report Duplicate | Flag | PURGE
Thomson Reuters Software Engineer / Developer Arrays - 0of 0 votes
AnswersProblem Statement :
- kumar.prince6 November 11, 2012 in India
• Given an 4n X 4n Matrix, where n is a positive integer taken as input. Imagine the matrix consisting of two interleaved coils whose centers are at the centre of the matrix. Implement a java program which takes an integer (n) as input and prints the two coils in two seperate lines.
Please have a look at the below examples to get a sense of what the two coils are :
• Example 1:
• Input: 1
• Matrix:
01 02 03 04
05 06 07 08
09 10 11 12
13 14 15 16
• Output the Two Coils as:
- Coil1: 10 06 02 03 04 08 12 16
- Coil2: 07 11 15 14 13 09 05 01
• Example 2:
• Input: 2
• Matrix:
01 02 03 04 05 06 07 08
09 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
• Output the Two Coils as:
- Coil1: 36 28 20 21 22 30 38 46 54 63 52 51 50 42 34 26 18 10 02 03 04 05 06 07 08 16 24 32 40 48 56 64
- Coil2: 29 37 45 44 43 35 27 19 11 12 13 14 15 23 31 39 47 55 63 62 61 60 59 58 57 49 41 33 25 17 09 01| Report Duplicate | Flag | PURGE
Yahoo Developer Program Engineer Arrays - 0of 0 votes
AnswersGiven two arrays, A and B, both containing integers, find values that appear in both arrays and output them.
I knew the fastest answer to this, which is basically adding array A to a hashmap and then checking if that map contains each element of B, which is an O(n) operation, but uses memory in O(n) as well. The interviewer then asked if I could figure a way of doing this with a complexity of O(n) without using any extra memory, basically just O(1) for memory.
Is this possible? I could not think of a simple quick solution for this on the fly, but I imagine it is possible.
Here is the code I wrote during the interview.import java.util.*; public class ArrayFun { public static void main(String[] args) { int[] a = {1,2,3,4}; int[] b = {2,5,6,7,3,2}; ArrayList<Integer> matches = ArrayFun.findMatches(a,b); for (int i = 0;i<matches.size();++i) { System.out.println(matches.get(i)); } } public static ArrayList<Integer> findMatches(int[] a, int[] b) { HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); ArrayList<Integer> matches = new ArrayList<Integer>(); for (int i = 0;i<a.length;++i) { map.put(a[i],0); } for (int i = 0;i<b.length;++i) { if (map.get(b[i]) != null && map.get(b[i]) == 0) { map.put(b[i],1); matches.add(b[i]); } } return matches; } }
Also, another quick question, is it typical for a phone interviewer to only ask you one question? I think it would be kind of difficult to ask more than one technical question, including coding, in such a short amount of time, i.e. < 1 hour
- M.Zimmerman6 November 08, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 1of 1 vote
AnswersWe have n number of sorted array for fixed length.
- Harsh123 November 04, 2012 in India for Kindle
Now we have to merge these and need to save finaly result array into given array.
Note- we can't use extra space except the given array.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays Data Structures Sorting - 0of 0 votes
Answers3)array contains only 0 and 1's need to sort the array such that all zeros at first and 1's later part of the array
- suryaoe November 04, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
AnswersFor an array of n integers and a number k between 2 and n, give an algorithm to determine if there are k elements that sum to zero. What are the time and space complexity?
- Vikas October 29, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 0of 0 votes
AnswersGiven an array of numbers (integers) find all pythogorean triplets (a^2 + b^2 = c^2). print a,b an c and the indexes.
- Ankit October 29, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays - 1of 1 vote
AnswersGiven an array containing sequence of bits (0 or 1), you have to sort this array in the ascending order i.e. all 0' in first part of array followed by all 1's. The constraints is that you can swap only the adjacent elements in the array. Find the minimum number of swaps required to sort the given input array.
- Ankit October 29, 2012 in India
Example: Given the array (0,0,1,0,1,0,1,1) the minimum number of swaps is 3.
Note: You just need to complete the function given below for this task. The function is given a binary string as input and returns the required answer.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Arrays Data Structures Sorting