You are on page 1of 4

Google Interview Questions: Software Engineer

Why are manhole covers round?


What is the difference between a mutex and a semaphore? Which one would you use to protect access to an
increment operation?
man pushed his car to a hotel and lost his fortune! What happened?
Explain the significance of "dead beef#!
Write a $ program which measures the the speed of a context switch on a %&I'()inux system!
Given a function which produces a random integer in the range * to +, write a function which produces a random
integer in the range * to -!
.escribe the algorithm for a depth/first graph traversal!
.esign a class library for writing card games!
0ou need to chec1 that your friend, 2ob, has your correct phone number, but you cannot as1 him directly! 0ou
must write a the 3uestion on a card which and give it to Eve who will ta1e the card to 2ob and return the answer to
you! What must you write on the card, besides the 3uestion, to ensure 2ob can encode the message so that Eve
cannot read your phone number?
4ow are coo1ies passed in the 4556 protocol?
.esign the SQ) database tables for a car rental database!
Write a regular expression which matches a email address!
Write a function f7a, b8 which ta1es two character string arguments and returns a string containing only the
characters found in both strings in the order of a! Write a version which is order &/s3uared and one which is order
&!
0ou are given a the source to a application which is crashing when run! fter running it *9 times in a debugger,
you find it never crashes in the same place! 5he application is single threaded, and uses only the $ standard library!
What programming errors could be causing this crash? 4ow would you test each one?
Explain how congestion control wor1s in the 5$6 protocol!
In :ava, what is the difference between final, finally, and finali;e?
What is multithreaded programming? What is a deadloc1?
Write a function 7with helper functions if needed8 called to Excel that ta1es an excel column value 7,2,$,.<
,2,$,< !!8 and returns a corresponding integer value 7=*,2=>,< =>?!!8!
0ou have a stream of infinite 3ueries 7ie: real time Google search 3ueries that people are entering8! .escribe how
you would go about finding a good estimate of *999 samples from this never ending set of data and then write code
for it!
5ree search algorithms! Write 2@S and .@S code, explain run time and space re3uirements! Aodify the code to
handle trees with weighted edges and loops with 2@S and .@S, ma1e the code print out path to goal state!
0ou are given a list of numbers! When you reach the end of the list you will come bac1 to the beginning of the list
7a circular list8! Write the most efficient algorithm to find the minimum B in this list! @ind any given B in the list! 5he
numbers in the list are always increasing but you donCt 1now where the circular list begins, ie: DE, F9, ++, EG, ?, *D,
>9, >D, D?!
.escribe the data structure that is used to manage memory! 7stac18
WhatCs the difference between local and global variables?
If you have * million integers, how would you sort them efficiently? 7modify a specific sorting algorithm to solve
this8
In :ava, what is the difference between static, final, and const! 7if you donCt 1now :ava they will as1 something
similar for $ or $HH8!
5al1 about your class proIects or wor1 proIects 7pic1 something easy8< then describe how you could ma1e them
more efficient 7in terms of algorithms8!
Suppose you have an &x& matrix of positive and negative integers! Write some code that finds the sub/matrix
with the maximum sum of its elements!
Write some code to reverse a string!
Implement division 7without using the divide operator, obviously8!
Write some code to find all permutations of the letters in a particular string!
What method would you use to loo1 up a word in a dictionary?
Imagine you have a closet full of shirts! ItCs very hard to find a shirt! So what can you do to organi;e your shirts
for easy retrieval?
0ou have eight balls all of the same si;e! - of them weigh the same, and one of them weighs slightly more! 4ow
can you fine the ball that is heavier by using a balance and only two weighings?
What is the $/language command for opening a connection with a foreign host over the internet?
.esign and describe a system(application that will most efficiently produce a report of the top * million Google
search re3uests! 5hese are the particulars: *8 0ou are given *> servers to wor1 with! 5hey are all dual/processor
machines with FGb of JA, FxF99G2 hard drives and networ1ed together!72asically, nothing more than high/end
6$Cs8 >8 5he log data has already been cleaned for you! It consists of *99 2illion log lines, bro1en down into *> D>9
G2 files of F9/byte search terms per line! D8 0ou can use only custom written applications or available free open/
source software!
5here is an array K&L of & numbers! 0ou have to compose an array MutputK&L such that MutputKiL will be e3ual
to multiplication of all the elements of K&L except KiL! @or example MutputK9L will be multiplication of K*L to
K&/*L and MutputK*L will be multiplication of K9L and from K>L to K&/*L! Solve it without division operator and
in M7n8!
5here is a lin1ed list of numbers of length &! & is very large and you donCt 1now &! 0ou have to write a function
that will return 1 random numbers from the list! &umbers should be completely random! 4int: *! %se random
function rand78 7returns a number between 9 and *8 and irand78 7return either 9 or *8 >! It should be done in M7n8!
@ind or determine non existence of a number in a sorted list of & numbers where the numbers range over A, ANN
& and & large enough to span multiple dis1s! lgorithm to beat M7log n8 bonus points for constant time algorithm!
0ou are given a game of 5ic 5ac 5oe! 0ou have to write a function in which you pass the whole game and name of
a player! 5he function will return whether the player has won the game or not! @irst you to decide which data
structure you will use for the game! 0ou need to tell the algorithm first and then need to write the code! &ote: Some
position may be blan1 in the game So your data structure should consider this condition also!
0ou are given an array Ka* 5o anL and we have to construct another array Kb* 5o bnL where bi = a*Oa>O<Oan(ai!
you are allowed to use only constant space and the time complexity is M7n8! &o divisions are allowed!
4ow do you put a 2inary Search 5ree in an array in a efficient manner! 4int :: If the node is stored at the ith
position and its children are at >i and >iH*7I mean level order wise8Its not the most efficient way!
4ow do you find out the fifth maximum element in an 2inary Search 5ree in efficient manner! &ote: 0ou should
not use use any extra space! i!e sorting 2inary Search 5ree and storing the results in an array and listing out the fifth
element!
Given a .ata Structure having first n integers and next n chars! = i* i> iD < i& c* c> cD < c&!Write an in/
place algorithm to rearrange the elements of the array ass = i* c* i> c> < in cn
Given two se3uences of items, find the items whose absolute number increases or decreases the most when
comparing one se3uence with the other by reading the se3uence only once!
Given 5hat Mne of the strings is very very long , and the other one could be of various si;es! Windowing will
result in M7&HA8 solution but could it be better? Aay be &logA or even better?
4ow many lines can be drawn in a >. plane such that they are e3uidistant from D non/collinear points?
)etCs say you have to construct Google maps from scratch and guide a person standing on Gateway of India
7Aumbai8 to India Gate7.elhi8! 4ow do you do the same?
Given that you have one string of length & and A small strings of length )! 4ow do you efficiently find the
occurrence of each small string in the larger one?
Given a binary tree, programmatically you need to prove it is a binary search tree!
0ou are given a small sorted list of numbers, and a very very long sorted list of numbers P so long that it had to be
put on a dis1 in different bloc1s! 4ow would you find those short list numbers in the bigger one?
Suppose you have given & companies, and we want to eventually merge them into one big company! 4ow many
ways are theres to merge?
Given a file of F billion D>/bit integers, how to find one that appears at least twice?
Write a program for displaying the ten most fre3uent words in a file such that your program should be efficient in
all complexity measures!
.esign a stac1! We want to push, pop, and also, retrieve the minimum element in constant time!
Given a set of coin denominators, find the minimum number of coins to give a certain amount of change!
Given an array, i8 find the longest continuous increasing subse3uence! ii8 find the longest increasing subse3uence!
Suppose we have & companies, and we want to eventually merge them into one big company! 4ow many ways
are there to merge?
Write a function to find the middle node of a single lin1 list!
Given two binary trees, write a compare function to chec1 if they are e3ual or not! 2eing e3ual means that they
have the same value and same structure!
Implement put(get methods of a fixed si;e cache with )J% replacement algorithm!
0ou are given with three sorted arrays 7 in ascending order8, you are re3uired to find a triplet 7 one element from
each array8 such that distance is minimum!
.istance is defined li1e this : If aKiL, bKIL and cK1L are three elements then distance=max7abs7aKiL/bKIL8,abs7aKiL/
cK1L8,abs7bKIL/cK1L88# 6lease give a solution in M7n8 time complexity
4ow does $HH deal with constructors and deconstructors of a class and its child class?
Write a function that flips the bits inside a byte 7either in $HH or :ava8! Write an algorithm that ta1e a list of n
words, and an integer m, and retrieves the mth most fre3uent word in that list!
WhatCs > to the power of ?F?
Given that you have one string of length & and A small strings of length )! 4ow do you efficiently find the
occurrence of each small string in the larger one?
4ow do you find out the fifth maximum element in an 2inary Search 5ree in efficient manner!
Suppose we have & companies, and we want to eventually merge them into one big company! 4ow many ways
are there to merge?
5here is lin1ed list of millions of node and you do not 1now the length of it! Write a function which will return a
random number from the list!
0ou need to chec1 that your friend, 2ob, has your correct phone number, but you cannot as1 him directly! 0ou
must write a the 3uestion on a card which and give it to Eve who will ta1e the card to 2ob and return the answer to
you! What must you write on the card, besides the 3uestion, to ensure 2ob can encode the message so that Eve
cannot read your phone number?
4ow long it would ta1e to sort * trillion numbers? $ome up with a good estimate!
Mrder the functions in order of their asymptotic performance: *8 >Qn >8 nQ*99 D8 nR F8 nQn
5here are some data represented by7x,y,;8! &ow we want to find the Sth least data! We say 7x*, y*, ;*8 N 7x>, y>,
;>8 when value7x*, y*, ;*8 N value7x>, y>, ;>8 where value7x,y,;8 = 7>Qx8O7DQy8O7+Q;8! &ow we can not get it by
calculating value7x,y,;8 or through other indirect calculations as lg7value7x,y,;88! 4ow to solve it?
4ow many degrees are there in the angle between the hour and minute hands of a cloc1 when the time is a 3uarter
past three?
Given an array whose elements are sorted, return the index of a the first occurrence of a specific integer! .o this
in sub/linear time! I!e! do not Iust go through each element searching for that element!
Given two lin1ed lists, return the intersection of the two lists: i!e! return a list containing only the elements that
occur in both of the input lists!
WhatCs the difference between a hashtable and a hashmap?
If a person dials a se3uence of numbers on the telephone, what possible words(strings can be formed from the
letters associated with those numbers?
4ow would you reverse the image on an n by n matrix where each pixel is represented by a bit?
$reate a fast cached storage mechanism that, given a limitation on the amount of cache memory, will ensure that
only the least recently used items are discarded when the cache memory is reached when inserting a new item! It
supports > functions: String get75 t8 and void put7String 1, 5 t8!
$reate a cost model that allows Google to ma1e purchasing decisions on to compare the cost of purchasing more
JA memory for their servers vs! buying more dis1 space!
.esign an algorithm to play a game of @rogger and then code the solution! 5he obIect of the game is to direct a
frog to avoid cars while crossing a busy road! 0ou may represent a road lane via an array! Generali;e the solution for
an &/lane road!
What sort would you use if you had a large data set on dis1 and a small amount of ram to wor1 with?
What sort would you use if you re3uired tight max time bounds and wanted highly regular performance!
4ow would you store * million phone numbers?
.esign a >. dungeon crawling game! It must allow for various items in the ma;e P walls, obIects, and computer/
controlled characters! 75he focus was on the class structures, and how to optimi;e the experience for the user as s(he
travels through the dungeon!8
What is the si;e of the $ structure below on a D>/bit system? Mn a ?F/bit?
struct foo T
char aU
charO bU
VU

Google Interview: Software Engineer in 5est
Efficiently implement D stac1s in a single array!
Given an array of integers which is circularly sorted, how do you find a given integer!
Write a program to find depth of binary search tree without using recursion!
@ind the maximum rectangle 7in terms of area8 under a histogram in linear time!
Aost phones now have full 1eyboards! 2efore there there three letters mapped to a number button! .escribe how
you would go about implementing spelling and word suggestions as people type!
.escribe recursive mergesort and its runtime! Write an iterative version in $HH(:ava(6ython!
4ow would you determine if someone has won a game of tic/tac/toe on a board of any si;e?
Given an array of numbers, replace each number with the product of all the numbers in the array except the
number itself OwithoutO using division!
$reate a cache with fast loo1 up that only stores the & most recently accessed items!
4ow to design a search engine? If each document contains a set of 1eywords, and is associated with a numeric
attribute, how to build indices?
Given two files that has list of words 7one per line8, write a program to show the intersection!
What 1ind of data structure would you use to index annagrams of words? e!g! if there exists the word "top# in the
database, the 3uery for "pot# should list that!

You might also like