Recent Interview Questions
- 3of 3 votes
AnswersFinding biggest plus sign "+" in a sparse matrix(matrix with elements 0 and 1)
- wtcupup2017 November 19, 2016 in United States
For example, the biggest plus sign for following matrix is located at (2,2), with length 1 for each edge(Yes, each edge should have same length)
0 0 1 0 0 1 0
1 0 1 0 1 0 1
1 1 1 1 1 1 1
0 0 1 0 0 0 0
0 0 0 0 0 0 0
Hint: use DFS/BFS| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 3of 3 votes
AnswersGiven a file (which can be considered as a String with comma delimiter for the complexity of the question) of usernames and a value k, find top k usernames (with number of logins) who logged into the system the most.
- sambenison66 June 05, 2016 in United States
For example -
Input:
User (String) = user1, user4, user2, user1, user3, user1, user2, user3
k (int) = 2
Output:
user1 (3)
user2 (2)
user3 (2)
- Both user2 and user3 should be included since both has same number of logins
Write a java method to find the output with best time and space complexity.| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Java - 3of 3 votes
Answers$a = [3, 1, 4, 5, 19, 6];
$b = [14, 9, 22, 36, 8, 0, 64, 25];
# Some elements in the second array are squares.
- Phil September 08, 2015 in Netherland
# Print elements that have a square root existing in the first array.
# $b[1] = 9, it’s square root is 3 ($a[0])
# $b[3] = 36, it’s square root is 6 ($a[5])
# $b[7] = 25, it’s square root is 5 ($a[3])
# Result:
# 9
# 36
# 25| Report Duplicate | Flag | PURGE
Booking.com Software Engineer Algorithm - 3of 3 votes
AnswersYou are given an array of distinct numbers. You need to return an index to a "local minimum" element, which is defined as an element that is smaller than both its adjacent elements. In the case of the array edges, the condition is reduced to one adjacent element.
- Anonymous January 27, 2015 in Israel
Reach a solution with better time complexity than the trivial solution of O(n).
If there are multiple "local minimums", returning any one of them is fine.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 3of 3 votes
AnswersThere is a clock at the bottom of the hill and a clock at the top of the hill. The clock at the bottom of the hill works fine but the clock at the top doesn’t. How will you synchronize the two clocks. Obviously, you can’t carry either of the clocks up or down the hill! And you have a horse to help you transport yourself. And, the time required for going up the hill is not equal to the time required to go down the hill.
- Nascent July 01, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon - 3of 3 votes
AnswersGiven an array with different numbers and a number of C,so how to find all the combinations which the sum is C..like..array={1,2,3,4},C=3,,return is 2,which contains two combinations{{1,2},{3}}.
- onyasGM May 23, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer Algorithm - 3of 3 votes
AnswersGiven an array of integers, find Pythagorean triplets.
- goelrinku90 March 29, 2013 in United States
i.e. find a,b and c which satisfies a^2 + b^2 = c^2
Integers could be positive or negative.| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer - 3of 3 votes
AnswersGive the algorithm and code to get the depth of the deepest odd level leaf node in a binary tree.
- tom March 04, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 3of 3 votes
AnswersDesign a phonebook dictionary which on input any characters gives names and phone number of all the matching names(prefix)
- vik February 08, 2013 in United States
For instance
Rihana 233222232
Ricky 134242444
Peter 224323423
Ron 988232323
If you give R as input it should list
Rihana Ricky and Ron which their contact numbers
If you give ri as input it should list
Rihana, Ricky which their contact numbers| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Algorithm Data Structures - 3of 3 votes
AnswersGiven a dictionary of words & a miss-spelled input, write a function which will find 3 words from the dictionary which are closest (by difference of 1-character) to the given input.
- vinzee93 February 28, 2019 in United States
eg - dict = {vil, sit, flick, pat, pluck, sat, vat}, input = vit, ans = {sit, vil, vat}| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersGiven a forest of balanced binary trees and two nodes, n1 and n2, find the closest common parent of n1 and n2. Nodes have parameters "parent", "left" and "right", and you cannot access the values of the nodes. If n1 and n2 are not on the same tree, return NULL.
- Matt Cooper December 26, 2015 in United States for Software Engineering
Try to do this in O(log(n)) time and O(1) space.| Report Duplicate | Flag | PURGE
Facebook Intern Trees and Graphs - 3of 3 votes
AnswersFind the number of bits set in a given character array.
- JSDUDE May 18, 2015 in United States
After giving him a bit wise operation that was O(n) where n is the number of bits set, he wanted a more optimum solution| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Bit Manipulation - 3of 3 votes
Answerswrite a function:
int median(int a, int b, int c)
and then write another function:
- ghirlwhocodes April 23, 2015 in Switzerlandint median(int a, int b, int c, int min, int max)
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 3 votes
AnswersFind the longest words in a given list of words that can be constructed from a given list of letters.
- Rohitraman2006 August 01, 2014 in United States
Your solution should take as its first argument the name of a plain text file that contains one word per line.
The remaining arguments define the list of legal letters. A letter may not appear in any single word more times than it appears in the list of letters (e.g., the input letters ‘a a b c k’ can make ‘back’ and ‘cab’ but not ‘abba’).
Here's an example of how it should work:
prompt> word-maker WORD.LST w g d a s x z c y t e i o b
['azotised', 'bawdiest', 'dystocia', 'geotaxis', 'iceboats', 'oxidates', 'oxyacids', 'sweatbox', 'tideways']
Tip: Just return the longest words which match, not all.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 3of 3 votes
AnswersGiven two unsorted integer arrays A & B of unequal length.
- vikas.singh.nitj December 05, 2013 in India
Find an element from A(say 'X') and another element from B(say 'Y') such that |X-Y| is minimum.
Note: A & B can contain positive/negative numbers.
How can you find this without sorting both arrays?
How can you find this by sorting both arrays?| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Algorithm - 3of 3 votes
AnswersGiven two log files, each with a billion usernames (each username appended to the log file), find the usernames existing in both documents?
- Madan December 04, 2013 in United States| Report Duplicate | Flag | PURGE
Google SDE-2 - 3of 3 votes
AnswersGiven a string, you need to find super string by word match. i.e. all words in the input string has to occure in any order in output string.
- zc51 March 29, 2013 in India
e.g. given data set:
"string search"
"java string search"
"manual c++ string search equals"
"java search code"
"c++ java code search"
...
input: "java search"
output:
1) "java string search"
2) "java search code"
3) "c++ java code search"
input: "c++ search"
output:
1) "manual c++ string search equals"
2) "c++ java code search"
There are millions of records in given data set and you need to process few million as input.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Data Mining - 3of 3 votes
AnswersGiven a sorted array, find all the numbers that occur more than n/4 times.
- alisonlee659 March 24, 2017 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersSuppose that each row of an n x n array A consists of 1's and D's such that, in any
- inevitablekris September 21, 2014 in United States
row i of A, all the 1's come before any D's in that row. Suppose further that the
number of 1's in row i is at least the number in row i+ 1, for i= 0, 1, ... .n - 2.
Assuming A is already in memory, describe a method running in O(n) time (not
O(n2) time) for counting the number of 1's in the array A.| Report Duplicate | Flag | PURGE
Arrays - 3of 3 votes
AnswersGiven list of pounds, the pounds that can be measured using a balance should be displayed.
- premkumar1989.ss March 13, 2013 in India for Dev
For Ex: 100,250
The output will be 100,250,150
The number of pounds which will be given in input might vary. Can someone please help with an algorithm for this?| Report Duplicate | Flag | PURGE
Kpro Solutions Analyst Algorithm - 3of 3 votes
AnswersGiven an array of object A, and an array of object B. All A's have
- hao.liu0708 October 30, 2014 in United States
different sizes, and all B's have different sizes. Any object A is of the
same size as exactly one object B. We have a function f(A, B) to compare the
size of one A and one B. But we cannot compare between two A's or two B's.
Give an algorithm to match each A with each B.| Report Duplicate | Flag | PURGE
Google Software Development Manager Algorithm - 3of 3 votes
AnswersGiven two parameters (a target string and a source string), write code that returns the number of times characters found in the source string occur in the target string.
- ootah November 14, 2013 in United States
For example, if target="Hello world" and source="llld" then return 4| Report Duplicate | Flag | PURGE
Citrix System Inc Software Engineer / Developer C - 3of 3 votes
AnswersUsing the mythical Hydra as an example, create a button that is destroyed by clicking it, but two new buttons are created in it's place.
- Kevin.Pheasey April 10, 2013 in United States for AWS| Report Duplicate | Flag | PURGE
Amazon Web Developer JavaScript - 3of 3 votes
AnswersGiven 'n' circles (each defined by center and radius)
- sheva November 12, 2016 in United States
Write an algorithm to detect if circles intersect with any other circle in the same plane
Better than O(n^2) complexity| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersWrite an algorithm that returns any duplicate in an array of integers. The algorithm must run in O(n) time and O(1) space. (hint: the integers in the array are not greater than the size of the array).
- davidgbadebo6 November 08, 2016 in United States| Report Duplicate | Flag | PURGE
Google Intern - 3of 3 votes
AnswersGiven two sorted lists and an integer k, merge the lists up to a maximum of k elements.
- codebrkr September 15, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon SDET - 3of 3 votes
AnswersDesign an application which sends the user the 10 closest hotels based on his geo location.
- assaf.keret1 June 21, 2015
When i asked roughly how many hotels in total are we talking about, i was asked to estimate how many hotels are there in the world...| Report Duplicate | Flag | PURGE
Google Software Engineer in Test - 3of 3 votes
AnswersLet's say there is a double square number X, which can be expressed as the sum of two perfect squares, for example, 10 is double square because 10 = 3^2 + 1^2
- baudday November 17, 2014 in United States for Emerging Markets
Determine the number of ways which it can be written as the sum of two squares| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 3of 3 votes
AnswersCreate the data structure for a component that will receive a series of numbers over the time and, when asked, returns the median of all received elements.
(Median: the numerical value separating the higher half of a data sample from the lower half. Example: if the series is
2, 7, 4, 9, 1, 5, 8, 3, 6
then the median is 5.)
Model the data structure for a component that would have these two methods:@interface SampleHandler { - (void)addNumber:(NSNumber*)number; - (NSNumber*)median; }
Justify your decisions. Calculate the complexity of each method.
- Diego May 16, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook iOS Developer Data Structures