Algorithm Interview Questions
- 1of 1 vote
AnswersGiven a length n, count the number of strings of length n that can be made using ‘a’, ‘b’ and ‘c’ with at-most one ‘b’ and two ‘c’s allowed.
- Nits September 07, 2019 in United States| Report Duplicate | Flag | PURGE
Facebook Software Development Manager Algorithm - 0of 0 votes
AnswersImplement auto complete for IDE, you will be given strings of classes and input, input can be like MVC, MoClick, MouseClickHand
- neer.1304 August 17, 2019 in United States
For MouseClickH => MouseClickHandler
MVC => can match to any classes where first word starts from M then V then C| Report Duplicate | Flag | PURGE
Pinterest Software Engineer / Developer Algorithm - 0of 0 votes
AnswersA stream of data representing the price of a commodity is being read. The data is of the format (price:Int, timestamp:Option[Long]).
- abzy August 17, 2019 in India
If the timestamp is missing, it means the price has to be deleted.
If timestamp is old, it means the previous data with same timestamp has to be updated with this new price.
Else it's the new price of the commodity.
At any point of time the latest, max and min of the price has to be printed.
If the delete instruction is received through the stream, the min/max should be updated accordingly.| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswerYou're given an array of integers sorted ( [1,2,3,5,6,7,10]) you need to serialize and compress this array into a string (1-3, 5-7,10)
- neer.1304 August 15, 2019 in United States| Report Duplicate | Flag | PURGE
Indeed SDE-2 Algorithm - 0of 0 votes
AnswerGiven two points on a directed acyclic graph determine their least common ancestor, give it's time complexity, and describe any improvements you could make (if possible).
- neer.1304 August 15, 2019 in United States| Report Duplicate | Flag | PURGE
Indeed SDE-2 Algorithm - 1of 1 vote
AnswersGiven a binary matrix of 0 and 1 where we can move in 4 directions left, right, top, down and we can only pass through 1's. Find the shortest path from given source coordinate (a,b) to destination (m,n) given we can flip any one of the zero to one.
- neer.1304 August 09, 2019 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswerPrint numbers that matches with the index in given non-duplicate unordered array.
- HR August 03, 2019 in United States| Report Duplicate | Flag | PURGE
None Algorithm - 0of 0 votes
AnswersWrite a program to encode a string from --> ABABXBYZXXX --> X4B3A2Y1Z1 (what should be the storage requirements for optimal conversion of 10TB file)
- HR August 03, 2019 in United States| Report Duplicate | Flag | PURGE
None Algorithm - 1of 1 vote
AnswerSuppose there is a function given to you that:
def get_friends( person_id ) { /* returns friends of person */ }
How you are now going to recommend friends to a person based on number of mutual friends? So, come up with the function:
- NoOne August 02, 2019 in Indiadef friend_reco( person_id, max_no_of_friends ){ }
| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven billions of Identity cards of the form :
card : { my_id : "my id", "moms_id" : "mom id", "dad_id" : "dads id" }
If one gives you two Person's id, how can you tell if these 2 persons are blood related.
So, write a function that is:
- NoOne August 02, 2019 in Indiadef is_blood_related( person_id_1, person_id_2 ) // go on..
| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersGiven an array of integers find the maximum value of a[i] - a[j] + a[k]
- ASimpleCoder August 01, 2019 in India
with constraints i < j < k and a[i] < a[j] < a[k]| Report Duplicate | Flag | PURGE
Uber Software Developer Algorithm - 0of 0 votes
AnswersYou're running a pool of servers where the servers are
- neer.1304 July 28, 2019 in United States
numbered sequentially starting from 1. Over time, any
given server might explode, in which case its server
number is made available for reuse. When a new
server is launched, it should be given the lowest available number.
Write a function which, given the list of currently
allocated server numbers, returns the number of the next server to allocate.
For example, your function should behave something like the following:
>> next_server_number([5, 3, 1])
2
>> next_server_number([5, 4, 1, 2])
3
>> next_server_number([3, 2, 1])
4
>> next_server_number([2, 3])
1
>> next_server_number([])
1
Server names consist of an alphabetic host type (e.g. "apibox") concatenated with the server number,
with server numbers allocated as before (so "apibox1",
"apibox2", etc. are valid hostnames).
Write a name tracking class with two operations,
allocate(host_type) and deallocate(hostname).
The former should reserve and return the next
available hostname, while the latter should release
that hostname back into the pool.
# For example:
#
# >> tracker = Tracker.new()
# >> tracker.allocate("apibox")
# "apibox1"
# >> tracker.allocate("apibox")
# "apibox2"
# >> tracker.deallocate("apibox1")
# nil
# >> tracker.allocate("apibox")
# "apibox1"
# >> tracker.allocate("sitebox")
# "sitebox1"| Report Duplicate | Flag | PURGE
Stripe Software Engineer Algorithm - 0of 0 votes
AnswersWrite a map implementation with a get function that lets you retrieve the value of a key at a particular time.
- neer.1304 July 28, 2019 in United States
t:0 A =1
t:2 A = 2
get(A, t:1) -> 1
get(A, t:3) -> 2| Report Duplicate | Flag | PURGE
Stripe Software Engineer Algorithm - 0of 0 votes
AnswersImplement following method of ScheduledExecutorService interface in Java
- neer.1304 July 23, 2019 in United States
schedule(Runnable command, long delay, TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.
scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.| Report Duplicate | Flag | PURGE
Uber SDE-2 Algorithm - 0of 0 votes
AnswersImplement a thread-safe data structure which can keep track of number of incoming
- neer.1304 July 22, 2019 in United States
requests grouped by IP Address over a time window. Add support for grouping by other
attributes such as BrowserAgent.| Report Duplicate | Flag | PURGE
Rubrik Algorithm - 0of 0 votes
AnswersGiven a string select two non-overlapping strings that are same and remove them. Perform this operation recursively till there are no desired strings.
- neer.1304 July 20, 2019 in United States
Print the number of possible substring after completing above operation.
Ex - abcc
Duplicate non-overlapping substring - abc
After removing abc from we are left with 1 substring abc.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersIn a 2-D matrix of m*n select m-1 elements from each row such that that the resulting sum is minimum and each column is selected atleast once.
- neer.1304 July 20, 2019 in United States
Ex -
2 3 5
3 2 5
4 4 7
Selecting (2,3) from 1st row, (2,5) from 2nd row and (4,4) from 3rd row would result in minimum sum of 20| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 3 votes
AnswersQuestion: Can you break the given string into words, provided by a given hashmap of frequency of word as <word: n>
- nitinguptaiit July 18, 2019 in United States
Example:
HashMap -> {"abc":3, "ab":2, "abca":1}
String: abcabcabcabca
output: Yes; [ abc, abc, abc , abca ]
Example:
HashMap -> {"abc":3, "ab":2}
String: abcabab
output: No
Example:
HashMap -> {"abc":3, "ab":2, "abca":1}
String: abcx
output: No| Report Duplicate | Flag | PURGE
Facebook Algorithm - 0of 0 votes
AnswersFind LCA for list of nodes of a tree
- neer.1304 July 17, 2019 in United States
Function defined as below -
TreeNode findLCA(TreeNode root, List<TreeNode> nodes)| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersWrite a program to find number of words in a file not using any standard tokenizing API's.
- neer.1304 July 12, 2019 in United States| Report Duplicate | Flag | PURGE
Boomerang Commerce Algorithm - 0of 0 votes
AnswersGiven n, you will be getting stream of sets each set may contain like (1,3,4,5) which signifies that 1,3,4,5 are related. Similarly you may get like (6,7) , (1,8).
- neer.1304 July 12, 2019 in United States
And you will be asked to find whether 1 & 4 are related => Yes (as they are from same set).
3 & 8 are related => yes as 8 & 3 are related through 1.
5 & 7 are related =>No| Report Duplicate | Flag | PURGE
Boomerang Commerce Algorithm - 0of 0 votes
AnswersImplement a function which accepts a number and returns top 10 big numbers the function is called with so far;
- vasa.v03 July 10, 2019 in India
If we call the function with 1.. to 100 , for the call function(100) the function will return 91 to 100 in reverse order since they are top 10 biggest number so far| Report Duplicate | Flag | PURGE
British Telecom Software Engineer Algorithm - 0of 0 votes
AnswersAn array is called a Good Array if the elements continually increasing or continually decreasing or continually decrease and then increase.
- neer.1304 July 09, 2019 in United States
Question 1: He asked how will you tell whether a given array is a good array or not.
Question 2: Given an array, you are allowed to add any number of values to each of the element. Find the minimum sum of elements that can make the array a good array.| Report Duplicate | Flag | PURGE
Nutanix Algorithm - 0of 0 votes
AnswersA software-based LRU Cache replacement algorithm has to be implemented for a Single Touch/Multi-Touch Cache. Single Touch can occupy at least 30% of the total cache space. A key accessed for the first time will appear in the Single Touch cache. When accessed multiple times, this will be part of the multi-touch cache. Also, multiple threads will access the cache. Following are the functions allowed for cache access.
- neer.1304 July 09, 2019 in United States
1. get(key): returns the value against the key if present else return NULL
2. set(key, value): set the value against the key| Report Duplicate | Flag | PURGE
Nutanix Algorithm - 0of 0 votes
AnswersGiven a tree, and there will be treasure in one of the nodes. We can query any node, it will return the node itself if it contains the treasure or it returns the branch which leads to the treasure. we need to find out the treasure in minimum number of queries.
- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE
Nutanix Algorithm - 0of 0 votes
AnswerImagine someone maliciously duplicated every file on your computer, and completely randomized their names and locations on your hard drive. Discuss an efficient way to clean up your drive of all these duplicates.
- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE
Nutanix Algorithm - 0of 0 votes
AnswersTwo very very large files F1, F2 containing key, value pairs. Write these key, values to a third file without any duplicates.
- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE
Cohesity MTS Algorithm - 1of 1 vote
AnswersBuild a key-value data structure that allows the user to take a snapshot of the data. The user can read the key-value store from any snapshot.
- neer.1304 July 09, 2019 in United States
Structure has the normal key/value like methods plus something like
snapshot = dataStructure.takeSnapshot()
value = dataStructure.get(key, snapshot)
void dataStructure.deleteSnapshot()| Report Duplicate | Flag | PURGE
Rubrik MTS Algorithm - 0of 0 votes
AnswersA table has some number of balls at various positions on a line segment. All are moving with same speed in one or the other direction. Wherever a collision occurs they change direction. A ball falls from the edges of the table. Find the time when all balls fall of the table given initial position of each ball and speeds
- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE
Rubrik MTS Algorithm - 1of 1 vote
AnswersGiven 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.
- neer.1304 July 03, 2019 in United States
Example:
L = [(‘abc’, 10), (‘def’, 15), (‘ghi’, 10), (‘abc’, 12), …, (‘xyz’, 100)]
The function should return [‘xyz’, ‘abc’, …, ‘def’, ‘ghi’]| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm