Recent Interview Questions
- 0of 0 votes
AnswersGiven 1 GB memory, input a file which contians 4 billion integers, output one integer that is not in the file. What if you have only 10 MB memory?
- AK47 November 08, 2007| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding Algorithm Math & Computation Data Structures - 1of 0 votes
AnswersImagine you have an unbalanced binary search tree. Design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you'll have D linked lists).
- Sach (Sachin) April 22, 2006
Each node in the linked list should have previous/next pointers (for the linked list) and left/right pointers (from the tree). Code this algorithm and then test it.| Report Duplicate | Flag | PURGE
Microsoft Coding Algorithm - 0of 0 votes
AnswersYou have eight balls: seven are the same weight, and one is heavier than the rest. Given a scale that only tells you which side is heavier, how do you find the heavy ball?
- SJ December 14, 2005| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers - 1of 1 vote
AnswersGiven an array of integers, design an algorithm that moves all non-zero integers to the end of the array. Minimize the number of writes or swaps.
- pygrammer January 21, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm Arrays - 2of 2 votes
AnswersGiven N stacks, each stack contains Si elements, find the maximum sum of the M numbers in the N stacks. To get the number of the stack, only supporting get the top number. For example, S=[1,200,1,2,3], if you want to get the number 200, you need choose 3,2,1 first.
- jeffrey November 28, 2016 in United States
EX:
S1=[1,1,100,3]
S2=[2000,2,3,1]
S3=[10,1,4]
the maximum sum of the 3 numbers in the above stacks is 3+100+3=107.
Any better solution for this problem?| Report Duplicate | Flag | PURGE
Google Software Engineer Dynamic Programming - 0of 0 votes
AnswersGiven Nodes such as
M-> N-> T-> D-> E | | | | C X Y L | | A Z
-> right pointer
- Raj July 14, 2016 in United States
| down pointer
Output should be
M->C->A->N->X->Z->T->Y->D-L>E
Write this to flatten
flatten(Node head) {
}
Node {
Node right;
Node down;
char a;
}| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersGiven an array of n integers. MaxPrefix is defined as count of elements those are greater than the element and in the right side of array wrt to the element. Write a program to give the max of MaxPrefix Ex. Input 10 -4 6 2 8 9 4 Output is 5
- darklight June 19, 2016 in India| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersWrite a Python program to print numbers from 1 to 100 except for multiples of 3 for which you should print "fuzz" instead, for multiples of 5 you should print 'buzz' instead and for multiples of both 3 and 5, you should print 'fuzzbuzz' instead.
- NS March 03, 2016 in United States| Report Duplicate | Flag | PURGE
JP Morgan Software Engineer / Developer Python - 0of 0 votes
Answers1. Write a function that removes the duplicate of a collection of numbers and returns the number of elements remaining in the collection after the duplicates have been removed. You must ensure that duplicates are actually removed from the list.
- laurentr September 18, 2015 in United States
Example #1
Input
{1, 1, 5, 3, 8, 3, 7, 32, 32}
Output
6
Example #2
Input
{21, 10, 24, 2, 21}
Output
4
int removeDuplicates(List numbers) {
// your code goes here
}| Report Duplicate | Flag | PURGE
Amazon Software Developer - 2of 2 votes
AnswersGiven an array of strings with only lowercase letters , create a function that returns an array of those same strings, but each string has its letters rearranged such that it becomes a palindrome (if possible, if not, return -1)
- makingworldcode September 13, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer Java - 1of 1 vote
AnswersFind a duplicates in an array of length n. The values are positive integers in the range between 1 .. n-1
- tested.candidate July 14, 2015 in Switzerland| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 26of 26 votes
AnswersIf a canoe can hold 2 kids and a max weight of 150 lbs, write a function that returns the minimum number of canoes needed, given a list of kids and their weights.
- Rando May 17, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer - 1of 1 vote
AnswersWrite a function which, given two integers (a numerator and a denominator), print the first N digits of a rational number. For example, for 5 / 3 with N=5, the result should be "1.66666". N=2: 1.66
- Dan Shah May 13, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer - 1of 1 vote
Answerswrite custom pattern match function to match following logic
.’ Matches any single character.
‘*’ Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be:
- storb99 April 07, 2015 in United Statesbool isMatch(const char *s, const char *p) Some examples: isMatch(“aa”,”a”) → false isMatch(“aa”,”aa”) → true isMatch(“aaa”,”aa”) → false isMatch(“aa”, “a*”) → true isMatch(“aa”, “.*”) → true isMatch(“ab”, “.*”) → true isMatch(“aab”, “c*a*b”) → true isMatch(“ccca”, “c*a”) → true
| Report Duplicate | Flag | PURGE
Yahoo Software Engineer Coding - 3of 5 votes
AnswersProblem Statement
- nirajkantsinha March 13, 2015 in United States
Diameter
The diameter of a graph is the maximum shortest path between any two nodes.
At the beginning, there is a simple grpah contains exactly 1 node. Then we add new nodes one by one to the graph. Each time when we add a new node to the graph, we also add exactly one edge to connect this node to another node which already exists.
We want to find the diameter of the graph each time we add a new node. Note that each edge cost 1.
Input Format:
First line of the input contains one integer N, indicating how many new nodes we will add.
Then following N lines. The ith line contains an integer X, which means we add the ith node and an edge connecting the Xth node and ith node.
The original node is the 0th node.
Output Format:
Output N lines. The ith line is an integer indicating the diameter of the graph after adding the ith node.
Constraints:
0 < N <= 100000
0 <= Xi < i
i is counting from 1
Sample Input:
5
0
0
1
1
1
Sample Output:
1
2
3
3
3
Explanation:
Firstly the graph contains only node 0. The first line of output is 1 because the diameter becomes 1 when node 1 is added and connected to node 0. Diameter becomes 2 after adding node 2 to node 0. Then adding node 3, 4, 5, all of them are connecting to node 1, caculate the shortest path of all pairs of nodes, the maximum shortest path is 3, so the last 3 lines of output are all 3.| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 2 votes
AnswersGiven an array of random integers and a sum value, find two numbers from the array that sum up to the given sum.
- shoryagupta1493 March 12, 2015 in United States for Amazon Fresh
eg. array = {2,5,3,7,9,8}; sum = 11
output -> 2,9
Implement in O(n) time complexity. Find all distinct pairs. (2,9) and (9,2) are not distinct.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven a number A, find the smallest number which has only 1s and 0s as its digits which divisible by the number A. For example: if the given number A is 4, the smallest number with 1s and 0s is which is divisible by 4 is 100.
- xyz_coder February 06, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Arrays Coding - -1of 3 votes
Answershow to print this pattern
- premnath.velmurugan March 08, 2014 in India
input N=4
output :
4444444
4333334
4322234
4321234
4322234
4333334
4444444
input N=3
output :
33333
32223
32123
32223
33333| Report Duplicate | Flag | PURGE
Software Trainee Algorithm C# Data Structures Applications Developer Java - 2of 4 votes
AnswersImagine x is an operand and * is a binary operator. We say a string of x and * follows Reverse Polish notation if it is a postfix notation.
- mahdi.oraei March 03, 2014 in United States
For example strings xx*, x, and xx*xx** follow Reverse Polish notation.
Given a string of x and *, how many insert, delete, and replace operations are needed to make the string follow the RPN.
For example, xx* need 0 operation to follow RPN since it already follows RPN.
x*x needs two operations to become xx* which follows RPN.
*xx* needs one operation to become xx* which follows RPN.
Your algorithm should work for a string of size up to 100.| Report Duplicate | Flag | PURGE
Facebook Developer Program Engineer - 2of 2 votes
Answers/**
- duskan February 22, 2014 in United States
* Returns a^b, as the standard mathematical exponentiation function
*/
public double pow(double a, int b) {}
Interviewer looking for log(n) solution, right on first attempt.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 3of 3 votes
AnswersQuestion: You are given a CSV file with 3 columns -- all integers:
- nicolasvin1982 December 05, 2013 in United States
id,parent,weight
10,30,1
30,0,10
20,30,2
50,40,3
40,30,4
0 is the assumed root node with weight 0
which describes a tree-like structure -- each line is a node, 'parent' refers to 'id' of another node.
Print out, for each node, the total weight of a subtree below this node (by convention, the weight of a subtree for node X includes the own weight of X).
You may assume that the input comes pre-parsed as a sequence of Node objects
(substitute the appropriate syntax for java/python/c++):
Node {
int id;
int parent;
int weight;
// ... you can add other fields right here, if necessary
}
implement the following:
public void printSubTreeWeight(List<Node> nodes) {
....}| Report Duplicate | Flag | PURGE
Google Senior Software Development Engineer - -1of 7 votes
AnswersFind maximum product of subarray in given array of integers
- Vin September 08, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 0of 0 votes
AnswersGiven:You have given Amazon's stock prices for next 10 days
- PKT July 23, 2013 in United States
Find out: max benefit in best time complexity to buy and sell 1 share
Condition: Share must be sold any day after buying date.
For ex:
Share in thousands
5 1 4 6 7 8 4 3 7 9
Max benefit 9 - 1 = 8 thousand| Report Duplicate | Flag | PURGE
Amazon Applications Developer Algorithm - 1of 9 votes
AnswersGiven one egg and a building with infinite number of floors. Find out minimum number of throws at which (least) floor egg will break, if thrown?
- Nitin Gupta July 19, 2013 in India for Illustrator
I said we have to start at floor 1 and keep incrementing and testing by moving 1 floor up. Then he said optimize it by minimizing no of throws. I could not find more optimal way. I told him that I know with problem with 2 eggs and finite floor building.
Then, he told me that now lets there are 2 eggs and infinite floor building, find minimum no if throws required to find least floor at which egg breaks.
I still could not do that for infinite floors.| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Brain Teasers - 1of 1 vote
AnswersGiven a sorted array, write a function to search first occurrence of a number in the array. If not found return -1.
- piyush290490 May 27, 2013 in India
Example::
{2,2,2,3,4,5,5,6,6,8,9}
search 6
should return 7.| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - 0of 0 votes
AnswersHow to find a missing value in an size N unsorted array (value from 0 to N but missing one of them).
- cronaldo March 28, 2013 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer - 1of 1 vote
AnswersGiven a string, find the start position of the largest block of repeated charactes.
- hnrqbaggio January 24, 2013 in United States for Office
After the solution, I was asked to write down as many test cases I could to test the function as if it was created by someone else.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm Microsoft String Manipulation Testing - 8of 8 votes
AnswersPrint all valid phone numbers of length n subject to following constraints:
- cee.el.dg January 17, 2013 in India
1.If a number contains a 4, it should start with 4
2.No two consecutive digits can be same
3.Three digits (e.g. 7,2,9) will be entirely disallowed, take as input| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Coding - 0of 0 votes
AnswersYou are given a squared integer matrix of nxn size in which all rows and all columns
- alljunkmail000 January 06, 2013 in United States
are sorted in ascending order. The task is to check if the given matrix contains a given key.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm