## Google Interview Questions

- 0of 0 votes

Answers1. merge intervals with value

- ajay.raj December 01, 2017 in United States

PD: there are a series of continuous intervals, and each interval has a value. Initially, the ith

interval is (i - 1, i - 1), merge these intervals and return the result.

Merge Rule:

a. We can only merge the ith interval with i-1 th or i + 1 interval. The value of new interval is the

mean of these two original intervals.

b. Define cost as absolute difference of two neighboring intervals,

every time merge two intervals with the smallest cost.

c. If the smallest cost exceeds a threshold t, then stop.

d. There may be multiple valid result, just return one.

for example:

value: 3 7 6 5 1

intervals: (0,0) (1,1) (2,2) (3,3) (4,4)

threshold: t = 2

first iteration:

min cost = |7 - 6| = 1, notice that |6 - 5| is also okay.

after merging:

value: 3 6.5 5 1

intervals: (0,0) (1,2) (3,3) (4,4)

second iteration:

min cost = |6.5 - 5| = 0.5

after merging:

value: 3 5.75 1

intervals: (0,0) (1,3) (4,4)

second iteration:

min cost = |3 - 5.75| = 2.75 > t = 2, stop

return [(0,0), (1,3), (4,4)]| Report Duplicate | Flag | PURGE

Google Java Developer - 1of 1 vote

AnswersGive all n cities the distance between them, and then you have to follow all the cities in the order of small to large index of the city, which means you must visit the cities in ascending order, and now you can choose not to visit k cities (k < n), ask choose not to go to which k cities can make the path shortest? Return the shortest journey.

- ajay.raj November 30, 2017 in United States

int findShortestPath(int[][] matrix, int k){

}| Report Duplicate | Flag | PURGE

Google SDET - 0of 0 votes

AnswersGenerate a random MxN starting board. It cannot have 3 or more pieces in a

- ajay.raj November 28, 2017 in United States

row (horizontally or vertically) of the same color. K colors.| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswersImplement a rate limiter attribute/decoration/annotation on top of an API endpoint. caps to N requests per minute with a rolling window (implement from scratch / test / compiling + working code. Was made to write the code in front of a computer.

- xyz November 28, 2017 in United States| Report Duplicate | Flag | PURGE

Google Senior Software Development Engineer - 0of 0 votes

Answersgive a list of cities a to city b the price of air tickets for example

- ajay.raj November 25, 2017 in United States

a b 100 $

b c 200 $

e f 200 $

...

Now let you from city x to city y, you cannot transfer more than twice between the two city, find the cheap flight from x to y, follow up print out the flight| Report Duplicate | Flag | PURGE

Google Backend Developer - 0of 0 votes

AnswersGas station problem, give you a starting point A and End B. An array of oil prices at each gas station index represents the location of each gas station. MPG = V, find the minimum cost of gas from A to B

- ajay.raj November 25, 2017 in United States| Report Duplicate | Flag | PURGE

Google SDE1 - 1of 1 vote

Answersgiven a string, and integer k, check if this string contain all the binary string of length k

- ajay.raj November 24, 2017 in United States

For example, k is 2, then 00,10,01,11.

Followup 1, find a string that can contain all binary string of length k.

Followup 2, find a shortest string that can contain all binary string of length k.| Report Duplicate | Flag | PURGE

Google SDE1 - 3of 3 votes

AnswersGiven a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature.

- md.lisul.islam November 22, 2017 in United States

[73, 74, 75, 71, 70, 76, 72] -> [1, 1, 3, 2, 1, nothing, nothing]| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven an array which is in ascending order till some point and then descending order till end. find peak element

- careercupuser November 22, 2017 in United States| Report Duplicate | Flag | PURGE

Google Applications Developer Algorithm - 0of 0 votes

AnswersGiven a tree find shorted path to a specified element from root. Actual question is different but theory behind it is same.

- careercupuser November 22, 2017 in United States| Report Duplicate | Flag | PURGE

Google Applications Developer Algorithm - 0of 0 votes

AnswersWrite code to find unmatched parentheses and return it in the below format:

- 1080ti November 18, 2017 in United States

((a) -> -10a1

(a)) -> 0a1-1

(((abc))((d))))) -> 000abc1100d111-1-1| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

Answersgive a bunch of job dependency, such as A-> B, A -> C, B-> D, and so on, implement two interfaces.

- ajay.raj November 17, 2017 in United States

The first one is get_next_stage, which returns jobs in parallel for the next phase. The second is job_done, which tells you which job completed.| Report Duplicate | Flag | PURGE

Google SDE1 - 1of 1 vote

AnswersGiven an array of sorted integers and find the closest value to the given number. Array may contain duplicate values and negative numbers.

- Vijay November 17, 2017 in India

Example : Array : 2,5,6,7,8,8,9

Target number : 5

Output : 5

Target number : 11

Output : 9

Target Number : 4

Output : 5| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm Arrays Coding Data Structures - 0of 0 votes

AnswersGive a list of the company's Mergers and Acquisitions relationships, for example

- ajay.raj November 16, 2017 in United States

[

["baidu", "ofo"],

["mobike", "alibaba"],

]

Said baidu acquired ofo, mobike acquired Alibaba.

Seeking the longest of a M & A chain. No cycle| Report Duplicate | Flag | PURGE

Google Backend Developer - 1of 1 vote

AnswersYou are given a binary tree and a function shouldBeErased(node to check whether a node should be erased. Erase all nodes that should be erased in the binary tree and return the resulting forest in the form of an array of every root node.

- ajay.raj November 13, 2017 in United States

Follow up:

What if this is a Binary Search Tree? (In this case you are given a list of nodes that should be erased instead of the function.) Does it make the problem simpler or more complicated or just the same?| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswersYou are given an arbitrary number of graphs using sets such as {a,b,c,d,a}, {a,b,a}, {e,f,g,h,e}... etc. Assume each element at position x_i in a set has a directed edge to x_{i+1}. so a-->b, b-->c etc. Write a program that selects a subset of at mot k vertices that contains at least one vertex from every directed cycle in the graph.

- jablaboo November 12, 2017 in United States| Report Duplicate | Flag | PURGE

Google - 0of 0 votes

AnswersWrite a program that always produces a two-way Euler tour that can be drawn such as it does not cross itself at any vertex.

- jablaboo November 12, 2017 in United States| Report Duplicate | Flag | PURGE

Google - 0of 0 votes

Answerslet's say you're given an arbitrary list of relations r1 and r2 from objects in a set of arbitrary size. find the size of th largest subset with the property that no two are related. for e.g., given set S = {a,b,c,d,e,f} and relations {a,d}, {b,c}, {a,c}, {a,e}, find the subset of S such that no two a connected.

- jablaboo November 12, 2017 in United States| Report Duplicate | Flag | PURGE

Google Trees and Graphs - 0of 0 votes

AnswersThere are n bus lines, known bus stops by bus, the bus is bi-direction, ask from station A to station B at least a few transfers.

- ajay.raj November 10, 2017 in United States| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswersWrite all the possible numbers returned from a calculator pad where a start number move in a L direction in any directions(1-2moves)

- wingchuihk November 08, 2017 in United States

ie. From calculator pad. Start from 8 --> go in L shape (2up, 1right), and it returns 3

ie. Start from 2, (move 2 down, 1 left), it will be 7

ie. Start from 2(move 2 down, 1 right), it will be 9

ie. Start from 7(move 1 left, 2 up), it will be 2

ie. Start from 7(move 1 up, 2 left), it will be 6| Report Duplicate | Flag | PURGE

Google SDET Java - 0of 0 votes

Answersthe longest unique value path in a graph

- ajay.raj November 06, 2017 in United States

/**

* Definition for undirected graph.

* class UndirectedGraphNode {

* int label;

* List<UndirectedGraphNode> neighbors;

* UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }

* };

*/

public class Solution {

public int findLongestUniqueValuePath(List<UndirectedGraphNode> node) {

}

}| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswersGiven an array of length n + 1, containing elements 1 through n and a space,

- ajay.raj November 04, 2017 in United States

Requires the use of a given swap (index i, index j) function to sort the array,

You can only swap the gap and a number, in the end, put the gap at the end| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswerDesign a SparseVector class that implements

- ajay.raj November 03, 2017 in United States

Vector interface, which contains 4 methods: get(int index),

increment(int index, int delta), numNonZeros(), and dotProduct(Vector other)| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswerGive a vote list = [(a, 100), (b, 150), (a, 200)] # (name, timestamp) and time T

- ajay.raj November 03, 2017 in United States

Find the highest number of votes (or anyone with the highest number of votes) at T

ex: T = 100 -> a, T = 150 -> a or b, T = 200 -> a

followup1, give one more input K, find Top K votes at T

followup2, the same vote list, K, but given the Top K votes list, find the time T.| Report Duplicate | Flag | PURGE

Google SDET - 2of 4 votes

AnswerCongrats to aonecode's member F.L.

- aonecoding November 03, 2017 in United States

Got offers from - Youtube(G), LinkedIn, Airbnb, Square, Wish, Blend and NextDoor!

Thanks for sharing the interview experience with us.

Youtube Interview

- Phone: Find anagrams of string A from string B (sliding window)

- Phone: Find if two frames in a screen are equal. Frames may overlap. (equal method)

Onsite:

- LC41 first missing positive

- LC499+LC505 The maze

- LC161 one edit distance

- Similar to hangman but make guesses based on a dictionary.

Assume a dictionary has words - {house, morse, jesus} and ‘morse’ is the answer. If your first guess is ‘house’, output will be ‘_o_se’, which indicates 3 letters are correct. (Here the arrangement of letters does not matter. Your guess can be ‘co’ and if answer is ‘ok’ then the output is gonna be ‘_o’ which indicates letter ‘o’ in answer. )

Try to get the answer with minimum guesses.

(Interviewer expects pre-processing the dictionary. Key: letter; Value: frequency. Begin with combinations of most frequent letters first)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

Answers

- ajay.raj November 01, 2017 in United States`give an enum, where each element has a parent-children relationship, and children's expression is the value of parent append an index, such as enum vehicle { car = 1 toyota = 11 camry = 111 corolla = 112 honda = 12 truck = 2 GMC = 21 } Ask a value, return to his parent, such as GMC = 21, return to the truck`

| Report Duplicate | Flag | PURGE

Google SDE1 - 1of 1 vote

AnswersGiven a list points on a 2d plane, find

- ajay.raj November 01, 2017 in United States

largest rectangular area that can be formed

for the rectangle only considers those parallel to x and y| Report Duplicate | Flag | PURGE

Google SDE1 - 0of 0 votes

AnswersGiven a set of strings (denoting URLs), like:

- lkjhgfdsa October 27, 2017 in United States

1. abc.pqr.google.com

2. pqr.google.com

3. pqr.google.net

4. yahoo.com

5. abc.yahoo.com

etc...

find an efficient way to find out how many times a particular string appears as a substring. For e.g., given the above set of strings, "google.com" appears twice; ".com" appears four times, "pqr.google.com" appears twice, and so on.

Follow up: How would you do this, if the input was no longer a URL (So, "abc.pqr.google.com" and "pqr.abc.google.com", both are valid)?| Report Duplicate | Flag | PURGE

Google Software Developer - 1of 1 vote

AnswersYou are a game developer working on a game that randomly generates levels. A level is an undirected graph of rooms, each connected by doors. The player starts in one room, and there is a treasure in another room. Some doors are locked, and each lock is opened by a unique key. A room may contain one of those unique keys, or the treasure, or nothing.

- robert October 24, 2017 in United States

Implement a representation for a level and write code that, given a level and starting room, returns true if the treasure can be reached by the player—likely requiring them to find certain other keys first—or false if there is no solution.| Report Duplicate | Flag | PURGE

Google Software Engineer Intern Algorithm - 3of 3 votes

AnswersQuestion 1.

- anonymous October 24, 2017 in India

You are given a string composed of uppercase English letters (‘A’ through ‘Z’).

Set of letters (‘A’, ‘E’, ‘I’, ‘O’, ‘U’) are called vowels. Other letters are called consonants.

We define foo value of a string as number of pairs of exactly same consecutive vowel letters.

For example,

Ex.1: BCDEEIOU - This has a foo value of 1 (because of EE). Note that although I is next to E, and O is next to I, and U is next to O, they aren’t exactly same neighbours, so they don’t contribute to foo value

Ex.2: BCDEEEIOU - This has foo value of 2. Because of first pair of EE and immediately next pair of EE

Ex.3: ABCDEFG - This has foo value of 0. There are no consecutive vowels

Ex.4: ABEUUOUOO - This has foo value of 2, because of UU and OO

You are given 2 inputs, N and K.

How many strings of length N can you form such that they all have foo value of K?

Let’s assume the constraints as:

1<=N<=15

0<=K<N| Report Duplicate | Flag | PURGE

Google Software Engineer

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window