Google Interview Questions
- 0of 0 votes
AnswersGive a chessboard, check if a group of white chesses are surrounded by all black chesses.
- ajay.raj February 14, 2018 in United States| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersGiven a list of relationship of report
- ajay.raj February 13, 2018 in United States
A reported to D, D reported to Z, who are reported to Z| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswerGive the structure of a directed graph
- ajay.raj February 13, 2018 in United States
START -> a -> b -> c -> END
If a word can start from start and end at END, then we think the word is in this diagram
For example, the string "abc" is consistent, but "ab" does not match,
Although "ab" is also inside the graph, b's next is "c" instead of END, so it's not legal word
(Note: each node can have more than one next)
1. According to the problem, design the data structure
Write a function, input is START and a string, to determine whether the string is a valid word
3. follow up, if the graph has cycle, how to do?
4. If the graph has repeated characters how to do?| Report Duplicate | Flag | PURGE
Google Java Developer - 1of 1 vote
AnswersWrite a function that takes two numbers as strings and returns the result as a string:
- NA February 12, 2018 in UK
mul(l string, r string) : string
Assume the numbers might be too large to be parsed into a variable of any numeric type the language has.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
Answershow to check is a small matrix appear in a big matrix
- ajay.raj February 12, 2018 in United States
boolean isSubmatrix(int[][] small, int[][] big)| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersYou have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery,
- ajay.raj February 12, 2018 in United States
Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work
requires that they only make one cut at a time.
It is easy to notice that different selections in the order of cutting can led to different prices. For
example, consider a stick of length 10 meters that has to be cut at 2, 4 and 7 meters from one end.
There are several choices. One can be cutting first at 2, then at 4, then at 7. This leads to a price
of 10 + 8 + 6 = 24 because the first stick was of 10 meters, the resulting of 8 and the last one of 6.
Another choice could be cutting at 4, then at 2, then at 7. This would lead to a price of 10 + 4 + 6 =
20, which is a better price.
Your boss trusts your computer abilities to find out the minimum cost for cutting a given stick.| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersA sequence of strings, printed first by column, on a screen of width K,
- ajay.raj February 06, 2018 in United States
Requires the first column of the same column by column alignment,
At least one character interval between columns and columns,
Ask how many lines at least?
such as:
The string sequence is {"abc", "de", "fghij", "k", "lmno", "p"}
The screen width is 10
The answer is at least 3 lines
abc k
de lmno
fghij p| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersGive a decimal number, such as 123. Asking a total of smaller num than 123 made up by 1 and 0 composed of decimal numbers.
- ajay.raj February 06, 2018 in United States
111, 110, 101, 100, 11, 10, 1, 0.| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersTo a word, and a map, map which is a word, ask this if a word is smash able? That is, you can smash one letter each time, and the rest of the letters can form a single word (the new word is still in the map) until it is completely hit.
- ajay.raj February 06, 2018 in United States
For example: sprint -> print -> pint -> pit -> it -> i -> ""| Report Duplicate | Flag | PURGE
Google Software Engineer - 2of 2 votes
AnswersMinimum number of swaps of chars in only one string to make two strings the same
- ajay.raj February 02, 2018 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
Answers
- ajay.raj February 01, 2018 in United StatesMatrix conversion problem. For example, give a matrix a: 1, b: 2. b: 2, c: 3 Then converted into a, b, c 1, 2, . ., 2,3
| Report Duplicate | Flag | PURGE
Google Backend Developer - 0of 0 votes
AnswersImplement a grep-like function. For example
- ajay.raj February 01, 2018 in United States
[A1 + A2, B1 + B2, C1], grep (A = A1), is to return the result that contains A1,
For example, [A1, B1, C1], [A1, B2, C1].
More tricky can be grep (A = A1, A2, B = B1), so that is included (A1 || A2) & B1.| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersGiven an array {a0, a1, a2, ... an, b0, b1, b2 ... bn},
- ajay.raj February 01, 2018 in United States
Rearrange this array into {a0, b0, a1, b1, a2, b2, ... an, bn}
inplace, O (1) space| Report Duplicate | Flag | PURGE
Google Java Developer - 1of 1 vote
AnswerSuppose there is a map with N bikes on it and now we have N individuals,
- ajay.raj February 01, 2018 in United States
Design an algorithm so that everyone can get the bike in the shortest distance| Report Duplicate | Flag | PURGE
Google Android Engineer - 0of 0 votes
AnswersGiven a string, at each time, you can move any one of the char to the front,
- ajay.raj February 01, 2018 in United States
ask you to find the minimum such move to get the target string
example
source abc, target cba :
abc -> bac -> cba
return 2| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersGive you a bunch of light bulbs. Can flip a range of open change off, turn off open, and then asked to do so k times later, just ask you a light bulb is turned on or turned off, how to do
- ajay.raj January 31, 2018 in United States| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
Answer*e*er -> peter
- ajay.raj January 31, 2018 in United States
**eue -> queue
**o
ma*
*p*a*e*
*erso*
***k*am*on
*ouse
*a*
*ur*
***igent
where there are 26 *, and we can fill all the stars in to form valid english words while using each letter once. Given this array and a dictionary how would you fill all the words in?| Report Duplicate | Flag | PURGE
Google Java Developer - -1of 3 votes
Answerspublic string stringWrap (String text, int characters)
text is an input string, characters on behalf of the output of
each line up to the number of bytes
input
- ajay.raj January 30, 2018 in United States"Thank you for shopping at the XYZ store.\n Your order has been processed successfully.\n", 20 output: "Thank you for\n shopping at the XYZ\n store.\n Your order has been\n processed\n Successfully.\n" example 2:"Hello! How are you?",6 output “Hello!\n How\n are\n you?\n"
| Report Duplicate | Flag | PURGE
Google Java Developer - -3of 3 votes
AnswersModify the following code:
def GenerateGraph(data): d = {} g = Graph() for word in data: for i in range(len(word)): bucket = word[:i] + '_' + word[i+1:] if bucket in d: d[bucket].append(word) else: d[bucket] = [word] for v in d.keys(): for word1 in d[v]: for word2 in d[v]: if word1 != word2: g.addEdge(word1,word2) return g
The objective is to find all combination of words by changing one letter at a time and adding to the graph if word exists in the dictionary.
- newbiepython January 28, 2018 in United States
We need to rewrite a different logic for the above code.| Report Duplicate | Flag | PURGE
Google Software Developer Python - 1of 1 vote
AnswersGive a string [] words,
- ajay.raj January 26, 2018 in United States
Find the shortest string [] containing the keyword inside.
example:
words: sky cloud google search sky work blue
keywords: sky blue
return: sky work blue| Report Duplicate | Flag | PURGE
Google Principal Software Engineer - 1of 1 vote
AnswerGiven an array, find the number of tuple such that A [i] + A [j] + A [k] = A [l] in an array, where i <j <k <l.
- ajay.raj January 26, 2018 in United States| Report Duplicate | Flag | PURGE
Google Data Engineer - 1of 1 vote
AnswersGiven a n-nary tree, check whether it is a mirror of itself (ie, symmetric around its center).
- ajay.raj January 26, 2018 in United States
class TreeNode {
int val;
List<TreeNode> children;
TreeNode(int val) {
this.val = val;
children = new ArrayList<>();
}
}| Report Duplicate | Flag | PURGE
Google Jr. Software Engineer - -2of 2 votes
AnswerImagine a scenario where there are N cars on an infinitely long single-lane road. Each car has a unique, permanent integer speed ranging between 1 and N, inclusive (units are irrelevant). The cars can be placed in any order along the road and then told to start driving indefinitely. Let's assume that the cars are traveling from right-to-left. So the leftmost car is at the front. Given an ordering of N cars, construct an algorithm to return an array of cluster sizes
- ajay.raj January 26, 2018 in United States
N=4
[2, 4, 1, 3] -> [2, 2]
[2, 5, 4, 3, 1] -> [4, 1]
followup:
New car speed = N+1. Given an ordering of N cars, construct an algorithm to return an array of arrays of cluster sizes that will arise when the N+1 car is inserted. The ith row in the outer array corresponds to the cluster sizes that exist when the N+1 car is inserted into the ith index
new car speed = 5
[2, 4, 1, 3] -> [[1, 2, 2], [3, 2], [3, 2], [2, 3], [2, 3]]| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersGiven one string s1, and then insert one char into this string at any place, to get s2, find the inserted char
- ajay.raj January 25, 2018 in United States
Could you do it in logn time| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersGive you a 2xN board and two kinds of tiles: 1x2 (two squares across), 2x1 (two squares up) Ask how many ways you can fill the board.
** ** * * * * ** **
Follow up is the new four kinds of tiles: L shape in different angle, , ask you how many kinds of tiles are now six
- ajay.raj January 23, 2018 in United States| Report Duplicate | Flag | PURGE
Google Data Engineer - 0of 0 votes
Answersgive a binary matrix, 0 on behalf of the sea, 1 on behalf of the land, the val also represents the height of the altitude, if a cell is originally on land and is also surrounded by eight neighbor are on land, that cell become 2, each cell and its eight neighbor elevation cannot differ by more than 1. Return to the highest altitude can take altitude (special case is if the entire matrix is 1, then it is unlimited)
- ajay.raj January 23, 2018 in United States| Report Duplicate | Flag | PURGE
Google Data Engineer - 0of 0 votes
AnswerIn the range of 0-n, return all the numbers that in the reverse can be mistaken for another number. E.g. 18 -> 81. The corner case is not counting the same number, such as 101 and not 0 at the end of the figure such as 60 (because 09 is not 9)
- ajay.raj January 23, 2018 in United States
Public List<Integer> getNum(int n)| Report Duplicate | Flag | PURGE
Google Backend Developer - 0of 0 votes
AnswersGiven a function that reads 4096 bytes from a file. write a new function which takes in a buffer and the number of bytes to be read from the user and uses the given function to write values into the buffer.
- fox January 22, 2018 in United States
//given
//returns the number of bytes read
private int read4k(int[] buffer, int offset)
//TODO:
// it should return the bytes read
public int readIntoBuffer(int[] buffer, int byteCount);| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswerGive a binary tree, each node has an extra information, that is, how many children he has,
Find the kth node val in the inorder transversal ,
Followup how to insert a node, such that this newly added node become the Nth node of the inorder binary tree's traversal
- ajay.raj January 21, 2018 in United Statesclass TreeNode{ int val; int NumberOfchildren; TreeNode left; TreeNode right; public TreeNode(int val){ this.val = val; } } public static int findKthOfInorder(TreeNode root, int k) {
| Report Duplicate | Flag | PURGE
Google Backend Developer - 0of 0 votes
AnswersGive a weighted n-nary tree and find the longest path from the root node to the leaf node
- ajay.raj January 21, 2018 in United States
class Node {
int id;
// connected node id, edge weight
Map <Integer, Integer> edges;
}| Report Duplicate | Flag | PURGE
Google Data Engineer