Algorithm Interview Questions
- 0of 0 votes
AnswersA list of students and their marks in three subjects are given in the respective order.
- Tywin lannister December 13, 2016 in India
Student1 20 40 65
Student2 35 40 50
Student3 10 55 65
Given n = 2.
Find the name of the students who has got top marks in atleast n subjects.
Output for the above example
student1
student3
since they got top marks in atleast 2 subjects| Report Duplicate | Flag | PURGE
ThoughtWorks Applications Developer Algorithm - 0of 0 votes
AnswersIf you can hop 1, 2, or 3 steps at a time, calculate the total number of possible combinations for `n` steps.
- noitidart December 10, 2016 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer Algorithm - 0of 0 votes
AnswersFind longest consecutive path in a binary tree.
- wtcupup2017 December 10, 2016 in United States
1. the path can be decreasing or increasing, i.e [1,2,3,4] and [4,3,2,1] are both valid
2. the path can be child-parent-child, not necessarily a parent-to-child path
similar to this question: http://www.geeksforgeeks.org/longest-consecutive-sequence-binary-tree/| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 4of 4 votes
AnswersGiven a singly linked list: 1->2->3->4->5
- rainnyforeverluv December 09, 2016 in United States
Change it to 1->5->2->4->3 using O(1) space| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersImplement delete operation for N-ary tree. Your function should return a list of roots after deletion operation. Notice that your delete function only delete one node instead of a subtree. The delete function takes a list of nodes to be deleted.
- wtcupup2017 December 09, 2016 in United Statesprivate class TreeNode { int val; TreeNode[ ] child; } List<TreeNode> delete(TreeNode root, HashSet<TreeNode> set) { }
| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
Answersgiven a stream of natural numbers ,
- salviaditya1986 December 08, 2016 in United States
and a array J contains integers in increasing orders
operations performed J = [2,3,4]
1 2 3 4 5 6 7 8 9 10…………..27....100...1111
first operation
J[0] = 2 => remove every 2nd integer
now the stream is
1 3 5 7 … 27
J[1] = 3
remove every 3rd
stream is now
1 3 7 …
3rd
given a natural number n , find if it will survive given J, or at what index it will
die.| Report Duplicate | Flag | PURGE
Amazon Software Engineer in Test Algorithm - 4of 4 votes
AnswersReturn the length of longest possible chunked palindrome string.
- AlgoBaba December 08, 2016 in United States
Examples :
Input : VOLVO
Output : 3
Explanation :
(VO)L(VO)
Input : merchant
Output : 1
Explanation : No chunks possible.
Input :
ghiabcdefhelloadamhelloabcdefghi
Output : 7
Explanation :
(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 3of 3 votes
AnswersGiven a list of manager and employee information represented in hashMap entries {AAA->BBB,CCC,EEE},{CCC->DDD}.
Print company structure tree with proper indentations. BBB, CCC and EEE directly reports to AAA, so they have one white space before "-", DDD reports to CCC, it has two whitespace before "-". The input is map<String,List<String>>
- wtcupup2017 December 08, 2016 in United States-AAA -BBB -CCC -DDD -EEE
| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersA producer continuously produces a stream of characters. There are multiple consumer threads which read the chars and match to one of known strings and increment the counter for that pattern. Write the consumer function. Show how you will synchronize and maintain parallelism.
- kgok December 06, 2016 in United States
Ex: Producer: abcdegabccaabbaacv ......
Known strings[] = {"ab", "aa", "fff" ... }
patternMatchCount[] = {3, 2, 0 ... }| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Algorithm - 1of 5 votes
AnswersFind sum of n elements after kth smallest element in BST. Tree is very large, you are not allowed to traverse the tree.
- gvikram244 December 06, 2016 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a number, return the count of numbers having non-repeating digits till that number starting from 1?
- crowdx December 04, 2016 in India| Report Duplicate | Flag | PURGE
InMobi Algorithm - 0of 0 votes
AnswerGiven the Java 8 Function interface:
- krish December 03, 2016 in United States
interface Function<T,R> {
R apply<T t>;
}
Provide code that will apply the composition of the following implementations and would have the type
Function<String, Integer>:
class GetBytes<String, byte[]> {
byte[] apply<String value> {
return value.getBytes<>;
}
}
class ArrayLength<byte[], Integer> {
Integer apply<byte[] value> {
return value.length;
}
}
If the input is “hello world” what would the expected result of the function be?| Report Duplicate | Flag | PURGE
Student freshers Algorithm - 0of 0 votes
Answershttps://www.hackerrank.com/challenges/array-and-simple-queries
- gopal.panda December 03, 2016 in United States
Given two numbers N and M. N indicates the number of elements in the array A[](1- indexed) and M indicates number of queries. You need to perform two types of queries on the array A[] .
You are given M queries. Queries can be of two types, type 1 and type 2.
Type 1 queries are represented as 1 i j : Modify the given array by removing elements from to and adding them to the front.
Type 2 queries are represented as 2 i j : Modify the given array by removing elements from to and adding them to the back.
Your task is to simply print | A[1] - A[N] | of the resulting array after the execution of M queries followed by the resulting array.
Note While adding at back or front the order of elements is preserved.| Report Duplicate | Flag | PURGE
Visa Staff Engineer Algorithm - 1of 1 vote
AnswersGiven a dictionary and an char array print all the valid words that are possible using char from the array.
- neer.1304 December 02, 2016 in United States
Ex- char[] arr = {'e','o','b', 'a','m','g', 'l'}
Dict - {"go","bat","me","eat","goal", "boy", "run"}
Print - go, me, goal.
We can pre-compute as much we want but the query time must be optimal.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 1of 1 vote
AnswersGiven a pattern and a string - find if the string follows the same pattern Eg: Pattern : [a b b a], String : cat dog dog cat
- AlgoBaba December 02, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswerGiven a matrix consisting of only 0's and 1's find the largest rectangular sub-array consisting of only 1's. Rows can be interchanged with each other and columns too can be interchanged with each other
- batman November 30, 2016 in India| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
Answersint bits(unsigned char v);
- swl91912 November 27, 2016 in Canada
Which returns number of set bits in v.
A) Optimize for memory usage:
B) Optimize for speed:| Report Duplicate | Flag | PURGE
Fortinet Software Engineer / Developer Algorithm - 0of 4 votes
AnswersGiven two pre-order traversal arrays of two binary search tree respectively, find first pair of non-matching leaves.
- wtcupup2017 November 27, 2016 in United States
Follow Up: If they are general binary trees instead of BSTs, could you solve it? give out your reason.
For the first question, I was thinking to construct two BSTs from pre-order traversal then do a leaf-level comparison. Any better solutions are welcome.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersFind out the number of ways in which two queens can be placed in a 8*8 chessboard.
- AlgoBaba November 26, 2016 in United States| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - 0of 0 votes
AnswerFind the possible (x,y) coordinates in a given 2-D chess board which are safe from the attack of a queen.
- AlgoBaba November 26, 2016 in United States| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - 0of 0 votes
Answers1. Find if two strings are palindrome
- hermione November 23, 2016 in United States
2. Given a list of strings, check if concatenating any two string would form a palindrome. Brute force way to do this is O(n^3), he asked ways to optimize this.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm - 0of 0 votes
AnswersSerialize and deserialize a binary tree
- hermione November 23, 2016 in United States| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a binary tree and a target number, return whether or not there exist a path that can create target number. All inputs are integers. Target is not a string.
- cool November 22, 2016 in United States
NOTE:: this is not path sums to target number
ex:
3
4 5
6 7 8 9
359 = return true
38 = return false
47 = return true
6 = return true| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersCombination of these two leetcode question.
- nauld November 22, 2016 in United States
Given a digital strings, find all the sentence it can represent.
Digital to letter mapping is same as telephone keypad.
Separating the letters according to a dictionary to form sentences.
https://leetcode.com/problems/letter-combinations-of-a-phone-number/
https://leetcode.com/problems/word-break-ii/| Report Duplicate | Flag | PURGE
Google SDE-3 Algorithm - 0of 2 votes
Answers// TokenBucket
- nauld November 22, 2016 in United States
// Goal: regulate a resource of some kind (1 token = 1 unit of a resource)
//
// init(start_tokens, max_tokens, fill_rate)
// get_tokens(int tokens)
// - block until those tokens are available in the token bucket
// - if number of tokens in the bucket is less than requested number of tokens, wait
// put_tokens(int tokens)
// - block until there is space in the token bucket for those tokens.
// fill_rate: x tokens per sec are added to the token bucket
Thread communication methods allowed are listed below. No thread safe collections are allowed.
// Lock()
// - lock()
// - unlock()
// ConditionVariable()
// - wait(lock, max_time_to_wait_in_secs)
// - releases lock before sleep and then reacquires lock upon waking
// - notify(): This wakes up 1 waiter on this condition variable
// - notifyAll(): Wakes up all waiters on this condition variable| Report Duplicate | Flag | PURGE
Google SDE-3 Algorithm - 0of 0 votes
AnswersGiven a list of ranges of Length N, where start and end are inclusive in the range [(5,7),(1,4),(2,3),(6,8),(3,5)]
- merchant.smeet November 20, 2016 in United States
and given any number K , lets say K=8
in an array of length K+1 find how many times each index is contained within a range in the List
lets say K=8, we will have an array (arr) from index 0 to index 8
arr[0]=0; arr[1]=1; {1 is only contained in (1,4)}
arr[2]=2; {2 is contained in (1,4) (2,3) }
arr[3]=3; {3 is contained in (1,4) (2,3) (3,5) }
arr[4]=2; {4 is contained in (1,4) (3,5)}
arr[5]=2; {5 is contained in (3,5) (5,7)}
arr[6]=2; {6 is contained in (5,7) (6,8)}
arr[7]=2; {7 is contained in (5,7) (6,8)}
arr[8]=1; {8 is contained in (6,8)}
I am looking for a O(N+K) solutio| Report Duplicate | Flag | PURGE
Algorithm - 2of 2 votes
AnswersYou are the main character in a game where you have to defeat a number of enemies in order. The player has a strength value and an initial amount of money. Each enemy also has a strength value, plus a price.
- camiloni42 November 19, 2016 in United States
When facing each enemy you can either:
1) Fight him (if your strength is enough). You keep your money.
2) Bribe him (if you have the necessary money). You subtract the enemy's price from your money, and it joins you and adds its strength to yours.
Given a starting strength and amount of money, calculate the optimal strategy and the amount of money you end with (-1 if impossible).
This can be easily solved recursively in O(2^n) basically trying out each option at every enemy. But is there a polynomial solution, maybe involving DP?| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersFinding biggest plus sign "+" in a sparse matrix(matrix with elements 0 and 1)
- wtcupup2017 November 19, 2016 in United States
For example, the biggest plus sign for following matrix is located at (2,2), with length 1 for each edge(Yes, each edge should have same length)
0 0 1 0 0 1 0
1 0 1 0 1 0 1
1 1 1 1 1 1 1
0 0 1 0 0 0 0
0 0 0 0 0 0 0
Hint: use DFS/BFS| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersYour program will simulate the creation of
- asrikanth.125 November 18, 2016 in United States
subdirectories (folders) on one of the disks of a
computer. The input file to your program,
prog5.dat, will contain a sequence of commands
that a user might enter from a command line, and
the output file prog5.out will contain the
operating system’s responses to these commands.
Below is an example of an input file, and on the
right is the listing of the corresponding output
file.
dir
mkdir sub6
mkdir sub3
mkdir sub4
dir
mkdir sub4
cd sub3
cd sub3
mkdir sub3
mkdir sub6
mkdir sub4
dir
cd sub6
mkdir sub666
dir
up
up
dir
up
Problem 5 by team X
Command: dir
Directory of root:
No subdirectories
Command: mkdir sub6
Command: mkdir sub3
Command: mkdir sub4
Command: dir
Directory of root:
sub3 sub4 sub6
Command: mkdir sub4
Subdirectory already exists
Command: cd sub3
Command: cd sub3
Subdirectory does not exist
Command: mkdir sub3
Command: mkdir sub6
Command: mkdir sub4
Command: dir
Directory of root\sub3:
sub3 sub4 sub6
Command: cd sub6
Command: mkdir sub666
Command: dir
Directory of root\sub3\sub6:
sub666
Command: up
Command: up
Command: dir
Directory of root:
sub3 sub4 sub6
Command: up
Cannot move up from root directory
End of problem 5 by team X| Report Duplicate | Flag | PURGE
Salesforce Software Developer Algorithm - 1of 1 vote
AnswersGiven a list of coin values, and quantity of each type of coin. Write a
- snakeonbasket November 18, 2016 in United States
program to return the set of all possible sums which can be made using those
coins.
ex. coins = [10, 50, 100, 500]
quantity = [5, 3, 2, 2]
sum could be 400 , 300 ,200 , 100| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm