Algorithm Interview Questions
- 0of 0 votes
AnswersA ‘plus’ pattern of size 1 is defined as following :
- neer.1304 March 08, 2017 in United States
1
1 1 1
1
size 2 :
1
1
1 1 1
1
1
Find size of largest plus pattern in given 2D matrix which has only 0s &1s.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
Answers/*
- JSDUDE March 08, 2017 in United States for Alexa
Amazon employees are encouraged to learn and be curious, and this means employees can transfer teams within the company easily.
This usually means they'll move to a new building, and for those who have parking, they'd need to swap parking spots.
The task is that given a list of employees who want to swap parking spots, write a function that can match them up 1 to 1.
The output can simply be tuples of aliases.
Each alias should only be matched once.
Input-
alias fromBuilding toBuilding
adrian building1 building2
john building2 building1
andrew building3 building2
william building4 building3
John building2 building4
Doe
output-
adrian,john
*/| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - 0of 0 votes
AnswersGiven a sorted array which has been rotated n number of times. Find the value of n.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersClone the binary tree.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersIn a binary tree return the maximum "turns" in tree. A "turn" is defined as LRL or RLR traversal.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-3 Algorithm - 0of 0 votes
AnswersReturn the maximum length sequence containing consecutive numbers from a binary tree.
- neer.1304 March 08, 2017 in United States
90
/ \
1 66
/ \
2 67
/ \ /
5 4 68
/ \
99 100
Consecutive sequence of maximum length: [66, 67, 68] of length 3.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersImplement Tower of Hanoi without using recursion.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersA stepping number is defined as a number in which the absolute difference between the consecutive digits is not greater than 1, A stepping number cannot be a single digit number. You have to find the number of stepping numbers between n1 and n2 where n2 > n1 and n2, n1 > 0.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersGiven a stack of integers of size n, you have to sort it using only push and pop operations in O(1) space.
- neer.1304 March 08, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersGiven a tree return the number of elements for the level with the maximum elements.
- neer.1304 March 07, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 1 vote
AnswersGiven an array it can be of 4 types
- neer.1304 March 07, 2017 in United States
(a) Ascending
(b) Descending
(c) Ascending Rotated
(d) Descending Rotated
Find out which kind of array it is| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 2 votes
AnswersThe following code has a bug, find it and fix it
- sergio March 05, 2017 in United Kingdom for BingRelease() { m_refCount--; m.lock(); if (m_refCount == 0) { free(this); return 0; } m.unlock() return m_refCount; }
| Report Duplicate | Flag | PURGE
Microsoft Software Developer Algorithm - 1of 1 vote
AnswersWrite a function that receives a string an returns a list of all the substrings (of length >= 2) composed by consecutive characters. E.g input : "BCCDE" , output: ["BC","CD","CDE","DE"]
- sergio March 05, 2017 in United Kingdom for Bing| Report Duplicate | Flag | PURGE
Microsoft Software Developer Algorithm - 0of 0 votes
AnswersGiven a linked list rotate it on the Kth element. For example, given 1->2->3->4->5 the list should be transformed into 4->5->1->2->3
- sergio March 05, 2017 for Bing| Report Duplicate | Flag | PURGE
Microsoft Software Developer Algorithm - 2of 2 votes
AnswersYou have a string of numbers, i.e. 123. You can insert a + or - sign in front of ever number, or you can leave it empty. Find all of the different possibilities, make the calculation and return the sum.
- twinmind March 03, 2017 in United States
For example;
+1+2+3 = 6
+12+3 = 15
+123 = 123
+1+23 = 24
...
-1-2-3 = 6
...
Return the sum of all the results.| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm - 2of 2 votes
Answers/**
* Given a nested list of integers, returns the sum of all integers in the list weighted by their REVERSED depth.
* For example, given the list {{1,1},2,{1,1}} the deepest level is 2. Thus the function should return 8 (four 1's with weight 1, one 2 with weight 2)
* Given the list {1,{4,{6}}} the function should return 17 (one 1 with weight 3, one 4 with weight 2, and one 6 with weight 1)
- xankar March 03, 2017 in United States*/ public int reverseDepthSum (List<NestedInteger> input) { // implementation here }
| Report Duplicate | Flag | PURGE
Linkedin Backend Developer Algorithm - 0of 0 votes
AnswersYou have a range of consecutive numbers, from 1 to n (inclusive). e.g. [1, 2, 3, 4... n]. We would like to calculate a sum of a function across the entire range, where the function returns the product of the preceding C elements.
- Junior Programmer March 02, 2017 in United States
If there are less than C previous elements, just use the available numbers. i.e. if you are processing the fourth number in the range, but C is greater than 3, then you will calculate the product using only the 3 available preceding numbers. In this situation as you move further along in this range more preceding numbers become available.
A worked example follows: if n=5 and C=2, the correct products and final sum for each element of the range are: 0 + 1 + 2 + 6 + 12 = 21
Can you explain this question and complexity of your algorithm?| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven the weekly vacation numbers for various cities for an year (ie 12 * 4 = 48 weeks ) , design a tour which will maximize the number of vacations for a salesman. The salesman can choose to work in any city for the week , and can weekly change the city unlimited number of times , but has to remain in the city for the week . It's not necessary for the salesman to go to all cities , goal is to find the schedule which maximize the vacation for whole year. Input will be HashMap<string , int[48] vacation> where string is the city name and int[48] is city's vacation numbers for an year.
- yuvithomas February 27, 2017 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 6 votes
AnswersCreate an iterator class that stores a list of the built-in Iterators.
- aonecoding February 27, 2017 in United States
Implement the next() and hasNext() methods in a Round Robin pattern (pops next element in a circle).
Example:
Given a list [iterator1,iterator2, iterator3...]
when calling RoundIterator.next()
pops iterator1.next if iterator1.hasNext() is true
when calling RoundIterator.next()
pops iterator2.next() if iterator2.hasNext() is true
when calling RoundIterator.next()
pops iterator3.next if iterator3.hasNext() is true
...
when calling RoundIterator.next()
pops iterator1.next if iterator1.hasNext() is true
when calling RoundIterator.next()
pops iterator2.next if iterator2.hasNext() is true
when calling RoundIterator.next()
pops iterator3.next if iterator3.hasNext() is true
...
until there is no more element in any of the iterators| Report Duplicate | Flag | PURGE
Google Algorithm - 1of 9 votes
AnswersQ: Weighted meeting room
Given a series of meetings, how to schedule them. Cannot attend more than a meeting at the same time. Goal is to find maximum weight subset of mutually non-overlap meetings.class Meeting: def __init__(self): self.startTime self.endTime self.weight
@concernedCoder
- aonecoding February 27, 2017 in United States
When you claim the questions as fake, provide evidence. These are no doubt questions asked in the coding interviews of the best companies and they definitely help interviewees to prepare for the interview.
Why do you have a problem with this?| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
Answers
- xankar February 26, 2017 in United Statesimport java.time.Duration; import java.time.LocalTime; import java.util.List; import java.util.Map; // Your goal is to write business logic for a very simple Restaurant booking system // You are encouraged to refactor exisiting code, create other classes, write helper methods etc // You also need to make sure that the implementation works correctly class Reservation { public String name; public int partySize; public LocalTime startTime; } class Table { public int tableNumber; public int maxPartySize; } class Restaurant { public List<Table> tables; public LocalTime openTime; public LocalTime closeTime; public Map<Integer, Duration> reservationDurationsPerPartySize; // Returns a Table if Reservation could be booked, null otherwise // Booking rules: // 1) Reservation could be made only when the Restaurant is open. // 2) Only one Reservation can be seatted a Table at any time. // 3) Reservation can be seatted only at a Table of the same or a bigger size. // 4) Reservation should stay on the same Table for the whole Duration. // 5) Reservation Duration is determined by PartySize. public Table bookReservation(Reservation reservation) { //TODO: } }
| Report Duplicate | Flag | PURGE
Opentable Backend Developer Algorithm Data Structures Java Problem Solving - 0of 0 votes
AnswersGiven set of N number of points/Co-ordinates[(x1,y1),(x2,y2), (x3,y3), (x4,y4), (x5,y5), etc] find if any of them form square.
- xankar February 26, 2017 in United States| Report Duplicate | Flag | PURGE
Pure Storage Backend Developer Algorithm Data Structures Java - 0of 0 votes
AnswersGiven 3 sorted arrays. Find(x,y,z), (where x is from 1st array, y is from 2nd array, and z is from 3rd array), such that x<y<z.
x = element(s) from array 1
y= element(s) from array 2
z = element(s) from array 3
I can have more than 1 elements from each array. But at least 1 from each array is mandatory and elements from .int[] arr1 = {3}; int[] arr2 = {11, 13, 16}; int[] arr3 = {45}; Correct Output : 7 (3,11,45) (3,13,45) (3,13,16,45) (3,16,45) (3,11,13,45) (3,11,16,45) (3,11,13,16,45)
Need to find the number of such sequences.
- manishasharma361 February 26, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm - 1of 3 votes
AnswerOn google search, how to enable key word auto completion after a few letters typed.
- aonecoding February 19, 2017 in United States
Follow-up: How to rank the words if they are weighted by frequency?| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersFind largest sub-array?
- xyz February 16, 2017 in United States| Report Duplicate | Flag | PURGE
Huawei SDE1 Algorithm - 1of 1 vote
AnswersYou have two servers. Both of these servers have an identical file with billion characters except for one single character. These servers are connected over a very slow connection.
- xankar February 15, 2017 in United States
How do you find the different character?
My ans: split those files in to batches of characters of 10,000 (say), now calculate checksum and compare the checksums for the chunks of 10,000 character lines. So now you are just comparing 'ints' and not the files per say. (remember the connection is very slow)
His question: How do you optimize this?| Report Duplicate | Flag | PURGE
VMWare Inc Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersFind the longest cycle in a graph ?
- Harsh Bhardwaj February 11, 2017 in United States| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersCross the River
- itsvks February 10, 2017 in India
Saatwik, an elite programmer love the woods. Once he was in one of his trips to the mighty Himalayas , he encountered a strange problem. As we all know that, Himalayas has abundant river streams and forests. While travelling in one of the forest, he was trapped by the river stream flowing. As the stream flow was fast, he couldn't cross by swimming across water, he must find some other way to cross it.
River is present throughout the X axis and its boundary is marked by y coordinates (i.e. from y=A to y=B) .
--------------------------------------------------------------------------------- (y=A)
..................................................................................................
..................................................................................................
..................................................................................................
---------------------------------------------------------------------------------- (y=B)
Now, You are provided with some rocks along with their centres and radius respectively. Currently Saatwik is present on the shore having y=B . We can't jump between the rocks but we can move from one rock to other if both overlap at some points. You need to tell whether Saatwik will be able to cross the river by using any number of rocks or not . If he can, then output the minimum number of rocks taken to achieve it otherwise output −1
Input :
First line of input will contain T denoting number of test cases. For each of the test cases, First line will contain N denoting number of rocks. From second line onward, there will be N lines containing 3 integers X,Y,R where (X,Y) denotes the coordinates of the centre of that rocks and R stands for its radius. Last line will contain two integers A and B denoting the upper and lower boundary of the river respectively.
Output:
Output the required answer in a separate line for each of the test case.
Constraints :
1≤T≤10
1≤N≤5000
−109≤X,Y,A,B≤109
1≤R≤109
B<A
Sample Input
1
3
1 1 2
1 2 1
3 4 1
3 0
Sample Output
1
Explanation
At first we can step onto the first rock from the river shore. Then we can cross river directly or can move to second rock and then cross it. Note that we can't use third rock as it is beyond the reach from the other rocks.
Time Limit: 2.0 sec(s) for each input file
Memory Limit: 256 MB
Source Limit: 1024 KB| Report Duplicate | Flag | PURGE
Cleartrip.com Software Developer Algorithm - 0of 0 votes
AnswerGiven an array A of size N, where the ith integer of the array is A[i] and has a value ranging between 1 and 1000 inclusive, you need to help Monk with the following task :
- itsvks February 10, 2017 in India
Given 3 additional numbers K, X and Y, you need to report the number of un-ordered pairs of elements (i,j) from this array, such that (1≤i<j≤N), (A[i]+A[j])%K=X, and (A[i]×A[j])%K=Y.
Input Format :
The first line contains 4 space separated integers N, K and X and Y. The next line contains N space separated integers where the ith integer denotes A[i].
Output Format :
Print the required number of ordered pairs of array elements on a single line. As the answer could be rather large, beware of integer overflows.
Constraints :
2 ≤ N ≤ 10 raised to power 5
1 ≤ K ≤ 10 raised to power 6
0 ≤ X, Y < K
1≤A[i]≤1000
Sample Input
5 2 1 0
1 2 3 2 1
Sample Output
6| Report Duplicate | Flag | PURGE
Cleartrip.com Software Developer Algorithm - 1of 1 vote
AnswersGiven a set of possibly overlapping rectangles in different levels (All of which are "not rotated", can be uniformly represented as (left-bottom,right-top) tuplets), return a minimal set of (non-rotated) non-overlapping rectangles, that occupy the same area.
- hulk February 09, 2017
The rectangle at lower level has more priority than at higher levels.| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm Data Structures