Coding Interview Questions
- 0of 0 votes
AnswersI was given this question recently in an interview.. There are three threads and a counter that will increase from 1 to 100. Catch is that thread 1 increments counter from 1 to 20. Thread 2 increments from 21 to 80. Thread 3 increments from 81 to 100.
- firefox December 11, 2017 in India| Report Duplicate | Flag | PURGE
Symantec Dev Lead Coding - 0of 0 votes
AnswersN different couple go to cinema with 2N different seats. They take their place randomly. You could make swap operations. Write a code for given input what is the minimum number of swap operations for sitting all couples with their partners? Additionally, be sure that no one swaps more than 2 times.
- new December 07, 2017 in United States| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm Arrays Coding Data Structures - 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
AnswersWrite a function to convert a String of ip address to hex
- Shilpi_Roy November 04, 2017 in United States
eg: ip is 197.27.11.11 = 0xC51BBB. The conversion to hex has to be done without pre-existing library function. like String.format() etc.| Report Duplicate | Flag | PURGE
Unity 3D Software Engineer / Developer Coding - 0of 0 votes
AnswersAn web service maintains logs (suppose there are multiple log files per day) of all ip address which has requested service. If there is a DOS attack on the server find all ip addresses that has sent more number of requests and block them. Can this be done without writing any function in higher programming language?
- Shilpi_Roy November 04, 2017 in United States
What would the function look like if written in some language like C, Java etc?
Can this be done in Time optimized and space optimized manner?| Report Duplicate | Flag | PURGE
Unity 3D Software Engineer / Developer Coding - 0of 0 votes
AnswersYou are provided with 2D char array. You have to provide the 2D char array as response which contains the multiplication od the input array. For eg: input=> {{a,b},{c,d}}, output => {{a,c},{a,d},{b,c},{b,d}}
- gauravkumar1491 September 13, 2017 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - -7of 7 votes
Answersaa
- Anonymous July 25, 2017 in United States| Report Duplicate | Flag | PURGE
Uber Senior Software Development Engineer Coding - 0of 0 votes
AnswersA company's organizational structure is represented as
- JustYourAverageDev July 14, 2017 in United States
1: 2, 3, 4
In the above employees with id 2, 3 and 4 report to 1
Assume the following hierarchy.
1: 2, 3, 4
3: 5, 6, 7
5: 8, 9, 10
Given an employee Id, return all the employees reporting to him directly or indirectly| Report Duplicate | Flag | PURGE
Bloomberg LP Senior Software Development Engineer Coding - 0of 0 votes
AnswersGiven a array of integers there is one that is repeated several time. How would you compute the length of the sequence of repeated elements.
- Fernando May 29, 2017
Assuming the initial array is sorted can you do better than O(n) both for spatial and temporal cost?| Report Duplicate | Flag | PURGE
unknown Software Engineer Coding - 0of 0 votes
AnswersImplement power function. The function should take two numbers as input (e.g. 2,3) and return 8 as output
- Syed May 22, 2017 in India
See link below for hints and answer https://baquerrizvinotes.blogspot.in/2017/05/how-to-crack-amazoncom-technical.html| Report Duplicate | Flag | PURGE
Amazon Software Engineer Coding - 0of 0 votes
AnswersYou are given an array of nodes where each node consists of node name, isValid flag, and parent Node index. so, this array actually represents a tree(forest). where root node has -1 as its index for the parent node. rest all node have their parent's index value.
- sonesh May 08, 2017 in United States
You will be given this array and an index. You have to cut down the subtree from the index. Cutting down a tree means, making all the nodes of that subtree false(Isvalid flag).
He was expecting O(N) solution.| Report Duplicate | Flag | PURGE
Two Sigma Software Engineer / Developer Arrays Coding Trees and Graphs - 0of 0 votes
AnswersYou are given an array of values, (not necessary integers or positives) and a value. You have to print all the pairs whose sum is given value. Write a general method which can accept integers, float, doubles, long, or any other thing where this make sense.
- sonesh May 08, 2017 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Senior Software Development Engineer Algorithm Coding - 0of 0 votes
AnswersA college student's record contains the following:
- Maddy May 02, 2017 in India
1. Name
2. Age
3. Subject(s)
4. Marks
5. ID
The student can choose from English, Mathematics and History as subjects. A student can choose one, two or all of the subjects.
The requirement is to search for students who have scored marks more than X in a certain subject. Which Data Structure would you use and how would you solve this problem in an optimal manner?| Report Duplicate | Flag | PURGE
Akamai Coding - 0of 0 votes
AnswersQ 2. You are given a chess game board of size NxN. You have find out positions(i,j), where you can place N queens so that, none of the queens can kill each other without making their first move.
- sonesh April 28, 2017 in United States| Report Duplicate | Flag | PURGE
Hitachi Data Systems Software Engineer / Developer Algorithm Coding Dynamic Programming Matrix - 0of 0 votes
AnswersImplement a Message Broker, with Publisher and Subscriber. There can be multiple Topic or Subject in Message Broker.
- DuttaJ March 23, 2017 in India| Report Duplicate | Flag | PURGE
Flipkart SDE-2 Coding - 2of 2 votes
AnswersGiven an array of integers greater than zero, find if it is possible to split it in two (without reordering the elements), such that the sum of the two resulting arrays is the same. Print the resulting arrays.
- eo March 21, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Production Engineer Coding - 2of 2 votes
AnswersIterate over a singly linked list backwards. Call print on each node.
Example: The list A->B->C should print as
"C B A"class Node { public Node next; public String value; }
There are 4 solutions
- Nerd March 16, 2017 in Europe
1) recursive
2) iterative with O(n) memory
3) iterative with O(1) memory and O(n²) runtime
4) iterative with O(1) memory and O(n) runtime (for this solution the initial list may be modified)
Explain all 4 solutions and write the code for solutions 3 and 4| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 1of 1 vote
AnswersYou are given an array of integers.
- Nerd March 16, 2017 in Europe
Write an algorithm that brings all nonzero elements to the left of the array, and returns the number of nonzero elements.
The algorithm should operate in place, i.e. shouldn't create a new array.
The order of the nonzero elements does not matter. The numbers that remain in the right portion of the array can be anything.
Example:
given the array [ 1, 0, 2, 0, 0, 3, 4 ],
a possible answer is [ 4, 1, 3, 2, ?, ?, ? ], 4 non-zero elements, where "?" can be any number.
Code should have good complexity and minimize the number of writes to the array.| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 1of 1 vote
AnswersCross the street
- pbox February 18, 2017 in United States
ABC Company is involved in the logistics business.
The company has many outlets and stockyards in a city. The city is like an
N
×
M
N×M grid. We consider a single cell of the given grid to be a single block in the city. The stockyard is at the upper-left corner and the outlet is located in the lower right corner. Everyday, one of the employees has to travel from the upper left to the lower right corner for supplies. Each block in the city has a height, where the height of the block located at position (i,j) in the grid is equal to
A
[
i
]
[
j
]
A[i][j]. The company wants to change the heights of some of the blocks, so that the employee can enjoy a high-speed drive from the stockyard to the outlet. But this change comes at a certain cost.
Specifically, if they change a block height from x to y, then they must pay exactly
|
x
−
y
|
|x−y| dollars. Please help them find the minimum cost, such that by spending that specific amount, they can get a path from stockyard to the outlet with all blocks along the path having the same height.
In a single move, the employee can move from a block to any of its adjacent blocks. Note that during this journey, the employee is allowed to move in all four directions, fulfilling the condition that he never goes out of the grid at any point in time.
Input :
First line contains two positive integers N and M - number of rows and columns in the city. Then, N lines follow, each containing M integers, where the
j
t
h
jth integer on the
i
t
h
ith line denotes
A
[
i
]
[
j
]
A[i][j].
Output :
The first and only line of output should contain minimum cost.
Constraints :
1<= N, M <=100
1<= height of blocks <=100
Sample Input
5 5
1 1 1 1 1
9 9 9 9 1
1 3 3 3 1
1 9 9 9 9
1 1 1 1 1
Sample Output
6
Explanation
Optimal path taken by the employee will be : (1,1) -> (1,2) -> (1,3) -> (1,4) -> (1,5) -> (2,5) -> (3,5) -> (3,4) -> (3,3) -> (3,2) -> (3,1) -> (4,1) -> (5,1) -> (5,2) -> (5,3) -> (5,4) -> (5,5) The height of each block along this path can be changed to
1
1, at a total cost of
6
6. There is no way to get a cost less than this.| Report Duplicate | Flag | PURGE
abc Software Engineer Coding - 1of 1 vote
AnswersWrite a program to reveres string from intervals
- kumarami663 February 05, 2017 in India| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 1of 1 vote
AnswersFind the maximum consecutive 1's in an array of 0's and 1's.
- nidhi.prakash.410 January 23, 2017 in India
Example:
a) 00110001001110 - Output :3 [Max num of consecutive 1's is 3]
b) 1000010001 - Output :1 [Max num of consecutive 1's is 1]| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersObject Oriented Design Problem
- tushar.1738 January 22, 2017 in India
--------------------------------
Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact.
Use Case:
1. Customer are given a ticket that they can use to redeem to get their vehicle back
2. Parking spots come in three sizes, small, med, large
3. Thee types of vehicles, small[Two Wheeler], med[Car], large[Bus]
-a small vehicle can park in a small, medium, and large spot
-a medium vehicle can park in a medium and large spot
-a large vehicle can park in a large spot
4. There are multiple entry gate to park vehicle. So Vehicle should asign nearest posible parking spot| Report Duplicate | Flag | PURGE
Coding Java Object Oriented Design - 0of 0 votes
AnswersPlease make analysis of RandomNumber1 and RandomNumber2 methods
- i-sokrat November 17, 2016 in United States
Result: values returned by methods, description of differences in behavior.
using System;
using static System.Math;
namespace Program
{
public class Analysis
{
public double RandomNumber1()
{
Random random = new Random();
return Round((random.NextDouble() - 0.5) * 2.00);
}
public double RandomNumber2()
{
Random random = new Random();
return Round((random.NextDouble() - 0.5) * 2.99);
}
}
}| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersWrite code for transforming equation into canonical form. An equation can be of any order. It may contain any amount of variables and parentheses.
- kanukadze October 18, 2016 in United States
The equation will be given in the following form:
P1 + P2 + ... = ... + PN
where P1..PN - terms that look like:
ax^k
where a - floating point value;
k - integer value;
x - variable (each term can have many variables).
For example:
x^2 + 3.5xy + y = y^2 - xy + y
Should be transformed into:
x^2 - y^2 + 4.5xy = 0| Report Duplicate | Flag | PURGE
Coding - 1of 1 vote
AnswersProgramming Challenge Description:
- abhinav.thegame October 17, 2016 in United States
Develop a service to help a client quickly find a manager who can resolve the conflict between two employees. When there is a conflict between two employees, the closest common manager should help resolve the conflict. The developers plan to test the service by providing an example reporting hierarchy to enable the identification of the closest common manager for two employees. Your goal is to develop an algorithm for IBM to efficiently perform this task. To keep things simple, they just use a single relationship "isManagerOf" between any two employees. For example, consider a reporting structure represented as a set of triples:
Tom isManagerOf Mary
Mary isManagerOf Bob
Mary isManagerOf Sam
Bob isManagerOf John
Sam isManagerOf Pete
Sam isManagerOf Katie
The manager who should resolve the conflict between Bob and Mary is Tom(Mary's manager). The manager who should resolve the conflict between Pete and Katie is Sam(both employees' manager). The manager who should resolve the conflict between Bob and Pete is Mary(Bob's manager and Pete's manager's manager).
Assumptions:
There will be at least one isManagerOf relationship.
There can be a maximum of 15 team member to a single manager
No cross management would exist i.e., a person can have only one manager
There can be a maximum of 100 levels of manager relationships in the corporation
Input:
R1,R2,R3,R4...Rn,Person1,Person2 R1...Rn - A comma separated list of "isManagerOf" relationships. Each relationship being represented by an arrow "Manager->Person". Person1,Person2 - The name of the two employee that have conflict
Output:
The name of the manager who can resolve the conflict Note: Please be prepared to provide a video follow-up response to describe your approach to this exercise.
Test 1:
Test Input
Frank->Mary,Mary->Sam,Mary->Bob,Sam->Katie,Sam->Pete,Bob->John,Bob,Katie
Expected Output
Mary
Test 2:
Test Input
Sam->Pete,Pete->Nancy,Sam->Katie,Mary->Bob,Frank->Mary,Mary->Sam,Bob->John,Sam,John
Expected Output
Mary| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Coding Java Python String Manipulation - -1of 1 vote
AnswersYou are given the arrival and departure times of airplanes at an airport for a single day. Schedules for the airplanes remain the same across all days. You are to determine the number of gates the airport should have so that no plane spends time waiting for a gate.
- funktional September 12, 2016 in United States for AWS
arr = [9:30, 11:15, 16:30]
dep = [11:45, 11:30, 16:45]
Arr array is sorted by time. And departure array is sorted by corresponding arrival times. Plane 'i' arrives at time arr[i] and departs at time dep[i]
Notes:
After some questions, it was decided that minute was the smallest unit of time we cared about. Gate was considered occupied on the arriving minute, but empty on the departing minute. And that the arrival and departure times could be represented as such as integers. e.g. Day runs from minute 0 to minute 1339 (since using a zero-based index). So our example times represented as:
arr = [570, 675, 990]
dept = [705, 690, 1005]| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Coding - 0of 0 votes
AnswersSame question asked in 27th Aug 2016 face to face interview.
- Mallikarjun Birajdar September 01, 2016 in India for Kindle
Find length of longest palindrome string, you can shuffle or remove any characters in string.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - -1of 1 vote
AnswersGiven a linked list a random ptr also exists. Clone the original linked list.I was asked to write test cases for it.
- Rahul Kumar August 09, 2016 in India| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersImplement a Reader/Writers lock by only using primitive locking semantics (such as mutex,semaphore, etc..)
- Lively July 01, 2016 in United States| Report Duplicate | Flag | PURGE
Zillow Software Engineer Coding - -3of 3 votes
AnswersWrite program that takes integer, deletes one of two consecutive digits and return greatest of all results.
- josearturodelosangeles June 01, 2016 in United States| Report Duplicate | Flag | PURGE
Google Applications Developer Coding