Algorithm Interview Questions
- 3of 3 votes
AnswersPrint the level of friendship.
- AnonD June 24, 2015 in United States
Given a person and list of his friends, print all his friends by level of association.
The text file will be like one below
A: B,C,D
D: B,E,F
E: C,F,G
If the input is A, the out put should be:
Level 1 - B,C,D
Level 2 - E,F
Level 3 - G| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 1of 1 vote
AnswersGiven a start string, end string and a set of strings, find if there exists a path between the start string and end string via the set of strings.
- JSDUDE June 23, 2015 in United States for Customer experience
A path exists if we can get from start string to end string by changing (no addition/removal) only one character at a time. The restriction is that the new string generated after changing one character has to be in the set.
start: "cog"
end: "bad"
set: ["bag", "cag", "cat", "fag", "con", "rat", "sat", "fog"]
one of the paths: "cog" -> "fog" -> "fag" -> "bag" -> "bad"| Report Duplicate | Flag | PURGE
Walmart Labs Software Developer Algorithm String Manipulation - 0of 0 votes
AnswersGiven an array of integers (+ve & -ve) find two equal sized contiguous non-overlapping sub-arrays with maximum dot-product
- JSDUDE June 23, 2015 in United States for Customer experience| Report Duplicate | Flag | PURGE
Walmart Labs Software Developer Algorithm Arrays - 0of 0 votes
AnswersMinimize the cost to chop the log into pieces of desired lengths. The cost to cut any piece is the max of the two lengths generated out of cutting the wood. e.g. If a 14 unit log is cut into 2 pieces of lengths 6 and 8, cost is 8.
- JSDUDE June 23, 2015 in United States for Customer experience
Write a function that takes the total length of the log and an array of piece lengths and returns the cheapest sequence to do this along with the cost| Report Duplicate | Flag | PURGE
Walmart Labs Software Developer Algorithm - 0of 0 votes
AnswersSuppose you have two arrays of objects. How would you find the common elements among them? How would you optimize the solution to avoid additional space?
- Yev June 23, 2015 in United States| Report Duplicate | Flag | PURGE
Centro Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersGiven an array such that it is increasing until a point and then decreasing. Return the index of the number n in the array in sub-linear time.
- SycophantEve June 22, 2015 in United States
Ex.
[1,2,5,8,13,9,3,-1] n = 5
Output = 2
Next: Can you do it without finding the maximum element?| Report Duplicate | Flag | PURGE
Algorithm - 1of 1 vote
AnswersYou are given a bunch of nodes evenly spaced in a rectangular shape. The rectangle is M nodes long and N nodes wide. Node A is in the upper left hand corner and node B is at the bottom right hand corner. How many different paths are there from A to B?
- moonracer0120 June 21, 2015 in United States
What is a brute-force solution? What is better than a brute force solution?| Report Duplicate | Flag | PURGE
Applications Developer Algorithm - 0of 0 votes
AnswersHow to sort an array of integers using two priority queues ?
- gopi.komanduri June 20, 2015 in United States| Report Duplicate | Flag | PURGE
Analyst Algorithm - 2of 2 votes
Answersstd C library has pow(x, n) function - implement that function
- kumarr.arvind June 20, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven a N-ary Tree. Return true if it follows Sum Property otherwise false.
- chaturvediprerna03 June 17, 2015 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a collection of pair representing intervals write a function which inserts new interval into collection and merges overlapping intervals.
- Eugene June 17, 2015 in United States
Example:
[-10, -1], [0,2], [4,10]
insert [-5, 1]
output: [-10, 2], [4, 10]| Report Duplicate | Flag | PURGE
Linkedin Software Engineer Algorithm - 0of 0 votes
AnswersYou are given a String S that consists of characters '0' and '1' only.Return the smallest positive integer K such that it is possible to cut S into K pieces, each of them being a power of 5. If there is no such K, return -1 instead.
- neer.1304 June 15, 2015 in India
Examples
0)
"101101101"
Returns: 3
We can split the given string into three "101"s.
Note that "101" is 5 in binary.
1)
"1111101"
Returns: 1
"1111101" is 5^3.
2)
"110011011"
Returns: 3
Split it into "11001", "101" and "1".
3)
"1000101011"
Returns: -1
4)
"111011100110101100101110111"
Returns: 5| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Algorithm - 2of 2 votes
AnswersShuffle a given array such that each position is equally likely.
- xmlprgrm June 15, 2015 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array {1,2,3,4,5}. Sort the array based on modulo of 3.
- Lake096 June 12, 2015 in United States
Expected output => {3,1,4,2,5} (Increasing order of modulo of 3)
({3,4,1,5,2} is also a right answer)
Interviewer expects a solution with O(N) time and O(1) memory(No additional datastructure other than the input array).| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersYou have a very large array of integers. write this function
- romina June 11, 2015 in United States
boolean hasTwoNumbersThatSumValue(int[] arr, int num)| Report Duplicate | Flag | PURGE
Fabrix Software Developer Algorithm - -1of 3 votes
Answerhow to calculate ncr%p where p is not a prime
- kanhaiya.yadav47 June 11, 2015 in United States| Report Duplicate | Flag | PURGE
Dropbox Algorithm - 0of 0 votes
AnswersGiven a set of 'n' intervals S = {(starti, endi) | 1<= i <= n}
- Anand Barnwal June 10, 2015 in India
Find a maximum subset of S such that no pair of intervals in S' overlaps ?| Report Duplicate | Flag | PURGE
Microsoft Intern Algorithm - 0of 0 votes
AnswersWhat is Big-O and Big Theta notations?
- Sach June 10, 2015 in India| Report Duplicate | Flag | PURGE
Credit Suisse Tech Lead Algorithm - 10of 12 votes
AnswersGiven a max-heap represented as an array, return the kth largest element without modifying the heap. I was asked to do it in linear time, but was told it can be done in log time.
- lilzh4ng June 10, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 2 votes
AnswersGiven a sorted array, find a way to find the # of occurrence of a number
- aj June 09, 2015 in United States
for eg: [1, 1, 2, 3, 3, 3, 4, 5]
find # of occurrence of 3 in time better than O(n)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 4 votes
AnswersGiven a range of floats, find the range of size 1 with max num of elements
- aj June 09, 2015 in United States
for eg: [-13.7, -14.5, -12.3, -12.5, -12.9]
one possible answer: [-12.3, -13.3]| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswerGiven two strings, how to find the longest common substring ?
- Anand Barnwal June 09, 2015 in India
Can it be implemented using suffix tree ? If then elaborate with an example.| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm - 1of 1 vote
AnswersGiven a file, read last n lines from the file
- pc June 08, 2015 in United States
string ReadNLines(sttring fileName, int n);| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 2of 2 votes
AnswersAssume we have a very large file containing millions of lines of data. Only 2 lines are identical, rest are unique.
- Anand Barnwal June 08, 2015 in India
Each line is long enough that they may not fit in memory.
Design an efficient algorithm to determine identical lines?
And, then generalize it for 'n' identical lines.| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 0of 0 votes
AnswersMake use of an example to depict Singleton pattern. How would you make sure it works in Multithreaded environment.
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Algorithm Threads - -1of 1 vote
AnswerWrite code for reader writer (multi threading)
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Algorithm Threads - -1of 1 vote
AnswerHow would you instantiate/start/stop thread in java.
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Algorithm Threads - -1of 1 vote
AnswersExplain diff between thread vs process.
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Algorithm Threads - -1of 1 vote
AnswersI think Bloomberg heavily expects candidates to have good knowledge of Multithreading concepts as they work in financial data.
- Tom Walker June 07, 2015 in United States
Explain multithreading.| Report Duplicate | Flag | PURGE
Bloomberg LP Algorithm Threads - 0of 0 votes
Answershashmap implementation?
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Ebay Software Developer Algorithm Coding Hash Table Java