Algorithm Interview Questions
- 1of 1 vote
AnswersDesign an algorithm that provided your current location and a list of ATMs locations in the area, get you the closest K ATMs to your location.
- ahmedthehack June 23, 2017 in UK for Amazon Video
Assume you have a method getDistance(a, b) that calculates the distance between a and b.
Follow Up:
Make your solution O(k) space and O(n) time| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersDesign an algorithm to find the shortest substring in a synopsis such that it contains all the words in a provided list.
- ahmedthehack June 23, 2017 in UK for Amazon Video
So, search for the shortest substring that contains ['Hello', 'World'].| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 3of 3 votes
AnswersGoogle full-time phD candidate w/ work experience.
- aonecoding June 22, 2017 in United States
Q1. On a 1 meter walkroad, randomly generate rain. The raindrop is 1 centimeter wide.
Simulate how raindrops cover the 1 meter [0~1] road. How many drops does it take to fully cover the 1meter?
Q2. Find out the maximum number of isosceles triangles you can make from a plane of points(cannot reuse points)
Q3.Longest holiday - Every city has a different days of holidays every week. You may only travel to another city at the weekends. What is the max days of holiday you can get this year.
Q4.
Design merchandising product data storage service| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersQuestion regarding largest possible sum of subarray of size K.
- filipslatinac June 21, 2017 in Canada| Report Duplicate | Flag | PURGE
Google Algorithm - 0of 0 votes
AnswersFirst asked how you can write a tree in a file?
- Ghosh June 17, 2017 in India
Next question was lets say value of one node is changed, how can you update that in that file without writing the whole tree in file again?d| Report Duplicate | Flag | PURGE
SDE-3 Algorithm Data Structures - 5of 5 votes
AnswersGoogle On-site in May
- aonecoding June 15, 2017 in United States
Create a class with a collection of integers.
Enable 3 APIs:
void append(int x),
int get(int idx),
void add_to_all(int x),//add x to all numbers in collection
These methods should run in O(1) time.
Follow-up
In addition, implement
void multiply_to_all(int x)
The same required to run in O(1) time| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersThere are around 40 million files in a directory which needs to be transferred to another system via FTP in order of oldest file first. What's the ideal way to iterate over files and store it in a data structure from where it can be transferred?
- anjesh June 12, 2017 in India| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswerGiven a m x n array filled with 1's & 0's. Find all the rectangles which are filled with all the 1's.
- Seeker June 01, 2017 in United States
Note : - It is guaranteed that there won't be any overlapping rectangles.| Report Duplicate | Flag | PURGE
MuleSoft Software Engineer Algorithm - 2of 2 votes
AnswersFind Famous person in the list of persons.
- Seeker June 01, 2017 in United States
A person is a famous person if he doesn't know anyone in the list and everyone else in the list should know this person.
The function isKnow(i,j) => true/ false is given to us. No need to worry about it.
Goal is to find the famous person in O(n) complexity.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - -1of 1 vote
AnswersGiven a stream of objects, O1, O2, O1, O3, O4... Provide an algorithm to identify the first unique object at any given point in time.
- abhi10901 May 31, 2017 in United States for AWS Auto Scaling
So for example, in the above, after receiving the first Object, it is unique. After receiving the second, the first is still the first unique object. After receiving the 3rd, the 1st object is no longer unique (you've not seen O1 twice), so O2 is not the first unique object. etc...| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersLast Monday phone interview of G.
- aonecoding May 27, 2017 in United States
Given a vector/list of doubly linked list pointers (a pointer is the directed linkage of two nodes), count how many independent blocks of linked lists there are for the pointers given.| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 0of 0 votes
AnswersFind the first non repeating character in a string. For example if the input string "abcdeabc", non repeating character is "e"
- kag May 24, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - -1of 1 vote
AnswersFind if a mathematical string is balanced in terms of parenthesis. For example "(1+2)" is balanced and "(1+2" is not balanced.
- kag May 24, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 1of 1 vote
AnswersYou have a array with integers:
[ 1, -2, 0, 6, 2, -4, 6, 6 ]
You need to write a function which will evenly return indexes of a max value in the array.
- vu-doo-cok May 22, 2017 in UK
In the example below max value is 6, and its positions are 3, 6 and 7. So each run function should return random index from the set.
Try to implement with O(n) for computation and memory.
Try to reduce memory complexity to O(1).| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersThe number of valid combinations of a strings for given input array a[], where a=>1, z => 26, and 0 <= a[i] <= 9
- nelly2k May 19, 2017 in United States
{1,1,1} => {aaa, ak, ka} => 3
{1,1,0} => {aj} => 1| Report Duplicate | Flag | PURGE
Facebook SDE-2 Algorithm - 0of 0 votes
Answers/* The objective of this exercise is to build a road network connecting every pair of cities.
- Learner_Ash May 19, 2017 in United States
Each city should be connected to each other city once.
*/
public class Program
{
/* Your function RoadBuilder should return a list of new roads required to be built,
if the existing roads are given by builtRoads and the total number of
cities is nCities. Roads should not connect cities to themselves.
*/
public static int[][] RoadBuilder(int nCities, int[, ] builtRoads)
{
//implement the function here
return new int[0][];
}
public static void Main()
{
int[, ] test1 = new int[3, 2]{{0, 1}, {1, 2}, {3, 2}};
Console.WriteLine(RoadBuilder(4, test1)); // expected result should be {{0,2}, {0, 3}, {1, 3}}
}
}| Report Duplicate | Flag | PURGE
Applications Developer Algorithm - 0of 0 votes
AnswersThere are three row of houses. There are N houses in each row. Each house can be painted with three colors: red, blue and green. The cost of painting each house with a certain color is different. You have to paint all the houses with following constaints
- jmincoder2 May 16, 2017 in United States
No two adjacent houses in a row have the same color.
Houses in a column have three different colors
You have to paint the houses with minimum cost. How would you do it?
Note: The cost of painting house 1 red is different from that of painting house 2 red in any row. Each combination of house and color has its own cost.| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - 0of 0 votes
AnswersGiven a binary tree of integers, write code to store the tree into a list of integers and recreate the original tree from a list of integers.
- Null0 May 13, 2017
Here's what your method signatures should look like (in Java):
List<Integer> store(Node root)
Node restore(List<Integer> list)
Example Tree:
5
/ \
3 2
/ / \
1 6 1| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm Data Structures Java Trees and Graphs - 4of 4 votes
AnswersYou are given set of strings, You have return anagrams subsets from it. An anagram set is that one where every string is an anagram of another string. If the subset contains only one string, don't include that in the result.
- sonesh May 11, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm String Manipulation - 0of 0 votes
AnswersYou are given a NxN boolean matrix, where matrix(i,j) will be one if 'i' is a parent of 'j' in a tree, otherwise, it is zero.
- sonesh May 11, 2017 in United States
Construct this tree.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm Trees and Graphs - 0of 0 votes
AnswerDesign/Implement an LRU cache so that Read/Write/Find operation only takes constant time.
- sonesh May 11, 2017 in United States
Now, Let's say, we will be considering the frequency as well. It means to keep the most used processes and in a case of the tie, use lease recently used to remove an element.
Now, as this new algorithm can cause many hits, or no new process will come to the cache if the last process of the cache has two hits., What can you do to prevent this, and how would you implement that.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm design - 1of 1 vote
AnswersApple On-site at Cupertino
- aonecoding May 10, 2017 in United States
Team Data Warehousing
III. Given three letters ABC, where AB->C, AC->B, BC->A (sequence doesn’t matter). Get the length of the path to convert from a given string to a single character.
For example, “ABACB” goes to “ACCB” (based on AB ->C, convert s[1] and s[2] to C)
“ACCB” goes to “BCB” (based on AC->B)
“BCB” goes to “AB”
“AB” goes to “C”
So it takes 4 steps to change the given string into a single character.
If a given string cannot be resized to 1 character, such as “AAA” or "ABACABB", return -1.| Report Duplicate | Flag | PURGE
Apple SDE-3 Algorithm - 1of 1 vote
AnswersApple On-site at Cupertino
- aonecoding May 10, 2017 in United States
Team Data Warehousing
There were 6.5 rounds in total, that 0.5 on package negotiation with the HR and the remaining rounds with 2 managers and 4 engineers.
Only three pure coding questions were asked.
I. Use a stack to sort given data.
II. Given an array with positive integers only, find the MIN integer that is missing from the array.| Report Duplicate | Flag | PURGE
Apple SDE-3 Algorithm - 0of 0 votes
AnswersYou are given an array of values, (not necessary integers or positives) and a value. You have to print all the pairs whose sum is given value. Write a general method which can accept integers, float, doubles, long, or any other thing where this make sense.
- sonesh May 08, 2017 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Senior Software Development Engineer Algorithm Coding - 0of 0 votes
AnswersYou are given an array of stock prices, You have to return maximum profit one can make when buying once and selling once. Consider, you are buying one stock only.
- sonesh May 08, 2017 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Algorithm - 0of 0 votes
AnswersYou are given set of strings, you have to print out the could of each distinct patterns. Please consider anagrams as same pattern and even the char count does not matter.
- sonesh May 08, 2017 in United States
Ex:
abbba
ab
ba
abcd
abdc
adbc
aabddc
output:
ab: 3
abcd: 4| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Algorithm - 0of 0 votes
AnswersImplement pow(x, n)
- alisonlee659 May 03, 2017 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Algorithm - 1of 1 vote
AnswersPick three numbers a, b, c from an array of integers to get the maximum product a * b * c.
- alisonlee659 May 03, 2017 in United States
Began with the O(N^3) solution. Then the interviewer give clues on optimization by sorting the array.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Algorithm - 0of 0 votes
AnswersJamie is walking along a number line that starts at point 0 and ends at point n. She can move either one step to the left or one step to the right of her current location , with the exception that she cannot move left from point 0 or right from point n. In other words, if Jamie is standing at point i,she can move to either i-1 or i+1 as long as her destination exists in the inclusive range [0,n]. She has a string ,s , of movement instruction consisting of the letters 1 and r , where 1 is an instruction to move one step left and r is an instruction to move one step right.
- Ashish Dass May 01, 2017 in India for Java
Jamie followed the instructions in s one by one and in order .For Example if s=‘rrlr’,she performs the following sequence of moves :one step right ->one step right ->one step left -> one step right .Jamie wants to move from point x to point y following some subsequence of string s instruction and wonders how many distinct possible subsequence of string s will get her from point x to point y. recall that a subsequence of a string is obtained by deleting zero or more characters from string .
it has four parameters
A String , s giving a sequence of eduction using the characters l( i.e. move left one unit ) and r (i.e. move right one unit)
An integer n, denoting the length of the number line.
An integer x, denoting jamie’s starting point on the number line
An integer y , denoting Jamie’s enidng point on the number line.
The function must return an integer denoting the total number of distinct subsequence of string s that will lead Jamie from point x to point y as this value cab be quite large .
Sample Input
rrlrlr
6
1
2
out put =7| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Algorithm - 0of 0 votes
AnswersQ 2. You are given a chess game board of size NxN. You have find out positions(i,j), where you can place N queens so that, none of the queens can kill each other without making their first move.
- sonesh April 28, 2017 in United States| Report Duplicate | Flag | PURGE
Hitachi Data Systems Software Engineer / Developer Algorithm Coding Dynamic Programming Matrix