Algorithm Interview Questions
- 0of 0 votes
AnswersHow to Design an Meeting scheduler
- DuttaJ March 23, 2017 in India| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Algorithm - 0of 2 votes
AnswersHow to randomly select a number in an array?
- aonecoding March 22, 2017 in United States
array: [15, 2, 4, 5, 1, -2, 0]
Follow-up:
Given a second array freq where freq[i] represents the occurrence of the ith number in array, how to randomly select a number in array based on the frequency.
Extra requirement:
Could you complete the selection in a single-pass(go through each array only once)?| Report Duplicate | Flag | PURGE
Linkedin Software Engineer Algorithm - 1of 5 votes
AnswersIn school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.
- aonecoding March 22, 2017 in United States
Given a student's attendance record represented by a string with 3 possible characters 'L'(Late), 'A'(Absent), 'O' (On time),
check whether the student qualifies for the reward.
e.g.
@INPUT (String) "OLLAOOOLLO"
@RETURN (Boolean) False
The student does not qualify for reward because "LLA" means he was late for 3 times in a row.
@INPUT (String) "OLLOAOLLO"
@RETURN (Boolean) True
Follow-up:
If known the length of the attendance string is n, how many possible ways there is to attend school and make sure you get the reward.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersIn school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.
- aonecoding March 22, 2017 in United States
Given a student's attendance record represented by a string with 3 possible characters 'L'(Late), 'A'(Absent), 'O' (On time), check whether the student qualifies for the reward.
e.g.
@INPUT (String) "OLLAOOOLLO"
@RETURN (Boolean) False
The student does not qualify for reward because "LLA" means he was late for 3 times in a row.
@INPUT (String) "OLLOAOLLO"
@RETURN (Boolean) True
Follow-up:
If known the length of the attendance string is n, how many possible ways there is to attend school and make sure the student gets the reward.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - -1of 1 vote
AnswersFind K which decides the number of open brackets are equal to the number of closed brackets.
- AlgoBaba March 21, 2017 in United States
input : (())
output : 2
Reason : if we divide the string at 2nd position, we get two open brackets and two closing brackets, and they are same .
input : (())))(
output : 4
Reason : if we divide the string(not necessarily equally) at 4rth position, we have (()) on the left side and on the right side we have ))( , as you can see, on the left half, we have two opening brackets and on the right half we have two closing brackets and they are equal .
input : ))
output : 2
Reason : there is no open brackets , so if we divide taking the whole string's length, we have )) on the left half and nothing on the right half. Now you can see that on the left half there is no open brackets and on the right half there is no closed brackets.
This question should be clear by now and remember you have to find out that K .| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersThere are two integer array arrayA and arrayB in the same size and two integer countA and countB. If arrayA[i] > arrayB[i], then we increase countA by 1, if arrayB[i]>arrayA[i], then we increase countB by 1. We will do nothing otherwise. Now you are given arrayA and arrayB, write a function to shuffle arrayA and so you can get countA > countB. Assume the input array are always valid, not empty and the input is guaranteed to have answer.
- gzyeli123 March 20, 2017 in United States
For example:
arrayA = [12, 24, 8, 32]
arrayB = [13, 25, 32, 11]
After shuffle:
arrayA = [24, 32, 8, 12]
arrayB = [13, 25, 32, 11]| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 0of 0 votes
AnswersFind the Maximum number of distinct nodes in a binary tree path
- AlgoBaba March 20, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersCheck if two given binary trees(expression trees with two characters 'a' and 'b' and obviously operators like +,-,*) are mathematically equivalent?
- AlgoBaba March 16, 2017 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
Answers1) Given a file containing lines of chars, find if it contains "aaaaab\naaaaa" string pattern. Need to return true only if contains the EXACT pattern specified (observe the new line character).
- xankar March 10, 2017 in United States
2) How do you differentiate between actual new line and the new line character?
3) what if the file is way too big to bring it all in memory?| Report Duplicate | Flag | PURGE
Dropbox Backend Developer Algorithm - 0of 0 votes
AnswersTop View of a Binary Tree in constant space
- neer.1304 March 10, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven a pattern containing only Is and Ds. I for increasing and D for decreasing. Devise an algorithm to print the MINIMUM number following that pattern. Digits from 1-9 and digits can’t repeat.
- neer.1304 March 10, 2017 in United States
Example:
1. Input: D Output: 21
2. Input: I Output: 12
3. Input: DD Output: 321
4. Input: II Output: 123
5. Input: DIDI Output: 21435
6. Input: IIDDD Output: 126543
7. Input: DDIDDIID Output: 321654798| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersImplement ConcurrentHashMap class in Java
- neer.1304 March 10, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersImplement LinkedHashMap class in Java
- neer.1304 March 10, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersYou have been given a grid with some doors, walls and some empty spaces.
- neer.1304 March 10, 2017 in United States
1st part : You have to tell the least no of moves to go from random position in the grid to the nearest door. You can move in four directions only, i.e, left, right, above, below.
2nd part : Least distance of every empty cell to the nearest door. Lots of discussion was done on both the parts of the problem.| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersMaximum triangle path Sum : Starting from the top of a pyramid of numbers like below, you can walk down going one step on the right or on the left, until you reach the bottom row:
- neer.1304 March 10, 2017 in United States
55
94 48
95 30 96
77 71 26 67
One of such walks is 55 -> 94 >- 30 -> 26. You can compute the total of the numbers you have seen in such walk, in this case it’s 205.
Your problem is to find the maximum total among all possible paths from the top to the bottom row of the triangle. In the little example above it’s 321.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - -1of 1 vote
AnswersDesign a system to upload images and tag them. Ability to search images with single and multiple tags.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 1of 1 vote
AnswersGiven a very large binary number which cannot be stored in a variable, determine the remainder of the decimal equivalent of the binary number when divided by 3. Generalize to find the remainder for any number k.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven a file having many lines of text(words) and given a dictionary having an API function boolean isValid(String word), which will return true is a word passed to this function is valid word in dic.,and will return false if given passed argument is not a valid word in dic.
- neer.1304 March 09, 2017 in United States
Now read the file and check if each word as well as all possible words from its L to R and R to L combinations, are valid words in dic. or not.| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 1of 1 vote
AnswersGiven sequentially placed boxes, each representing a number( which may be positive or negative), we need to select the numbers in order to have the maximum sum, having the constraint that if we select a given box, we cannot select adjacent box to it, but can select any other.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven 2 integers, add them without using any arithmetic operator
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersImplement a LRU cache with ttl at each block
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven some resources in the form of linked list you have to delete all the resources which sum up to 0(Zero) and return the remaining list.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersFind all anagrams of a given string in a file of size 1TB.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 1of 1 vote
AnswersGiven two strings print all possible permutations of two strings such that the order of characters are maintained.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven an array,generate all valid ip address from the array.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersFind Longest Repeated Substring in the given string.
- neer.1304 March 09, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven a equi-weighted uni directed graph and need to find the max distance possible from a given node.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersAdd 1 to the integer represented by a linked list with O(n) time, O(1) space, no recursion(stack space) and without reversing the linked list.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswerWrite a program to check whether it is a valid binary tree or not.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersMultiply two numbers represented as a linked list.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm