Recent Interview Questions
- 4of 4 votes
AnswersGiven an unordered array of positive integers, create an algorithm that makes sure no group of integers of size bigger than M have the same integers.
- Fred_Castro January 22, 2014 in United States
Input: 2,1,1,1,3,4,4,4,5 M = 2
Output: 2,1,1,3,1,4,4,5,4| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 4 votes
AnswersRearrange characters in a string so that no character repeats twice.
- pcinterview October 10, 2015 in United States
Input: aaabc
Output: abaca
Input: aa
Output: No valid output
Input: aaaabc
Output: No valid output| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 4of 4 votes
AnswersPrint combinations of strings from List of List of String
- mohrmanla October 23, 2014 in United States
Example input: [[quick, slow], [brown, red], [fox, dog]]
Output:
quick brown fox
quick brown dog
quick red fox
quick red dog
slow brown fox
slow brown dog
slow red fox
slow red dog| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 4of 4 votes
AnswersSparse number is an integer if there are no adjacent 1 in it's binary representation.
- Rahul Sharma March 30, 2015 in United States
Like: 5 -> 101 (no adjacent 1)
9 -> 1001 (no adjacent 1)
while 6-> 110 is not sparse number.
Now you are given an integer find the NEXT BIGGER sparse number.Please mind 'it is next bigger'.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - 4of 4 votes
AnswersGiven a polygon with N vertexes and N edges. There is an int number(could be negative) on every vertex and an operation in set(*,+) on every edge. Every time, we remove an edge E from the polygon, merge the two vertexes linked by the edge(V1,V2) to a new vertex with value: V1 op(E) V2. The last case would be two vertexes with two edges, the result is the bigger one.
- zilchistDeepblue January 15, 2013 in United States
Return the max result value can be gotten from a given polygon.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 4 votes
AnswersGiven a list of strings, return a list of lists of strings that groups all anagrams.
- tirelative December 13, 2014 in United States
Ex. given {trees, bike, cars, steer, arcs}
return { {cars, arcs}, {bike}, {trees, steer} }
m = # of words
n = length of longest word
I solved this in O(m * n * log n) time.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 4of 4 votes
AnswersTwo finite, strictly increasing, integer sequences are given. Any common integer between the two sequences constitute an intersection point. Take for example the following two sequences where intersection points are
- blackfever June 29, 2014 in India
printed in bold:
First= 3 5 7 9 20 25 30 40 55 56 57 60 62
Second= 1 4 7 11 14 25 44 47 55 57 100
You can ‘walk” over these two sequences in the following way:
1. You may start at the beginning of any of the two sequences. Now start moving forward.
2. At each intersection point, you have the choice of either continuing with the same sequence you’re currently on, or switching to the other sequence.
The objective is finding a path that produces the maximum sum of data you walked over. In the above example, the largest possible sum is 450 which is the result of adding 3, 5, 7, 9, 20, 25, 44, 47, 55, 56, 57, 60, and 62
this is the same problem which I saw in SPOJ Problem Set| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 4of 4 votes
AnswersGiven a random generator rand(5) which generates numbers between 0 to 4. How do u generate numbers between 0 to 6, I.e. Implement rand(7).
- hulk April 16, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Brain Teasers - 4of 4 votes
AnswersGiven a current absolute path, e.g., "/usr/bin/mail", and a relative one, e.g, "../../../etc/xyz/../abc" return the absolute path created from the combination of the first two paths. In the example strings, the answer should be "/etc/abc".
- meh March 24, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 4 votes
AnswersGiven an integer array. Perform circular right shift by n.
- wolfengineer November 09, 2013 in United States
Give the best solution.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 4of 4 votes
AnswersI Got this Crazy Question on PHONE INTERVIEW AT GOOGLE:
- hhh April 11, 2013 in United States
Design and implement a class to generate random numbers in an arbitrary probability distribution given by an array of integer weights, i.e. for int[] w return a number, n, from 0 to w.length - 1 with probability w[n] / sum(w). Using an existing random number generator with a uniform distribution is permitted.
Example distribution:
w = 1, 2, 3, 2, 1
Example probabilities:
w / sum = 1/9, 2/9, 1/3, 2/9, 1/9
Example results:
n = 0, 1, 2, 3, 4
Documentation:
Class java.util.Random
public int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All n possible int values are produced with (approximately) equal probability.
Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
the next pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive) from this random number generator's sequence
Throws:
IllegalArgumentException - if n is not positive| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 4of 4 votes
AnswersGiven an array Of integers build a new array of integers such that every 2nd element of the array is greater than its left and right element.
- Gaurav Shah March 17, 2015 in United States for Chrome Team
eg:
[1,4,5,2,3]
o/p:
[1,4,2,5,3]
Soln proposed:
Step 1:Sort The array -> O(nlogn)
Step 2:Use 2 indices: one starting at leftmost index and other at rightmost index.
and populate the new array alterntely using the left pointer(index) first and then the right pointer and then increment the pointer used. till both the pointers meet/cross each other. -> O(n).| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 4of 4 votes
AnswersGiven an m x n matrix where each row element is sorted, but the columns do not appear in sorted order, write a function to print each matrix element in sorted order.
- seanchen11235 March 06, 2015 in United States
Example matrix:
matrix = [
[20, 40, 80],
[5, 60, 90],
[45, 50, 55]
]
Your function should print 5, 20, 40, 45, 50, 55, 60, 80, 90.
Add on: Assume that we are space-constrained such that we can only hold one row in memory at a time. Optimize your function to work under such constraints as efficiently as possible.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 4 votes
Answersgive an algorithm for finding duplicate parenthesis in a expression.
example :
- rahul May 02, 2014 in United States(( a + b ) + (( c + d )))
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Stacks - 4of 4 votes
AnswersReplace element of an Array with nearest bigger number at right side of the Array in O(n)
- SachinG2 October 23, 2013 in India
For example if the input Array is
7, 5, 6, 3, 4, 1, 2, 9, 11
output array should be
9, 6, 9, 4, 9, 2, 9, 11, 11| Report Duplicate | Flag | PURGE
PayPal Member Technical Staff Algorithm - 4of 4 votes
AnswersGiven a list of integers, find the highest value obtainable by concatenating these together.
- GAGA November 20, 2015 in United States
For example, given 9, 918, 917 - The answer is 9918917.
But given 1,112,113 - The answer is 1131121| Report Duplicate | Flag | PURGE
Google - 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 - 4of 4 votes
AnswersWe have 25 horses and we need to find top 5 fastest horses irrespective of order, in a race only 5 horse can run. how many min races required to know top 5 horses...out of top 5 ordering not matter...u not need to tell which is fastest which is at second position.....
- Kavita June 03, 2014 in India| Report Duplicate | Flag | PURGE
Samsung Intern - 4of 4 votes
AnswersYou are given an unsorted sequence of integers 'a'. Find the longest subsequence 'b' such that elements of this subsequence are strictly increasing numbers. Elements in the subsequence 'b' must appear in the same relative order as in the sequence 'a'. You may assume that 'a' can fit to the memory.
- autoboli February 24, 2015 in United States
Example:
input: a = [-1 2 100 100 101 3 4 5 -7]
output: b = [-1 2 3 4 5]| Report Duplicate | Flag | PURGE
Google - 4of 4 votes
AnswersYou are given an array of integers 'a' that can fit in a memory. Write a method that retuns an array of the same lenght such that each element 'i' of this array is a sum of 'a' except the element a[i]. You are not allowed to use '-' operator.
- autoboli January 13, 2015 in United States| Report Duplicate | Flag | PURGE
Google - 4of 4 votes
AnswersGiven arrays for N (>= 2) users, each representing the IDs of hotels visited, find the common IDs of the hotels visited amongst the users.
- PraTrick April 26, 2017 in India
Input:
userA = { 2, 3, 1 }
userB = { 2, 5, 3 }
userC = { 7, 3, 1 }
Output:
{3}
Assumptions:
Arrays are unsorted.
Cases:
1) Each array consists of distinct hotel IDs
2) Each array may contain duplicate hotel IDs| Report Duplicate | Flag | PURGE
Booking.com Software Engineer / Developer - 4of 4 votes
AnswersWe are given a set of integers with repeated occurences of elements. For Example, S={1,2,2}.
- sc.shobhit September 14, 2013 in India
We need to print the power set of S ensuring that the repeated elements of the power set are printed only once.
For the above S, the power set will be {NULL, {1}, {2}, {2}, {1,2}, {1,2}, {2,2}, {1,2,2}}. So, as per the question requirements, we need to print {NULL, {1}, {2}, {1,2}, {2,2}, {1,2,2}}| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm Coding Trees and Graphs - 4of 4 votes
AnswersGiven the relative positions (S, W, N, E, SW, NW, SE, NE) of some pairs of points on a 2D plane, determine whether it is possible. No two points have the same coordinates.
- united November 02, 2014 in United States
e.g., if the input is "p1 SE p2, p2 SE p3, p3 SE p1", output "impossible".| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 4 votes
AnswersImplement a method called printNonComments() which prints out a extract of text with comments removed.
- Ash June 30, 2014 in UK
For example, the input:
hello /* this is a
multi line comment */ all
Should produce:
hello
all
You have access to a method called getNextLine() which returns the next line in the input string.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 4 votes
AnswersYou are given a scrambled input sentence. Each word is scrambled independently, and the results are concatenated. So:
- merlinme October 25, 2016
'hello to the world'
might become:
'elhloothtedrowl'
You have a dictionary with all words in it. Unscramble the sentence.| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer String Manipulation - 4of 4 votes
AnswersGiven the root of a binary tree containing integers, print the columns of the tree in order with the nodes in each column printed top-to-bottom.
- takepwn February 26, 2016 in United StatesInput: 6 / \ 3 4 / \ \ 5 1 0 / \ / 9 2 8 \ 7 Output: 9 5 3 2 6 1 7 4 8 0 Input: 1 / \ 2 3 / \ / \ 4 5 6 7 When two nodes share the same position (e.g. 5 and 6), they may be printed in either order: Output: 4 2 1 5 6 3 7 or: 4 2 1 6 5 3 7
| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Trees and Graphs - 4of 4 votes
AnswersCheck if two integers are equal without using any comparison operators.
- coolProgrammer August 03, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Developer Bit Manipulation - 4of 4 votes
AnswersQuestion: Two players A and B are playing a game. Pots of gold, each with
- kiran.sanni October 28, 2014 in United States
varying number of coins are placed in a single line. The rules of the game are:
1) Players play turn by turn.
2) On each turn a player can pick a pot of gold from either end of the line. He
gets all the gold in that pot. The next pot of gold on that end is now available
for picking.
What is the maximum number of gold can the first player get ?| Report Duplicate | Flag | PURGE
Google Intern Algorithm - 4of 4 votes
Answersdesign a method which consumes an integer and output the corresponding column number in Microsoft Excel ( ex. A, B, C......Z, AA, AB....ZZ....)
- chandeepsingh85 September 25, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer