Recent Interview Questions
- 1of 1 vote
AnswersGiven 2 set of arrays of size N(sorted +ve integers ) find the median of the resultant array of size 2N.
- gdg July 25, 2014 in United States
(dont even think of sorting the two arrays in a third array , though u can sort them. Try something better than order NLogN| Report Duplicate | Flag | PURGE
Google - 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
Answersremove a character from the string which does not come simultaneously in c
- gaurav May 27, 2014 in United States
for example, given the string str1 = "120jdvj00ncdnv000ndnv0nvd0nvd0" and the character ch = '0', the output should be 12jdvj00ncdnv000ndnvnvdnvd. That is, the 0 is removed only wherever it occurs singly. this code is not working| Report Duplicate | Flag | PURGE
C - 2of 2 votes
AnswersWrite a function, for a given number, print out all possible way to make up that number eg: 2 - 1 1,2
- sLion May 25, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersHe asked me to print root to leaf path WITHOUT using recursion . I got stuck at it and used too much space according to him .
- !@# May 02, 2014 in India
I constructed a visited array , path array and a stack .
Is there any other optimal algorithm ?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 1of 1 vote
AnswersGiven a list of n sorted lists of numbers, write a method that returns one giant list of all the numbers in order.
- valheru April 23, 2014 in United States
Example input:
NSArray* input = @[
@[@2, @5, @10],
@[@25, @100, @105],
@[@7, @56, @42],
.......
];| Report Duplicate | Flag | PURGE
Facebook iOS Developer Sorting - -3of 11 votes
AnswersGiven an array of Integers, and a range (low, high), find all continuous subsequences in the array which have sum in the range. Is there a solution better than O(n^2)?
- Obiwana March 21, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - -2of 6 votes
AnswersGiven a dictionary of words, and a set of characters, judge if all the characters can form the words from the dictionary, without any characters left.
- DoZerg March 20, 2014 in United States
For example, given the dictionary {hello, world, is, my, first, program},
if the characters set is "iiifrssst", you should return 'true' because you can form {is, is, first} from the set;
if the character set is "eiifrsst", you should return 'false' because you cannot use all the characters from the set.
P.S. there may be tens of thousands of words in the dictionary, and the chars set length could be up to hundreds, so I really need some efficient algorithm.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a string, return the string with the words reversed
- Bryan.S.Lam February 26, 2014 in United States for Quality Engineer Intern
"I am good" -> "good am I"
List test cases and if you were crunched on time and only had time to test one test case, which would you pick| Report Duplicate | Flag | PURGE
Salesforce Intern Algorithm - -1of 3 votes
AnswersGiven a set of intervals, find the interval which has the maximum number of intersections (not the length of a particular intersection). So if input (1,6) (2,3) (4,11), (1,6) should be returned. Some suggest to use Interval Tree to get this done in O(logn), but I did not understand how to construct and use the Interval Tree after reading its wiki page. Is there any other way to do it? If Interval tree is the only option, please educate me how to construct/use one. Thanks.
- Guy February 23, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 2 votes
AnswersCheck if a given tree is a valid BST
- tbag October 26, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersYou have two arrays of integers, where the integers do not repeat and the two arrays have no common integers.
- Billy Jim October 05, 2013 in United States
Let x be any integer in the first array, y any integer in the second. Find min(Abs(x-y)). That is, find the smallest difference between any of the integers in the two arrays.
Assumptions: Assume both arrays are sorted in ascending order.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a string of text, group all the words such that anagrams are stored and returned together in groups.
- AVK September 22, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 3of 3 votes
AnswersI need to store countries, its states and cities in a data structure.
- krupaljpatel July 24, 2013 in United States for Risk
The following queries might be used to fetch details
1) find list of states for a country.
2) find list of cities for a state.
3) find the name of the country and state for a city.
eg:
1) India -> Gujarat, UP, MP
MP -> bhopal,indore
Gujarat-> Surat,Ahmedabad, Baroda
2) USA -> Texas, California.. and so on.
Which is the best data structure that can be used to store these details.| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Data Structures - 0of 0 votes
AnswersGiven an Array A[], find the maximum j - i such that A[j] > A[i].
- pirate July 20, 2013 in India
For example Input { 34,8,10,3,2,80,30,33,1} and Output 6 (j=7, i=1)
Time Complexity should be less then O(n^2)| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm - 2of 2 votes
AnswersIn an array of unsorted integers (you may assume the array may contain +ve, -ve and 0s), write a function
- Jeanclaude June 28, 2013 in United States
int returnNthMax(int[] arr, int n)
which will return the nth Max number. For e.g. if this is given array {2, -4, 5, 6, 0, 7, -1, 10, 9} and n=1, it should return the max number, 10 and if n=3, it should return 3rd max number, which is: 7.| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Arrays - 1of 5 votes
AnswersThis was the question of two buckets of 3 and 5 litres each. Now measure four litre. I had given 2 solutions but still he wanted 3 solution.
- Nikhil June 11, 2013 in United States for any
1st soln: fill 3 litre and then interchange in various ways to get 4 litre.
2nd soln: fill 5 litre and then interchange in various ways.
do you have any soln other than this.| Report Duplicate | Flag | PURGE
Samsung Developer Program Engineer Financial Software Developer Brain Teasers - 0of 4 votes
AnswersGiven a matrix consisting of nos you can print the max length of sequence possible where in a sequence each consecutive nos have a diff of +1 or -1.
- bharat June 06, 2013 in United States
Ex :
3 5 7 3
4 5 8 1
6 4 5 2
here sequence is
3
4 5
4 5| Report Duplicate | Flag | PURGE
Amazon SDE1 - -1of 1 vote
AnswersQ1. Given two arrays of size n1, n2, sum up the two arrays in such away that the resultant array is computed in the below way.
- pavankumar.thati May 30, 2013 in India
arr1 : {a1,a2,a3}
arr2 : {b1,b2,b3,b4}
resultant array : {a1+b1, a1+b2, a1+b3. a1+b4, a2+b1, a2+b2, a2+b3, a2+b4, a3+b1, a3+b2, a3+b3, a3+b4}
find the median of the resultant array in n1 + n2 time .| Report Duplicate | Flag | PURGE
Algorithm - 1of 1 vote
AnswersIn a party there are n different-flavored cakes of volume V1, V2, V3 ... Vn each. Need to divide them into K people present in the party such that
- ANONU April 14, 2013 in India
- Each member of party gets equal volume of cake (say V, which is the solution we are looking for)
- A given member should get a cake of single flavour only i.e. You cannot distribute parts of different flavored cakes to same member.
- Minimum volume of cake gets wasted after distribution so that means a maximum distribution policy| Report Duplicate | Flag | PURGE
Google SDE1 - 2of 2 votes
AnswersWrite a function that takes a string and returns true if the entire string is a palindrome, otherwise return false. The function should be case-insensitive and ignore any whitespace or punctuation.
- Barry Fruitman March 20, 2013 in United States
For example, return true for:
"A man, a plan, a canal: Panama."| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 5of 5 votes
AnswersGiven a hashmap M which is a mapping of characters to arrays of substitute characters, and an input string S, return an array of all possible mutations of S (where any character in S can be substituted with one of its substitutes in M, if it exists).
What is the time complexity? What is the space complexity? Can you optimize either?
- trunks7j February 15, 2013 in United StatesExample input: M = { f: [F, 4], b: [B, 8] } S = fab Expected output: [fab, Fab, 4ab, faB, FaB, 4aB, fa8, Fa8, 4a8]
| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersFind an ancestor of given two node from a tree in O(n) time. The tree is binary tree.
- Jeff February 14, 2013 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven N arrays with sizeof N, and they are all sorted, if it does not allow you to use extra space, how will find their common datas efficiently or with less time complexity?
- yingsun1228 February 04, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersFollowing is an interview question asked by 'Amazon' to me. I still haven't come up with a optimized solution.
- audi February 01, 2013 in United States
Problem Statement:
Given an unsorted array of integers n. Return 'true' if the addition of any integers from that array matches with the target value else return false.
Note:
1)'n' could be 1000 or 10,000.
2) Target value could be 'negative'
Test Condition:
i/p:- Array A[]= {-5,6,7,1,0,12,5,-6,100}
Target = 13
o/p:- TRUE
As, 6+7=13.
If we try to do it linearly or normally it will take O(2^n) time complexity.
So I am looking for any method or algorithm which will optimized this problem more.| Report Duplicate | Flag | PURGE
Amazon Algorithm - 5of 5 votes
AnswersYou have a link list with the following structure:
- francisco.gutierrez.91 January 24, 2013 in United States for Office
struct Node{ Node*next; Node*other; }
next pointer points to next node, but "other" pointer points to any node in the list, it can be itself or null.
you receive the header of a list with this structure.
you have to copy it(allocate new memory) , you cannot modify the structure, you can not modify the list you are given.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Linked Lists Algorithm Data Structures - -2of 2 votes
AnswersWrite a long running program in C. This program should not hog the CPU, use no sleep()/block()/select()/wait(), should not block resources...and should terminate after a very very very long time
- Ravi January 24, 2013 in United States for youtube| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer C - 0of 0 votes
AnswersGiven a Binary Tree (not BST) with integer values . 1) Find path from root to any node with max sum. 2) As there can be many path's find all of them. 3) Print all such paths.
- singhsourabh90 January 18, 2013 in India
Do this in O(n) : n is number of node's in tree. he wanted an O(n) solution not O(n)+O(n) ie. u can't traverse tree twice .| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answersgiven arr1 = {5,6,4,2,2} arr2={4,2,2,1}
- Minnu December 27, 2012 in United States
return common elements {4,2,2}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven a million points (x, y), give a O(n) solution to find 100 points closest to (0, 0).
- Illusion November 25, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Algorithm