Recent Interview Questions
- 2of 2 votes
AnswersWrite a code to test whether string s2 is obtained by rotating the string s1 by 2 places.
- Surekhag28 July 26, 2014 in India for Kindle
e.g S1="amazon" S2="azonam" return true
S1="quality" S2="lityqua" return false| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 2of 2 votes
AnswersGiven an array of values, design and code an algorithm that returns whether there are two duplicates within k indices of each other? k indices and within plus or minus l (value) of each other? Do all, even the latter, in O(n) running time and O(k) space.
- fbrubacher May 19, 2013 in United States for Engineer| Report Duplicate | Flag | PURGE
Palantir Technology Software Engineer / Developer Algorithm - 2of 2 votes
AnswersU have a number, don't know how long it is, do not know how many digits, don't know when number ends, do not know which is the last number. There is a function to increment the number by 1, but function can take only stream of digits and not the complete number e.g if you have 878999 as a number, you could input this number into the function only as single digit e.g 8,7,8,9,9,9. The output should be the whole number incremented by 1 i.e 879000, remember only single digits you can send to function as input. You can use any data structure, but need to tell why you are using that particular data structure. No need to worry about Time complexity.
- algoram November 29, 2012 in United States for Site Reliability Engineering Team
Kindly, suggest how to approach this problem ?| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersImplement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.
- abhishek January 01, 2011| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou are given a permutation arr[N]. E.g. arr[3] = {2, 1, 0} or arr[5] = {0,1,2,4,3};
- emb October 05, 2015 in United States
Then you can prepare somehow and then start serving requests: request(a, b, k) = sorted(arr[a:b])[k], that is, k-th order statistic on slice [a:b] of arr.
E.g. if arr is [3,4,5,0,1,2] and a = 2 and b = 5, then arr[a:b] = [5,0,1] and let k = 2, so we sort it - get [0,1,5] and take k-th element, that is - 5.
Implement request(a, b, k) function. You can preprocess input data, that is, assume there will be only one array and many request() calls.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 2of 2 votes
AnswersSink Zero in Binary Tree. Swap zero value of a node with non-zero value of one of its descendants
- yuanbing January 18, 2014 in United States
so that no node with value zero could be parent of node with non-zero.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 2of 2 votes
AnswersGiven nxn boolean matrix (0's and 1's) .
- thebiker925 September 11, 2013 in United States
Find out whether there exist a row i and column j such that
1) all elemets of row i are zero's and
2) all elements of column j are 1's and
3)(i,j)th entry of the matrix can be either 0 or 1
Find out such a i and j exist or not .
complexity :O(n)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
Answers1.Substring Addition
- Stephie February 19, 2013 in United States
Write a program to add the substring
eg :say you have a list {1 7 6 3 5 8 9 } and user is entering a sum 16.Output should display (2-4) that is {7 6 3} cause 7+6+3=16.| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer - 2of 2 votes
AnswersGiven a set of numbers [1-N] . Find the number of subsets such that the sum of numbers in the subset is a prime number.
- Anonymous November 21, 2011 in India| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven two arrays/Lists (choose whatever you want to) with sorted and non intersecting intervals. Merge them to get a new sorted non intersecting array/list.
- HumbleLearner February 12, 2016 in United States
Eg:
Given:
Arr1 = [3-11, 17-25, 58-73];
Arr2 = [6-18, 40-47];
Wanted:
Arr3 = [3-25, 40-47, 58-73];| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 2of 2 votes
AnswersGiven a list/array of names(String) sort them such that each name is followed by a name which starts with the last character of the previous name.
- anurag.11feb January 07, 2014 in Netherlands
# input
[
Luis
Hector
Selena
Emmanuel
Amish
]
# output:
[
Emmanuel
Luis
Selena
Amish
Hector
]| Report Duplicate | Flag | PURGE
Booking.com Developer Program Engineer Algorithm - 2of 2 votes
AnswersWrite a method to count the number of 2s between 0 and n.*
- xankar May 12, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Developer Coding - 2of 2 votes
AnswersFind how many numbers of length n are there such that each number is at least 4 smaller/greater than the number before and after it.
- coolProgrammer August 02, 2015 in United States
Eg: if n = 5, such numbers are 39518, 15951, etc.| Report Duplicate | Flag | PURGE
Google Software Developer Dynamic Programming - 2of 2 votes
Answersgiven a vector of integers, v[i] represent the stock price on day i. Now you may do at most K transactions. you must sell your stock before you buy it again and that means you can NOT have two stocks at the same time. write a program to find max profit you can get.
- rjrush December 17, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersWrite code to sum 2 integer but u cant use a+b method, you have to use either ++ or --. How you will handle negative numbers.
- newbee October 10, 2014 in United States| Report Duplicate | Flag | PURGE
Apple Software Engineer in Test Algorithm - 2of 2 votes
AnswersAssume I have a log file with list of people with their arrival and departure time at an event that happened in the past.
- Bevan March 02, 2013 in United States
My task is to find out the maximum number of people present at any time during the entire event? I am not given query time.
ai = Arrival time of person i
di = Departure time of person i
I have a list of pairs like (a1,d1), (a2,d2), (a3,d3).... (an,dn)... It's not in a database.
I apologize as I cannot edit my previous question. I think it had a incomplete description.
Please let me know if you guys still need clarification. Thanks| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
Answerssort an array of 0's and 1's in a most efficient way.
- mahi December 23, 2009| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 2of 2 votes
AnswersVerify if S2 = {5,8,2} is a subset of S1 = {1,5,4,6,8,2} and S3 = {5,8,2,7} is not a subset of S1.
- hadeebataj May 10, 2019 in India| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer String Manipulation - 2of 2 votes
AnswersGiven predicted stock prices for next n days for a stock e.g : 10, 30, 42, 15, 20, 50, 10, 25 find the maximum profit that can be made with a single buy-sell transaction. If no profit can be made return 0. In the example buying at 15 and selling at 50 gives maximum profit. Note that the two prices are neither minimum nor maximum in the array.
- Kiara October 27, 2015 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 2of 2 votes
AnswersGiven two strings, return true if they are one edit away from each other, else return false. An edit is insert/replace/delete a character.
- codewarrior September 07, 2015 in United States
Ex. {"abc","ab"}->true, {"abc","adc"}->true, {"abc","cab"}->false| Report Duplicate | Flag | PURGE
Amazon SDE1 - 2of 2 votes
AnswersTech Screening
- sonesh July 02, 2015 in United States
Question 1 : You will be given a stream of integers, and a integer k for window size, you will only receive the streams integers one by one. whenever you receive an integer, you have to return the maximum number among last k integers inclusive of current entry.
Interviewer was expecting O(N) solution for N asks.
Edits: Interviewer was expecting O(N) Time + O(1) avg case space complexity solution for N asks.
and integers are not given in a array, every time only one integer will be passed as input to your method.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Arrays Data Structures - 2of 2 votes
AnswersAn array consist of elements whose difference is positive or negative 1. I have to find the given elements without using linear search.
- thilaksmile June 15, 2015 in India
Say
Int arr[]={1,2,3,4,3,4,5,6,7
To find : 6
.
Please provide some one code/algorithm for this problem.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer - 2of 2 votes
Answershow to implement a queue using one integer. this should store value 0 to 9. example suppose queue has first value 2 then insert 4 then 6 so it should look like 246. first value should be popped as 2. then it should be 46. program should support 0 in all the levels also. example queue should handle like 01235 also, 0 as first value in queue. remember 0 just to use integer, nothing else as data storage.
- Justin January 13, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven N stacks, each stack contains Si elements, find the maximum sum of the M numbers in the N stacks. To get the number of the stack, only supporting get the top number. For example, S=[1,200,1,2,3], if you want to get the number 200, you need choose 3,2,1 first.
- jeffrey November 28, 2016 in United States
EX:
S1=[1,1,100,3]
S2=[2000,2,3,1]
S3=[10,1,4]
the maximum sum of the 3 numbers in the above stacks is 3+100+3=107.
Any better solution for this problem?| Report Duplicate | Flag | PURGE
Google Software Engineer Dynamic Programming - 2of 2 votes
AnswersGiven an array of strings with only lowercase letters , create a function that returns an array of those same strings, but each string has its letters rearranged such that it becomes a palindrome (if possible, if not, return -1)
- makingworldcode September 13, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer Java - 2of 2 votes
Answers/**
- duskan February 22, 2014 in United States
* Returns a^b, as the standard mathematical exponentiation function
*/
public double pow(double a, int b) {}
Interviewer looking for log(n) solution, right on first attempt.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 2of 2 votes
Answersgiven y bytes and you can transfer only x bytes at once..give a mathematical expression having only + - / * which gives the number of iterations to copy y bytes. ( dont try giving modulo operator answers )
- rahulbmv October 25, 2012 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven N pair of parenthesis. Write an algorithm which would print out all possible permutations possible with those parenthesis given that parenthesis are in correct order (i.e. every open parenthesis is matched with closed parenthesis)
- shadykiller March 06, 2012 in India
For .e.g. .. N =3 should give:
()()()
(()())
()(())
(())()
((()))| Report Duplicate | Flag | PURGE
Flipkart Algorithm - 2of 2 votes
AnswersGiven an array of integers, return true if there're 3 numbers adding up to zero (repetitions are allowed)
- fatenuller January 09, 2015 in United States
{10, -2, -1, 3} -> true
{10, -2, 1} -> true -2 + 1 +1 =0| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm