Algorithm Interview Questions
- 2of 2 votes
AnswersGiven an undirected graph and a node, modify the graph into a directed graph such that, any path leads to one particular node.
- neer.1304 December 25, 2015 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer 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 - 2of 2 votes
AnswersGiven a lane where there are various houses each containing a fixed amount of gold. Now a robber has to rob the houses such that when he robs a house the adjacent one cannot be robbed.Calculate the maximum amount of gold collected by him.
- kri1311 May 27, 2015 in India| Report Duplicate | Flag | PURGE
Flipkart SDE1 Algorithm - 2of 2 votes
AnswersDesign a parking lot system where you need to provide a token with the parking space number on it to each new entry for the space closest to the entrance.
- duskan February 13, 2014 in United States for Sales
When someone leave you need update this space as empty.
What data structures will you use to perform the closest empty space tracking, plus finding what all spaces are occupied at a give time.| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer Algorithm - 2of 2 votes
Answers1. Which of the following regular expressions denotes zero or more instances of an a or b?
- !@# June 07, 2013 in India
a) a l b
b) (ab)*
c) (a l b)*
d) a* l b| Report Duplicate | Flag | PURGE
Algorithm - 2of 2 votes
AnswersGiven a pre-order traversal, construct a binary search tree in O(n) time.
- neer.1304 September 04, 2017 in United States| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 2of 2 votes
Answers2.1 career discussion
- aonecoding July 15, 2017 in United States
2.2 divide two numbers with no / or %| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 2of 2 votes
AnswersGiven a 'friendship' graph, how would you generate friend suggestions for people, and how would you distribute the data across machines?
- nr June 04, 2013 in United States for google map| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 2of 2 votes
AnswersWrite a program to find out if the binary tree is balance or not. The tree is balance if the difference between the
- india.tp.1976 January 21, 2012 in United States
left node and right node is equal or less than 1. The above considition is applicable for subtree too..
If tree do not have any child, its height will be zero.
What is the order of above program| Report Duplicate | Flag | PURGE
IBM Accountant Algorithm - 2of 2 votes
AnswersHe showed me a game on his android phone. some sort of maze. There is ball at starting point ball can move in 4 direction at max if there is no wall. End point is hole you need to write code to solve this problem. Idea is convert it into graph and do the DFS to find the path from start to end.
- MaYanK July 29, 2010| Report Duplicate | Flag | PURGE
Google Developer Program Engineer Algorithm - 2of 2 votes
AnswersGiven an infinite chessboard, find minimum no. of steps for a knight to reach from the origin to (x, y).
- neer.1304 July 03, 2019 in United States
Extension A list of forbidden coordinates are introduced where knight can’t reach. Handle this in your code. Make sure the infinite loop is handled since the board is infinite.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersRound1
- aonecoding August 09, 2017 in United States
Find if two people in a family tree are blood-related.
Round2
Given some nodes in a singly linked list, how many groups of consecutively connected nodes there is.
For linked list
0->1->2->3->4->5->6,
given nodes 1, 3, 5, 6
there are 3 groups [1], [3], and [5, 6].| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersGoogle on-site June
- aonecoding August 03, 2017 in United States
Round 1
Leetcode 10
Round 2
Select a random point uniformly within a rectangle, (The side of rectangle is parallel to the x/ y grid).
Follow-up: Given multiple non-overlapped rectangles on the 2D grid, uniformly select a random point from the rectangles.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
Answers/**
* Given a nested list of integers, returns the sum of all integers in the list weighted by their REVERSED depth.
* For example, given the list {{1,1},2,{1,1}} the deepest level is 2. Thus the function should return 8 (four 1's with weight 1, one 2 with weight 2)
* Given the list {1,{4,{6}}} the function should return 17 (one 1 with weight 3, one 4 with weight 2, and one 6 with weight 1)
- xankar March 03, 2017 in United States*/ public int reverseDepthSum (List<NestedInteger> input) { // implementation here }
| Report Duplicate | Flag | PURGE
Linkedin Backend Developer Algorithm - 2of 2 votes
AnswersWrite a function that receives a position in 2 dimensional (x,y) array, which was initially initialized with 'o' (signals "water"), the function changes the value/state of that position to 'x' (signals "land") and returns the number of isles in the board.
- vesh February 08, 2017 in Irland
For example, for 3x3 board, it will initially look like the following:
o o o
o o o
o o o
After calling the function with the position (1,2), the board will look like the following:
o o x
o o o
o o o
and the functions returns 1
An isle is defined as 'x' surrounded horizontally and vertically with 'o'
In the following board there is only one isle
o o o
o x x
o x o| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer Algorithm - 2of 2 votes
AnswersInterview gave towers of Honai with 4 pegs namely: source, helper1, helper2, destination.
- poorna.chandra.akp April 28, 2014 in India
What are the minimum number of steps to move N number of discs from source to destination.
he was looking for a recursive function which defines the number of moves required for N and the minimum value for that function.| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Algorithm - 2of 2 votes
AnswersPrint array in spiral
- Shyam November 23, 2013 in India for Kindle
123
894
765
Output: 123456789| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Algorithm - 2of 2 votes
AnswersYou have a 3x3 grid. In each cell you can have two colors, white or black. At the beginning, the matrix has some cells painted white and others black.
- neer.1304 April 21, 2019 in United States
If you change a color cell, that is, grid [i] [j] the cells grid [i-1] [j], grid [i + 1] [j], grid [i] [j-1] and grid [ i] [j + 1] also change (if these positions do not leave the 3x3 grid), that is, if they were white, they change to black.
Return, the minimum number of cells you have to flip for the 3x3 grid to be totally white. If you cannot do this, return -1!
Sample input/output - ibb.co/3Y0WVNR| Report Duplicate | Flag | PURGE
Google SDE-2 Algorithm - 2of 2 votes
AnswersRound3
- aonecoding August 09, 2017 in United States
For N light bulbs, implement two methods
I. isOn(int i) - find if the ith bulb is on or off.
II. toggle(int start, int end)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersGiven an array of numbers, find the maximum and minimum sum of sub sequences at a distance > m
- nitinsharma021 July 25, 2016 in India
Example –
arr = {3, 4, -2, 1, -2, 4, 6, -3, 5} & m = 2
Solution – max = 13 {4 + 4 + 5}, min = -5 {-2-3}| Report Duplicate | Flag | PURGE
Deshaw Inc Algorithm - 2of 2 votes
AnswersWrite a function to detect the number of cycles in a directed graph. The graph is passed as an adjacency matrix.
- Anand Barnwal October 27, 2015 in India| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 2of 2 votes
AnswersDesign and Implement a Telephone database structure in which a Customer Entry has PhoneNum,Name,Address.
- R@M3$H.N December 31, 2014 in United States
a) Given any PhoneNum return all the Customer details
b) Given any Name list all the Entries (As Name can be duplicate, only PhoneNum is unique)
c) Also Name searching should support Prefix Based.| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Algorithm - 2of 2 votes
AnswersDesign an iterator for a given stream of integers, with next() and hasnext() being called in any sequence, but skipping any 0's in the stream.
- duskan March 20, 2014 in United States for Ad| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm - 2of 2 votes
AnswersCreate a data structure that has fast insertion, removal, membership testing, and random selection.
- / February 21, 2014 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersRound 3
- aonecoding August 03, 2017 in United States
Given a matrix of 0s and 1s where 0 is wall and 1 is pathway, print the shortest path from the first row to the last row.
Can walk to the left, top, right, bottom at any given spot.
Follow-up:
If every pathway takes a cost (positive integer) to get through, print the minimum cost path from the first row to the last row.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersApple Map Team
- aonecoding July 25, 2017 in United States
1. Given an array A and some queries, query(i, j) returns the result of Ai*...*Aj, in other words the multiplication from Ai to Aj.
The numbers in A are non-negative.
Implement query(i, j).
2. Flatten nested linked list
3. POI search design
4. LC238 & LC279| Report Duplicate | Flag | PURGE
Apple Software Engineer Algorithm - 2of 2 votes
AnswersGiven infinite supply of coins of denominations 25, 10, 5 and 1, find the distinct number of ways to use the coins to sum up to the given value
- rajansthapit October 10, 2016 in United States| Report Duplicate | Flag | PURGE
Adobe Software Engineer Algorithm - 2of 2 votes
AnswersFind the minimum (index) distance sum of 3 words. For example: arr = {"2", "1", "0", "2", "0", "3", "0"}, input = "1","2","3". The result should be 8 since the 2nd "2" and "1", "3"'s distance are 3, 1, 5 and abs(3,1)+abs(3,5)+abs(5,1)=8.
- lifeGoGoGo April 01, 2016 in United States
Implement this in O(N)| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 2of 2 votes
AnswersGiven an array of integers find the element for which the sum of left = sum of right. example -1 100 1 98 1 should return index of 1 i.e 2
Answer: First told him about Brute Force approach and then told him if we can iterate once and get the total sum
- Mumbaiya_Chori January 19, 2015 in India for Machine learningint findIndex(A){ int sum =0; for(int i =0;i<A.lenght;i++) { sum+= A[i]; } int lSum=0; for(int i=0;i<A.length;i++) { int rsum = sum - lsum-A[i]; if(lsum==rsum) return i; lsum += A[i]; } return -1; }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm