Algorithm Interview Questions
- 0of 0 votes
AnswersConsider that your office provides an app to book meeting rooms. You provide the start and end time of the meeting. The app list the available rooms for that slot and you select a room and confirm your booking.
- Coding Panda September 30, 2016 in United States
All meeting happen between 9am - 6pm.
Write a method for getAvailableRooms(startTime, endTime). Use appropriate data structures.| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersWrite a program that reads a maze from a file and outputs from 'X' to 'O'. Example,
- mrsurajpoudel.wordpress.com September 30, 2016 in United StatesInput: ########## X # # # # # # # # O ########## Output: ########## +++#+++++# # +#+ # +# # +++ # ++ ##########
| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 1of 1 vote
Answerscount the duplicates in a array of strings??
- manasa0930 September 29, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Algorithm - 2of 2 votes
AnswersGiven an Array A with n elements. Pick maximum number of elements from given array following the rule:
- chan alex September 25, 2016 in United States
1. We cannot pick A[i] and A[j] if absolute value of (A[i] - A[j]) > absolute value of (i - j)
Example: {13,5,4}
Ans: 2
Pick 5 and 4.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 4 votes
AnswersA frequent traveller collects all his travel tickets.
- rd22 September 24, 2016 in India
A ticket has only 2 attributes, Start Journey Location name and Destination Name. Example from Delhi to Mumbai.
At the end of the year, the traveller gets all his tickets together and tries to map his journey across the year. Print his travel route in a readable format. He does not remember his start location.
Edit: he can visit a location multiple times, and can also go back and forth a place several times.| Report Duplicate | Flag | PURGE
Amazon Algorithm - 1of 1 vote
AnswersThere is a 2D grid and there are two players P1 and P2. Their x,y positions are given. Then there are N gems on the grid and their positions are also given. The two players together are supposed to collect the gems in the given sequence making minimum moves (movement in all 8 directions is considered as 1 move). Note: the gems should be collected in the given order by either one of the players and then their position then becomes the position of the gem.
- Saroj Sharma September 22, 2016 in India| Report Duplicate | Flag | PURGE
Directi Applications Developer Algorithm - 0of 0 votes
AnswersImplement method:
Lìst<Range> getRanges(Lìst<Shard> shards, Lìst<Key> keys)
That returns list of ranges. Each range represents multiple keys aggregated over a shard:
n-keys —> 1-shard —> l-range
Method should return no more than 1 range per shard that spans all keys or their parts belonging to this shard.
Each of the ‘Range` , 'Shard’ and ‘Key’ classes have ‘end’ and ‘start’ fields of int type, where ‘start’ is inclusive and ‘end’ is exclusive.
Example:
- ermilanardeshana September 21, 2016 in United States1—9, 12—59, 100—999 <— shards (input) 2—3, 6—8, 11—20, 200—220 <— keys (input) 2—8, 12—20, 200—220 <— ranges (output)
| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 0of 0 votes
AnswersWrite a program which will get the top 'x' tweets based on their re-tweet count from 'n' tweets.
- danny459 September 20, 2016 in India| Report Duplicate | Flag | PURGE
N/A Front-end Software Engineer Algorithm - 0of 0 votes
AnswersSuppose there is a social networking site like Facebook. Every user gets some friend recommendations (i.e. People you may know!). Now, if there is a user A and he has 100 friends and each of his friends has got 5 other friends,A can get these 500 recommendations. But the condition is that he should only get the top 10 recommendations with whom he has the maximum number of mutual friends(If A and B are friends and B and C are friends, then A and C have a mutual friend, B). Suggest an efficient data structure for this and how to implement it. The implementation should be flexible as at any moment, any user can make new friends and he may also unfriend someone!
- manidam07 September 19, 2016 in India| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - -1of 1 vote
AnswersSearching for a string in a DOM tree. A complete working solution was required. Assume you have any string matching algorithm available.
- vgupta.2119 September 18, 2016 in India
(Based on Ctrl+F search in chrome)| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - -1of 1 vote
AnswersSearching for a string in a DOM tree. A complete working solution was required. Assume you have any string matching algorithm available.
- vgupta.2119 September 18, 2016 in India
(Based on Ctrl+F search in chrome)| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 1of 1 vote
AnswersGiven a directed graph G, duplicate the graph using minimum space.
- vgupta.2119 September 18, 2016 in India| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswersDesign a rules engine. It should run in at least linear time and should efficiently handle repetitive attributes in different rules. E.g.,
- angshu1986 September 18, 2016 in India
Attributes:
1. Digit check
2. Character check
Rule:
1. Rule 1 - input should be digit
2. Rule 2 - input should be digit and = 3
3. Rule 3 - input should be digit and between 2 and 5
4. Rule 4 - input should be character and value should be 'A'
5. Rule 5 - input should be character and value should be 'B'
Design rule matrix and process a stream of inputs. More than one rule may be applicable for a given input.| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Algorithm Object Oriented Design - 0of 0 votes
AnswersYou are given a dictionary of fixed words, you need to find the maximum chain of words that can be formed by any of these words. A chain is formed by picking a word and removing one character from it and this newly formed word should be present in the dictionary.
- rd22 September 15, 2016 in India
As an example say the dictionary consists of {a, b, ba, bca, bda, bdca}, then the word that forms the biggest chain will be bdca -> bca -> ba -> (a or b), i.e. a chain of length 4.| Report Duplicate | Flag | PURGE
Amazon Algorithm - 1of 1 vote
AnswersA list of words is given and a bigger string given how can we find whether the string is a permutation of the smaller strings.
- novicedhunnu September 15, 2016 in India
eg- s= badactorgoodacting dict[]={'actor','bad','act','good'] FALSE
eg- s= badactorgoodacting dict[]={'actor','bad','acting','good'] TRUE
The smaller words themselves don't need to be permuted. The question is whether we can find a ordering of the smaller strings such that if concatenated in that order it gives the larger string
One more constraint - some words from dict[] may also be left over unused| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - -1of 1 vote
AnswersYou have a bidimensional space of area N that contains a circle of area M that could be placed anywhere in this space. What is the optimal way of finding the circle, drawing lines, considering you have a function that can tell you if a line is intersecting the circle?
- Ray September 14, 2016 in United States| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 0of 0 votes
AnswerWe need a functionality to block an user who makes more than 10 requests in last 5 minutes. You need to implement the following function.
- rayasamharish September 14, 2016 in United States
{{
boolean block_user(int user_id)
{
//TODO: return true in case u want to block user
}
}}| Report Duplicate | Flag | PURGE
anonymous SDE-2 Algorithm - 0of 0 votes
AnswersGiven an array of numbers find the duplicates
- andy.r.nathan September 14, 2016 in United States for Mobile| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm - 1of 1 vote
AnswersSuppose you have a list of Dishes, where each dish is associated with a list of ingredients. Group together dishes with common ingredients.
- andy.r.nathan September 14, 2016 in United States for Mobile
E.g:
Input:
"Pasta" -> ["Tomato Sauce", "Onions", "Garlic"]
"Chicken Curry" --> ["Chicken", "Curry Sauce"]
"Fried Rice" --> ["Rice", "Onions", "Nuts"]
"Salad" --> ["Spinach", "Nuts"]
"Sandwich" --> ["Cheese", "Bread"]
"Quesadilla" --> ["Chicken", "Cheese"]
Output: ("Pasta", "Fried Rice") ("Fried Rice, "Salad") , ("Chicken Curry", "Quesadilla") ("Sandwich", "Quesadilla")
Follow up: What is the time and space complexity?| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm - 0of 2 votes
AnswersReturns the zero based index of the first occurrence of any character of str2 in str1
- tikolo September 06, 2016 in United States
Input:
str1="adf6ysh"
str2="123678"
output: 3
I have solved this by taking second string in hashset and then iterating first string one by one but i need more optimized way.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Algorithm - 0of 0 votes
AnswersGiven a list L of numbers from 0 to n, and another number k = [0-9], find how many times k appears in L. If the target number in L is more than one digit, treat each digit separately. For example, k=0 appears twice in L = [0,10].
- / September 05, 2016 in Canada| Report Duplicate | Flag | PURGE
TalkIQ Senior Software Development Engineer Algorithm - 2of 2 votes
AnswersMr. Kim has to deliver refrigerators to N customers. From the office, he is going to visit all the customers and then return to his home. Each location of the office, his home, and the customers is given in the form of integer coordinates (x,y) (0≤x≤100, 0≤y≤100) . The distance between two arbitrary locations (x1, y1) and (x2, y2) is computed by |x1-x2| + |y1-y2|, where |x| denotes the absolute value of x; for instance, |3|=|-3|=3. The locations of the office, his home, and the customers are all distinct. You should plan an optimal way to visit all the N customers and return to his among all the possibilities.
- Loser September 03, 2016 in India
You are given the locations of the office, Mr. Kim’s home, and the customers; the number of the customers is in the range of 5 to 10. Write a program that, starting at the office, finds a (the) shortest path visiting all the customers and returning to his home. Your program only have to report the distance of a (the) shortest path.
You don’t have to solve this problem efficiently. You could find an answer by looking up all the possible ways. If you can look up all the possibilities well, you will get a perfect score.
[Constraints]
5≤N≤10. Each location (x,y) is in a bounded grid, 0≤x≤100, 0≤y≤100, and x, y are integers.
[Input]
You are given 10 test cases. Each test case consists of two lines; the first line has N, the number of the customers, and the following line enumerates the locations of the office, Mr. Kim’s home, and the customers in sequence. Each location consists of the coordinates (x,y), which is reprensented by ‘x y’.
[Output]
Output the 10 answers in 10 lines. Each line outputs the distance of a (the) shortest path. Each line looks like ‘#x answer’ where x is the index of a test case. ‘#x’ and ‘answer’ are separated by a space.
[I/O Example]
Input (20 lines in total. In the first test case, the locations of the office and the home are (0, 0) and (100, 100) respectively, and the locations of the customers are (70, 40), (30, 10), (10, 5), (90, 70), (50, 20).)
5 ← Starting test case #1
0 0 100 100 70 40 30 10 10 5 90 70 50 20
6 ← Starting test case #2
88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
10 ← Starting test case #3
39 9 97 61 35 93 62 64 96 39 36 36 9 59 59 96 61 7 64 43 43 58 1 36
...
Output (10 lines in total)
#1 200
#2 304
#3 366| Report Duplicate | Flag | PURGE
Samsung Software Engineer Algorithm - 2of 2 votes
Answers[redacted]
- tohhubeta September 02, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswerTime Complexity ?
- Ragesh September 02, 2016 in United States for Seattle
a. Inserting a node in Linked List?
b. HashMap time complexity?| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersFind missing number from sequence of numbers in an array? Time Complexity?
- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersReverse a String using Recursion and unit tests?
- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 1of 1 vote
AnswersGiven a sparse matrix, implement below two methods:
- starlord September 01, 2016 in United States
void set(int row, int col, int val) /*Update value at given row and col*/
int sum(int row, int col) /*give sum from top left corner to given row, col sub-matrix*/| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswersGiven two positive floating point numbers (x,y), calculate x/y to within a specified epsilon without using in-built functions
- jason.sarka August 31, 2016 in United States| Report Duplicate | Flag | PURGE
Expedia Algorithm - 0of 0 votes
AnswersYou have a buffer of 1024 only.There are packets coming from infinite sources. Need to design a data structure that can list the sources based on highest number of packets received from a source. After every 5 min, a scan is done and top 50 sources from where max packets are received are to be removed.
- srihari August 30, 2016 in United States| Report Duplicate | Flag | PURGE
Algorithm - 1of 1 vote
AnswersA company is looking for algorithm to show item recommendations.
- maksymas August 29, 2016 in United States
If a customer bought A and B items and another buys A item, B should come as recommendations.
There are two types of recommendations based on the connections
1) Two items are strongly connected if a customer buys those items.
2) Two items are weakly connected if each items are strongly/weakly connected to another third item.
Provided the sample input
ABC
10
first:ABC
first:HIJ
sec:HIJ
sec:KLM
third:NOP
fourth:ABC
fourth:QRS
first:DEF
fifth:KLM
fifth:TUV
first, sec, third.. represents the customer names
ABC, HIJ... represents the item codes
For the Input item Id "ABC", since "ABC" is strongly connected to HIJ, DEF, QRS
and whereas ABC is weakly connected to KLM and TUV
the output should be count of strong and weak connection i.e., [3,2]| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm