Google Interview Questions
- 0of 0 votes
AnswersGiven an array of words (i.e. ["ABCW", "BAZ", "FOO", "BAR", "XTFN", "ABCDEF"]), find the max value of length(s) * length(t), where s and t are words from the array. The catch here is that the two words cannot share any characters.
- supatroopa December 13, 2015 in United States
Assume that there are many words in the array (N words) and average length of word is M.
Answer for the example above is "ABCW" and "XTFN" as the result is 4 * 4 = 12.
"ABCW" and "ABCDEF" do not work since they share similar characters.| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersSimplify the implementation below as much as you can.
- noam.nta April 12, 2015 in United States
Even better if you can also improve performance as part of the simplification!
FYI: This code is over 35 lines and over 300 tokens, but it can be written in
5 lines and in less than 60 tokens.
קוד: בחר הכל
static int func(String s, char a, char b)
{
if (s.isEmpty()) return -1;
char[] strArray = string.toCharArray();
int i=0;
int aIndex=0;
int bIndex=0;
while (aIndex=0 && bIndex==0 && i<strArray.length)
{
if (strArray[i] == a)
aIndex=i;
if (strArray[i] == b)
bIndex=i;
i++;
}
if (aIndex != 0)
{
if (bIndex == 0)
return aIndex;
else
return Math.min(a, b);
}
else
{
if (bIndex != 0)
return bIndex;
else
return -1;
}
}| Report Duplicate | Flag | PURGE
Google Developer Program Engineer - 0of 0 votes
AnswersImplement a set that supports insert, remove and getRandomElement() operations.
- ak February 21, 2013 in India| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Data Structures - 0of 0 votes
AnswersWrite a function
- psuedo April 10, 2015 in India
bool fancy_shuffle(char* s);
which rearranges characters in the string given as input, in such a way that no same character occurs twice in a row (that is, next to each other).
If such rearrangement is not possible, the function should return false.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersPrint the numbers of form 2^i.5^j in increasing order. For eg:
- controlc September 18, 2011 in India
1, 2, 4, 5, 8, 10, 16, 20| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Brain Teasers - 0of 0 votes
AnswersYou are at a political convention with n delegates, each one a member of exactly one political
- rohit_dayal March 25, 2012 in United States
party. It is impossible to tell which political party any delegate belongs to; in particular, you will
be summarily ejected from the convention if you ask. However, you can determine whether any
two delegates belong to the same party or not by introducing them to each other—members of the
same party always greet each other with smiles and friendly handshakes; members of different
parties always greet each other with angry stares and insults.
(a) Suppose a majority (more than half) of the delegates are from the same political party.
Describe an efficient algorithm that identifies a member (anymember) of the majority party.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array of intergers. Write a program to print all the permutations of the numbers in the array. The output should be sorted in a non-increasing order. For example for the array { 12, 4, 66, 8, 9}, the output should be:
- Nidhi Jain September 02, 2012 in United States
9866412
9866124
9846612
....
....
1246689| Report Duplicate | Flag | PURGE
Google Arrays - 0of 0 votes
AnswersGiven two arrays A & B of length l, containing non negative integers, such that the sum of integers in A is the same as sum of integers in B.( The numbers need not be the same in both the arrays.)
- Jan November 26, 2010
Now if you start with an index 'k' in each array and do the following summation, SUMMATION (Ak-Bk), where Ak is the value at index k of array A, and Bk is the value at index k of array B, where 'k' increments and wraps back all the way to k-1, the final sum value will be zero.
Question: Find a suitable 'k' such that during any point in the summation, SUMMATION(Ak-Bk) is always non negative. Find such a 'k' in O(n) time.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
Answershow to crash your system immediately?
- Domino February 26, 2011| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Brain Teasers - 0of 0 votes
AnswersFlatten a List<List<Integer>> in Java and implement the hasNext() and next() methods.
- Ana April 23, 2013 in United States
e.g. [[6,8],4] should return true when at 6, 8 and false at 4.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 0 votes
AnswersGive two binary search trees, print the numbers of both together in ascending order.
- Softy July 21, 2011| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a binary matrix of N X N of integers , you need to return only unique rows of binary arrays
- Rahul June 09, 2011
eg:
0 1 0 0 1
1 0 1 1 0
0 1 0 0 1
1 1 1 0 0
ans:
0 1 0 0 1
1 0 1 1 0
1 1 1 0 0| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Data Structures Matrix - 0of 0 votes
AnswersYou r given a large string of characters lets call it Sbig. Then there is a small set of characters lets call it Ssmall. You have to find smallest substring of Sbig which contains all characters in Ssmall.
- GoogleInterview January 10, 2010
For example you are given Sbig = "hello what are you doing"
Ssmall= "eo"
answer is "ello"| Report Duplicate | Flag | PURGE
Google Directi Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGive a min and max of an integer array, write a function to randomly return a number inside of this range, but not in the list. Also write a class that contains this function.
- cqyanbo January 05, 2013 in United States for Google New York City| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Arrays - 0of 0 votes
AnswersGiven unsigned integer 'x', write an algorithm thet returns unsigned integer 'y' such that it has the same number of bits set as 'x' and is not equal to 'x' and the distance |x-y| is minimized.
- autoboli August 31, 2015 in United States
Example:
x: 01
y: 10
Note that one bit is set and 'x' is not equal 'y'. You may assume that x is positive integer between zero and 2^32-2;| Report Duplicate | Flag | PURGE
Google - 0of 0 votes
AnswersImplement rotate function for forward-only iterators.
- JacVlD July 31, 2012 in United States
Clarification: with O(1) additional memory. Rotate semantics should be that of std::rotate.
I personally know a O(n*log(n)) solution which takes O(log(n)) extra memory, and I assume it should be possible to reduce memory costs to O(1).| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
AnswersYou have coins with different denominations and you have limited number of each denominations (some maybe zero), how will you determine if you can supply the given change. DP , are you sure? think again.
- __coder November 13, 2011 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersWrite an 0(n) algorithm for detecting conflicts in appointments.
- jp January 06, 2011public class Appointment { long startTime; long endTime; boolean hasConflict; } public static ArrayList<Appointment> markCOnficts(ArrayList<Appointment> apntmnts) //your code here..for each appointment if it //has a conflict you need to set hasConflict //parm = true
| Report Duplicate | Flag | PURGE
Google Developer Program Engineer - 0of 0 votes
AnswersList of string that represent class names in CamelCaseNotation.
- lavankumarmuvalla July 07, 2016 in United States
Write a function that given a List and a pattern returns the matching elements.
['HelloMars', 'HelloWorld', 'HelloWorldMars', 'HiHo']
H -> [HelloMars, HelloWorld, HelloWorldMars, HiHo]
HW -> [HelloWorld, HelloWorldMars]
Ho -> []
HeWorM -> [HelloWorldMars]| Report Duplicate | Flag | PURGE
Google String Manipulation - 0of 0 votes
AnswersWrite a function that takes an array of numbers and returns the maximum and minimum values.
- trophygeek February 21, 2015 in United States
Give BigO for runtime.
(This is a basic coding question. There are no real tricks or shortcuts.)| Report Duplicate | Flag | PURGE
Google Software Engineer Coding - 0of 0 votes
AnswersGiven a matrix with 1's and 0's, find the number of groups of 1's. A group is defined by horiz/vertically adjacent 1's.
- Steve October 16, 2012 in United States| Report Duplicate | Flag | PURGE
Google Algorithm - 0of 0 votes
AnswersGiven k - which is the number of bits, print all the possible combinations of numbers formed by printing all numbers with one bit set, followed by two bits set, ... upto the point when all k-bits are set. They must be sorted according to the number of bits set, if two numbers have the same number of bits set then they should be placed as per their value.
- theconqueror May 27, 2016 in India
For example if K=3
Output:
000, 001, 010, 100,101, 110, 011, 111
0 bits set, followed by 1 bits set followed by 2 bits set followed by 3 bits set.| Report Duplicate | Flag | PURGE
Google Algorithm - 0of 0 votes
AnswersYou are given a string 's' and you are given a dictionary of english words. You goal is to write an algorithm that returns all words from the dictionary the can be formed by characters from that string 's'.
- autoboli January 07, 2015 in United States
Example:
s = "ogeg"
following words can be formed from 's': go egg ego . . .
Further it is given that string 's' always consists of four lower case characters. Lets say that the dictionary is contained in a file and can be fitted in the memory. It is up to you which data structure you use to represent the dictionary.
How would you design an efficient algorithm? Follow up: What if the dictionary file can not be fitted in the memory?| Report Duplicate | Flag | PURGE
Google - 0of 0 votes
AnswersSuppose you have a million integer numbers.
- l33t June 14, 2014 in United States for Hangouts
Return all possible values of a,b and c such that
a+b+c<=d.
d will be provided to you.
ex: if the numbers are 1,2,3,4,5,6,7
and d=7
[1,2,3]
[1,2,4]
[1,2,3] will be same as [1,3,2] and [3,2,1]...
follow up:
Return all such parts that satisfy the above condition if d is not provided.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
Answersgiven a maze (matrix bool[N][M]) where 0 = free way, 1= obsticle - How many ways are there to reach from [0][0] to [N][M]? write a non-recursive solution.
- adam2008 February 16, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
AnswersYou are given an array A of k values which contain int values in sorted (asec) order. Find top k values (asec) which can either be the number from the array A, or sum of any two numbers from A or sum of any three numbers from A. So, if A's values are represented as : a1,a2,...,ak , the possible numbers can be: a(i), a(i)+a(j), a(i)+a(j)+a(l) for any i,j,l < k
- mexx April 08, 2011
Ex: A[7] = {3,4,5,15,19,20,25}
output B[7] = {3,4,5,(3+4),(3+5),(4+5),(3+4+5)}| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
AnswersGive an unsorted array find count of pairs of numbers[a,b] where a > b and b comes after a in the array.
- Software Engineer June 20, 2010
Eg. {8,3,6,10,5}
the count of such numbers is 5. i.e. (8,3), (8,6), (8,5), (6,5) and (10,5)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm