0% found this document useful (0 votes)
15 views3 pages

Google SWE

Uploaded by

vikaskr733
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Google SWE

Uploaded by

vikaskr733
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Google SWE

Interview Questions

1. Given an unsorted array containing duplicates and a number, find at what position that
number would occur if the array is sorted.
Follow up – How will you do it in O(n)?

2. Given a chat history represented in the form of a vector of strings, find the top k users who
spoke the maximum number of words.
Example: Rahul: hey, how are you.
Naman: Good. You?
Rahul: I am good too. See you soon!

3. Given is a network of cities. A crime has occurred in city C and the criminal has fled to his
hometown H. Now the police want to catch the criminal and he knows that the criminal will
go from city A to city B only if the shortest path distance from city B to H is less than city A to
H. We are supposed to find the number of possible routes that the criminal might have taken
starting from C.

4. Find the preorder traversal of the tree then there are 2 follow ups where we need to remove
leaf nodes using malloc or delete then there is one more follow up where there are some
more condition and the idea for that is topological sort.

5. The problem statement has a java class and predicate function. We are given an array of
object of this class and we have to minimise data movement based on the predicate function
– looks very complicated but the simply thing is we need to apply Dutch flag problem
approach.

6. Given a list L of video names and their watch rates, write a function that will return the
videos with the top 10 watch rates. Video names may appear more than once.

7. Given a graph, a start and destination point. Each node had a value of length. You have to
find the shortest path to the destination. Also, there is an infected node with a virus and the
path would not work if you reach that node. In addition, the infected node had a virality,
meaning that all the neighbours connected to this infected node would get infected as well
depending on the value of this virality. How will you find the shortest path to the
destination?

8. Given an array of N positive numbers, the task is to find a contiguous subarray (L-R) such that
a[L]=a[R] and sum of a[L] + a[L+1] +…+ a[R] is maximum.
Example:
Input: arr[] = {1, 3, 2, 2, 3}
Output: 10
Subarray [3, 2, 2, 3] starts and ends with 3 and has sum = 10

9. Leetcode Problem 1591 – https://leetcode.com/problems/strange-printer-ii/


10. Leetcode Problem 127 – https://leetcode.com/problems/word-ladder/

11. You are given an array where each element represents the number of floors of the building.
In one operation you can remove one floor from any building. After a certain number of
operations, the number of floors of all buildings must be either zero or equal to some
specific non-negative number ‘K’. You have to find a minimum number of operations
required and a value of K.
Example:
Sample Input: arr = [1,3,4,7,8,9]
Sample Output: minimum operations = 11. K=7.
Final array: [0,0,0,7,7,7]

12. You are given an n-ary tree where each node can have up to n children (i.e., 0 to n). A frog is
currently sitting at a root node. It is given that frog can jump from the current node to any of
its child nodes with equal probability. The frog can stay on the current node only if the
current node has zero child nodes (i.e., leaf node) otherwise frog must jump. For each node
find the probability that the frog is present at that node after an infinite amount of time.
Follow-up: Instead of a tree, assume it is a Directed acyclic graph.

13. Leetcode Problem 287 - https://leetcode.com/problems/find-the-duplicate-number/

14. Given an array weight[] of size N containing weights of luggage. If the weights are within a
threshold of W then it does not require any extra cost. But after the weights cross the
threshold, they need to pay extra cost according to the following table. The task is to
calculate the extra cost of the luggage required.

Example:
Input: weight[] = {120, 135, 280, 60, 300}, W = 90
Output: 1700
Explanation: The weight 120 is 30 more than the threshold. So, it requires 100 extra cost.
The weight 135 is 45 more than the threshold. So, it requires 100 extra cost.
The weight 280 is 190 more than the threshold. So, it requires 500 extra cost.
The weight 300 is 210 more than the threshold. So, it requires 1000 extra cost.
And the weight 60 is within threshold. So, it requires no cost.
The total extra cost is (100 + 100 + 500 + 1000) = 1700

15. https://www.geeksforgeeks.org/changing-one-clock-time-time-minimum-number-
operations/
16. Given an array of some cards from a deck and the number of suites (s) and ranks (r) in each
suit of these custom cards, return the highest five flushes i.e. find out a set of cards with 5
consecutive ranks in a suit and return one such set with the highest value. The suits are
ranked from 1 to s and each suit ranks from 1 to r in increasing order of value.
Example:
Input: Total number of suites = 7, Total number of ranks = 10, an array of cards S1R0, S2R2,
S2R5, S2R3, S3R1, S3R4, S2R6, S2R4, S3R5, S3R2, S3R3, S5R9.
Output: array of S3R1, S3R2, S3R3, S3R4, S3R5.

*NOTE:

• It is important for the interviewee to know the time and space complexity of the proposed
approach along with which data structure will be best suitable.
• You will be asked to dry run the code on Google docs.
• Kindly be prepared with you introduction before all interviews.

You might also like