Recent Interview Questions
- 2of 2 votes
AnswersGiven An Array with N integer with values ranging from 1 to N. there is only one duplicate in the Array.
- Geek December 09, 2012 in United States
Find out Duplicate value.
i.e.
A = { 10,6,3,4,7,5,2,4,9,1}
values from 1 to 10.
in this example, Duplicate element is 4.
N could be quite large.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
Answersfind if 2 strings are anagrams of each other
- Abhi April 15, 2011| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer String Manipulation - 0of 0 votes
AnswersGiven an array of +ve and -ve integers, re-arrange it so that u have +ves on one end and -ves on other,BUT RETAIN ORDER OF APPEARANCE..
- shilpa February 01, 2011
for eg,
1,7,-5,9,-12,15
ans=
-5,-12,1,7,9,15
do it in O(n) without using any extra space.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm - 1of 0 votes
AnswersPrint a binary tree in zig zag way... that is:
- bindas September 01, 2008
......a.........
....b....c.......
..d...e...f...g..
.h.i.j.k.l.m.n.o.
should be printed as a-c-b-d-e-f-g-o-n-m-l-k-j-i-h
what data structure will u use for that?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array of 0s and 1s, and k, Find the longest continuous streak of 1s after flipping k 0s to 1s.
- neer.1304 February 14, 2016 in United States
E.x array is {1,1,0,0,1,1,1,0,1,1}
k = 1 (which means we can flip ‘k’ one 0 to 1)
Answer: 6 (if we flip 0 at index 7, we get the longest continuous streak of 1s having length 6)| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 1 vote
AnswersGiven an array of "array range", return an optimized array by deleting subarrays.
- dark_knight October 19, 2015 in United States
NOTE: Array range (2,6) represents (2,3,4,5,6)
INPUT: [(2,6),(3,5),(7,21),(20,21)]
OUTPUT: [(2,6),(7,21)]
Reason: (3,5) is a subarray of (2,6) and (20,21) is a subarray of (7,21)| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm - 7of 7 votes
AnswersGiven an array of integers.
- Victor November 27, 2014 in United States
Move all non-zero elements to the left of all zero elements.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 1of 1 vote
AnswersWrite a program that gives count of common characters presented in an array of strings..(or array of character arrays)
- satya June 16, 2014 in United States
For eg.. for the following input strings..
aghkafgklt
dfghako
qwemnaarkf
The output should be 3. because the characters a, f and k are present in all 3 strings.
Note: The input strings contains only lower case alphabets| Report Duplicate | Flag | PURGE
Linkedin Algorithm - 1of 3 votes
AnswersYou are given a string which has numbers and letters. Numbers occupy all odd positions and letters even positions. You need to transform this string such that all letters move to front of array, and all numbers at the end.
- andy March 09, 2014 in United States for Google Search
The relative order of the letters and numbers needs to be preserved
I need to do this in O(n) time and O(1) space.
eg: a1b2c3d4 -> abcd1234 , x3y4z6 -> xyz346
Please don't submit your answers if it is not fulfilling the time-space complexity requirements.| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersImagine we have a large string like this "ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD" which contains multiple palindromes within it, like ABCBA, RACECAR, ARA, IAMAI etc... Now write a method which will accept this large string and return the largest palindrome from this string. If there are two palindromes which are of same size, it would be sufficient to just return any one of them.
- Jeanclaude January 22, 2014 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test String Manipulation - -1of 1 vote
Answersif apple is for 40 cents, banana is for 60 cents and grapefruit is for 80 cents then what pear is for???
- thinker August 20, 2012 in India| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Brain Teasers - 0of 0 votes
AnswersGiven a list of 'N' coins, their values being in an array A[], return the minimum number of coins required to sum to 'S'
- Aman August 15, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a String - aaaabbbbcc, convert the given string in to a4b4c2 without using extra memory. ( Note that every character appears more than once in input string and the repeated characters are contiguous)
- Mike February 12, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersConvert in O(n) time:
- Anonymous January 10, 2010
a1a2a3a4.....aNb1b2b3b4.....bN
to
a1b2a2b2a3b3a4b4..........aNbN| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Algorithm - 0of 0 votes
Answersarray1 :4,1,6,2,8,9,5,3,2,9,8,4,6
- t2 November 23, 2009
array2 :6,1,2,9,8
second array contains elements which are in first array in consequetive locations but may be in any order.Find their starting and ending indexes in array1 most efficiently.
(Be careful of duplicate numbers).| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 0of 0 votes
AnswersGiven an array of integers where every int has exactly one duplicate except one,
- other January 30, 2006
find the number with odd occuring number.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers - 0of 0 votes
AnswersGiven an array of words (i.e. ["ABCW", "BAZ", "FOO", "BAR", "XTFN", "ABCDEF"]), find the max value of length(s) * length(t), where s and t are words from the array. The catch here is that the two words cannot share any characters.
- supatroopa December 13, 2015 in United States
Assume that there are many words in the array (N words) and average length of word is M.
Answer for the example above is "ABCW" and "XTFN" as the result is 4 * 4 = 12.
"ABCW" and "ABCDEF" do not work since they share similar characters.| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersSimplify the implementation below as much as you can.
- noam.nta April 12, 2015 in United States
Even better if you can also improve performance as part of the simplification!
FYI: This code is over 35 lines and over 300 tokens, but it can be written in
5 lines and in less than 60 tokens.
קוד: בחר הכל
static int func(String s, char a, char b)
{
if (s.isEmpty()) return -1;
char[] strArray = string.toCharArray();
int i=0;
int aIndex=0;
int bIndex=0;
while (aIndex=0 && bIndex==0 && i<strArray.length)
{
if (strArray[i] == a)
aIndex=i;
if (strArray[i] == b)
bIndex=i;
i++;
}
if (aIndex != 0)
{
if (bIndex == 0)
return aIndex;
else
return Math.min(a, b);
}
else
{
if (bIndex != 0)
return bIndex;
else
return -1;
}
}| Report Duplicate | Flag | PURGE
Google Developer Program Engineer - 5of 5 votes
AnswersGiven three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|, |b-c| and |c-a| are minimum
- Greg September 04, 2014 in United States
Please provide as efficient code as you can.
Can you better than this ???| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C++ Coding - 0of 0 votes
AnswersQuestion was on Arithmetic progression
- careeradmirer October 27, 2013 in United States
Example :
Given the AP :- 1 3 7 9 11 13 find the missing value "which would be 5 here".
Conditions :
Get an user for the length of AP sequence and make sure user provides length is above 3.
Get the input in a single line ex:- "1 3 5 7 9 11"
Provide the solution in O(n) or less if you can.| Report Duplicate | Flag | PURGE
Facebook Algorithm - 0of 0 votes
AnswersThere are n points on a 2D plan, find the k points that are closest to origin ( x=0, y=0)
- k October 17, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Web Developer Algorithm - 1of 1 vote
Answers
- BVarghese July 26, 2013 in United StatesSearch for an element in a matrix. Rows and columns of the matrix are sorted in ascending order. eg. matrix [1 14 25 35] [2 16 28 38] [5 20 28 40] [16 22 38 41] search for 38. The interviewer was looking for a solution better than O(n+m). He didn't want a solution which starts searching from the left bottom and go to right or above according to the key value to search. That solution has O(n+m) worst complexity, where n is row count and m is column count.
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven you an array of 100 Elements with one number missing, how will you find the missing number?
- radibioinfo July 25, 2013 in United States
Array 1 to 100 with 55 missing.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - 2of 2 votes
AnswersWrite a function which compress string AAACCCBBD to A3C3B2D
- kishore February 18, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - 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 - 0of 0 votes
AnswersGiven a linked list that contains 0,1 and 2 . Sort this linked such that it contains 0s first, then 1s and then 2s in O(n) time. Remember its a linked list not an array.
- Nascent September 12, 2012 in India| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersIn given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c1,c2,c3,...cn] Write a program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn].
- masoom May 13, 2012 in India
PS: Do it without using extra memory
Sample Testcases:
Input #00:
{1,2,3,4,5,6,7,8,9,10,11,12}
Output #00:
{1,5,9,2,6,10,3,7,11,4,8,12}
Explanation:
Here as you can notice, the array is of the form
{a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 1of 1 vote
AnswersFind the substring of length 3 which is present in the reverse order from the string.
- swethas17 November 22, 2011 in United States
Ex: if the string is abcdcba (cba is the reverse of abc) so we should return cba.
And was asked to improve upon the complexity.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer String Manipulation