Recent Interview Questions
- 2of 2 votes
Answershow would you merge two sorted arrays provided not to use a third array nor u can allocate extra space. try to optimize the problem to the best. time complexity should be less than O(n^2)
- not a looser January 19, 2009| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Software Engineer in Test Arrays - 2of 2 votes
AnswersFind the longest sequence of prefix shared by all the words in a string.
- employee11 July 15, 2014 in Israel
"abcdef abcdxxx abcdabcdef abcyy" => "abc"| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou have two numbers decomposed in binary representation, write a function that sums them and returns the result.
- getmax0 December 16, 2013 in United States
Input: 100011, 100100
Output: 1000111| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersYou are given a 2D array of characters and a character pattern. WAP to find if pattern is present in 2D array. Pattern can be in any way (all 8 neighbors to be considered) but you can’t use same character twice while matching. Return 1 if match is found, 0 if not.
- NaiveCoder March 21, 2012 in India
eg :
Matrix
{'A','C','P','R','C'},
{'X','S','O','P','C'},
{'V','O','V','N','I'},
{'W','G','F','M','N'},
{'Q','A','T','I','T'}
And pattern is microsoft.
It's funny when google looks for pattern of microsoft ;)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 2of 2 votes
AnswersGiven a document and a query of K words, how do u find the smallest window that covers all the words at least once in that document? (given you know the inverted lists of all K words, that is, for each word, you have a list of all its occurrrences). This one is really hard. Could someone propose an algorithm in O(n)?
- Anonymous November 11, 2009| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven an array contains positive and negative values, find the subarray, whose sum is most closed to zero. Require nlogn time complexity.
- wolfyink September 06, 2012 in United States| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 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 - 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 - 2of 2 votes
AnswersGiven an array of integers . Write an algorithm to find all the Pythagorean triples.
- Raj August 31, 2013 in India
Eg : i/p : int arr[ ] = {1,3,4,5,6,7,8,10,11}
o/p: Print 3,4,5 and 6,8,10| Report Duplicate | Flag | PURGE
Amazon - 2of 2 votes
AnswersSay there is a string hllsacefgdbdfdfdffd
- tarun.aggarwaltarun March 17, 2012 in India
You need to find the biggest string that has all consecutive characters
Conditions
consecutive string might have jungled words i.e acb is also continous or bcad is also continuous| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm - 2of 2 votes
AnswersA multiset or a bag is a collection of elements that can be repeated. Contrast with a set, where elements cannot be repeated.
- ersegun August 20, 2015 in Netherlands
Multisets can be intersected just like sets can be intersected.
Input :
A = [0,1,1,2,2,5]
B = [0,1,2,2,2,6]
Output :
A ∩ B = C = [0,1,2,2]
Input :
A = [0,1,1]
B = [0,1,2,3,4,5,6]
Output
A ∩ B = C = [0,1]
Write a function to find the intersection of two integer arrays in that way ?| Report Duplicate | Flag | PURGE
Booking.com Software Developer String Manipulation - 2of 2 votes
AnswersFind the unique number that is present only once in array while all the others are present three times.
- Rahul Sharma November 03, 2014 in India
Example: 2,3,5,1,2,2,5,3,5,3
Answer : 1 as 2,3,5 are repeated three times
Complexity should be better than O(nlogn)| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Algorithm - 2of 2 votes
AnswersGenerate MAX_INT (Max signed int value) using bitwise operators. Should work in 32 and 64 bit processors
- bartcois January 28, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersThe stepping number:
- Anon October 13, 2014 in United States
A number is called as a stepping number if the adjacent digits are having a difference of 1. For eg. 8,343,545 are stepping numbers. While 890, 098 are not. The difference between a ‘9’ and ‘0’ should not be considered as 1.
Given start number(s) and an end number(e) your function should list out all the stepping numbers in the range including both the numbers s & e.| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm Data Structures Dynamic Programming Java Online Test - 2of 2 votes
Answers// cat, actor -> T // car, actor -> F bool anaStrStr (string needle, string haystack) { }
Write a function that takes 2 strings , search returns true if any anagram of string1(needle) is present in string2(haystack)
- juny February 19, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
Answerswe have given a char array like “a1b2c3″ we have to convert this array to array like this “abbccc” .This has to be done in place as we have given that array has just enough space to hold the expanded array.
- nishu9101 February 20, 2013 in India
example:
1)input: a1b1c1
output:abc
length of array will be shortened.
2)input: a2b2c2
output:aabbcc
length of array will be equal to given array.
3)input: a3b4
output:aaabbbb
length of array will be greater than given array.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven some resources in the form of linked list you have to canceled out all the resources whose sum up to 0(Zero) and return the remaining list.
- ganesh.eng2015 July 24, 2016 in India
E.g-->> 6 -6 8 4 -12 9 8 -8
the above example lists which gets canceled :
6 -6
8 4 -12
8 -8
o/p : 9
case 3 : 4 6 -10 8 9 10 -19 10 -18 20 25
O/P : 20 25| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 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
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 - 2of 2 votes
Answersyou have given 2n+1 numbers in which 2n numbers are repeated means every number is having duplicate value.find that non repeating number in constant space and o(n) time.i told him using XOR.
- time February 03, 2012 in India
then he gave me 2n+2 numbers in which 2n numbers are repeating like above now you have 2 different number.find both number in constant space and o(n) time.(f2f 4th round)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven a string s contains lowercase alphabet, find the length of the Longest common Prefix of all substrings in O(n)
- Prateek Agrawal December 02, 2018 in United States
For example
s = 'ababac'
Then substrings are as follow:
1: s(1, 6) = ababac
2: s(2, 6) = babac
3: s(3, 6) = abac
4: s(4, 6) = bac
5: s(5, 6) = ac
6: s(6, 6) = c
Now, The lengths of LCP of all substrings are as follow
1: len(LCP(s(1, 6), s)) = 6
2: len(LCP(s(2, 6), s)) = 0
3: len(LCP(s(3, 6), s)) = 3
4: len(LCP(s(4, 6), s)) = 0
5: len(LCP(s(5, 6), s)) = 1
6: len(LCP(s(6, 6), s)) = 0
String contains only lowercase alphabates.| Report Duplicate | Flag | PURGE
Google SDE1 Data Structures - 2of 2 votes
AnswersGiven an array of integers greater than zero, find if it is possible to split it in two (without reordering the elements), such that the sum of the two resulting arrays is the same. Print the resulting arrays.
- eo March 21, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Production Engineer Coding - 2of 2 votes
AnswersGiven a sorted array with only 0's and 1's.Count the number of 0's.
- steelrahul June 16, 2015 in India for Hyderabad
e.g: 0 0 0 0 1 1
Ans: 4.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
Answers0 1 ?
- .netDecoder May 08, 2015 in United States
? wildcard for 0 or 1
"01?"
010 011
Example:
01?0?
Will produce
01000
01100
01001
01101| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
Answersint sum = 0;
- nirupam.astro January 04, 2014 in India
for (int i = 0; i < m; i++)
for (int j = i + 1; j < n; j++)
for (int k = j + 1; k < l; k++)
sum++;
what will be the value of sum?| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersSort an array which only has 0's and 1's. Do not use count sort.
- CodeNameEagle May 10, 2013 in India| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm Arrays - 2of 2 votes
AnswersGiven a binary tree, print its perimeter:
- JSDUDE May 04, 2013 in United States
node, left->most nodes from top to bottom, leaf nodes from left-> right, right->most nodes from bottom to top
----------------------------1
-----------------------2--------3
------------------4-----5-----6--------7
-------------8------9-----10------11-----12
should print:
1-2-4-8-9-5-10-11-12-7-3
5 because it doesn't have any children. 10 and 11 are children of 6 and 8 & 9 are children of 4.
Apologies for the messy diagram.| Report Duplicate | Flag | PURGE
Microsoft SDE1 Trees and Graphs - 2of 2 votes
Answersfind consecutive integers in a list that give you the biggest sum
- J@sper February 09, 2016 in United States
Like for -2 5 -1 7 -3 it would be 5 -1 7| Report Duplicate | Flag | PURGE
Google Java - 2of 2 votes
AnswersGiven an bunch of airline tickets with [from, to], for example [MUC, LHR], [CDG, MUC], [SFO, SJC], [LHR, SFO], please reconstruct the itinerary in order,
- blah_blah May 18, 2015 in United States
for example: [ CDG, MUC, LHR, SFO, SJC ].
//tickets can be represented as nodes| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm