Software Developer Interview Questions
- 1of 1 vote
AnswersAmazon has N buildings on the site, building ID ranged from 0 to N-1
- arpita.tanvi21 October 13, 2019 in United States
Every employee has an office space in one of the buildings.
Now employee may make a request to move from current building X to
another building Y. A moving request is noted by
Class Request{
String employee names;
int from building;
int to building;
}
Initially all buildings are full. A request from building X to building Y is
achievable only if someone in building Y made an achievable requests to
move away and therefore creates a vacancy
Given a wishlist of requests, help us plan for the best way of building
swaps. A plan that fulfill the maximum number requests is considered
the best
Output is a list of employee names on cyclic swaps.
For Ex:
Input :
List<Request requests{
<"Alex" 1, 2>,
<"Ben", 2, 1>,
<"Chris", 1, 2>,
<"David", 2, 3>,
<"Ellen", 3, 1>,
<"Frank", 4, 5>
}
Expected Output:
List<List>
[ ["Alex","Ben"],["Chris","David","Ellen"] ]
Can someone please help me how to solve this one?| Report Duplicate | Flag | PURGE
Software Developer - 0of 0 votes
AnswersSuppose two arrays are given A and B. A consists of integers and the second one consists of 0 and 1.
- AN October 11, 2019 in India
Now a operation is given - You can choose any adjacent bits in array B and you can toggle these two bits ( for example - 00->11, 01->10, 10->01, 11->00) and you can perform this operation any number of times.
The output should be the sum of A[0]*B[0]+A[1]*B[1]+....+A[N-1]*B[N-1] such that the sum is maximum
During the interview, my approach to this problem was to get the maximum number of 1's in array B in order to maximize the sum.
So to do that , I first calculated the total number of 1's in O(n) time in B. Let count = No. Of 1's=x
Then I started traversing the array and toggle only if count becomes greater than x or based on the elements of array A(for example : Let B[i]=0 and B[i+1]=1 & A[i]=51 and A[i+1]=50
So I will toggle B[i] B[i+1] because A[i]>A[i+1])
But the interviewer was not quite satisfied with my approach and was asking me further to develop a less time complex algorithm.
Can anyone suggest a better approach with lesser time complexity??| Report Duplicate | Flag | PURGE
Software Developer Algorithm - 1of 1 vote
Answersfind nearest word from the given non-english dictionary which is one off character. (could be non ascii characters)
- prathji October 01, 2019 in United States
for eg. dictionary contains { apple, pineapple, banana, orange }
if given word "applx" then return true, as applx matches with apple and only one character is off.
aplpe returns false| Report Duplicate | Flag | PURGE
Google Software Developer - 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
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
AnswersGiven a rectangle with width 'W' and height 'H', you have to fit a string 'S' in it with maximum possible font size
- neer.1304 April 21, 2019 in United States
The font size ranges from 1 to 30
You are given two APIs getCharacterWidth(char c , int font_size) and getCharacterHeight(int font_size)
getCharacterWidth(char c , int font_size): returns the width of a character for a particular font size
getCharacterHeight(int font_size): returns the height of characters for a particular font size| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswersYou are given a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers is missing in the list. Write an efficient code to find the missing integer.
- Nits April 08, 2019 in India| Report Duplicate | Flag | PURGE
Brocade Software Developer - 7of 7 votes
AnswersCount number of strings of length N with following properties:
- oaashifo April 08, 2019 in India for India
A. Consists of char 'A' and 'B' only.
B. There is atleast one occurrence of 3 consecutive Bs.
Input: Only line having integer N.
Output: Number of string with given properties. As then number can be very large print it with modulo 10^9+7.
Sample Input 1:
3
Sample Input 2:
1
Explanation: Only possible string "BBB"| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - 0of 0 votes
AnswersIts farewell day, there are total N students, every student has bought a gift to give. He/She will give this gift to some other student. After gifting process is over, you are given an array, representing number of gift student receive i.e. ith number denoting number of gift he/she got. Your task is to find, whether given gift count array is valid or not. If it is valid print any of possible way of gifting that lead given array.
- oaashifo April 08, 2019 in India for India
PS: Student can't gift to himself. Student has exactly one gift with himself.
Input: First line will have one integer M, denoting number of students. Next line wil have N spaced integers denoting number of gift student gets.
Ouput: -1, if given gift received array is not valid else print N spaced integers denoting ith gifted to jth.
Sample Input 1:
3
1 1 1
Sample Output 1:
2 3 1| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - 0of 0 votes
AnswersYou have given a string which consists of four characters {a,c,t,g}, find minimum length of unique substring which occurs only once.
- him4211 March 31, 2019 in United States
Eg:
Input :
#1 aacc
#2 actg
Output:
#1 2 3
#2 1 4
Explain:
aacc -> {aa, ac, cc} are the smallest unique string with single occurrence.| Report Duplicate | Flag | PURGE
Samsung Software Developer - 0of 0 votes
AnswersGiven a list of sorted lists each of size maximum size M, implement an iterator (maintain the order of items as in the original list of lists).
- sanjos February 04, 2019 in United States
I had a solution requiring extra space using minHeap; However, the interviewer was looking for a constant space solution.| Report Duplicate | Flag | PURGE
Microsoft Software Developer Algorithm - 1of 1 vote
AnswersGiven a directed graph and a node , find the shortest cycle in a graph with given node .
- saurabh January 23, 2019 in India| Report Duplicate | Flag | PURGE
Google Software Developer Coding - 0of 0 votes
AnswerHow to divide a circular array into k group of contiguous element such that difference between maximum sum and minimum sum is minimum. Each group have contiguous element of array. For e.g If the array is as follow. [6 13 10 2] and k=2 then o/p should be 18(6+10+2)-13=5. As array is circular 6,10,2 are contiguous element of array.
- him4211 January 05, 2019 in India
For e.g If the array is as follow. [6 13 2 10] and k=2 then o/p should be 16(6+10)-15(13+2)=1. As array is circular 6,10 are contiguous element of array.
For e.g If the array is as follow. [100 92 133 201 34 34 34 94 108] and k=4 then group as follow 208(108,100), 225(92,133), (201), 196(34,34,34,94) so 225-196=29| Report Duplicate | Flag | PURGE
Samsung Software Developer Algorithm - 1of 1 vote
Answersl1=[1,2,3,4]
- nikhil19kekan December 04, 2018 in United States for Community Operations
l2=[1,3,6,7,null,null,null,null]
output: l2=[1,1,2,3,3,4,6,7]| Report Duplicate | Flag | PURGE
Facebook Software Developer - 1of 1 vote
Answersk=2, l=[1,2,3,4,5,6]
- nikhil19kekan December 04, 2018 in United States for Community Operations
output: l=[5,6,1,2,3,4]
In place O(1) space complexity| Report Duplicate | Flag | PURGE
Facebook Software Developer Arrays - 3of 3 votes
AnswersYou have two sorted arrays, where each element is an interval. Now, merge the two array, overlapping intervals can be merged as a single one.
- Seetha November 11, 2018 in United States
I/P :
List 1 [1,2] , [3,9]
List 2 [4,5], [8, 10], [11,12]
O/P [1,2], [3,10], [11,12]| Report Duplicate | Flag | PURGE
Facebook Software Developer - 0of 0 votes
AnswersI/P [8, 3, 2, [5, 6, [9]], 6]
- Seetha November 11, 2018 in United States
O/P 8+3+2+2*(5+6+3*(9))+6 => 95| Report Duplicate | Flag | PURGE
Facebook Software Developer Arrays - 0of 0 votes
AnswersYou are given an array A of size N and Q queries. For each query, you are given two indices of the array L and R. The subarray generated from L to R is reversed. Your task is to determine the maximum sum of the subarrays.
- Sameer October 29, 2018 in United States
Note: After each query is solved, the array comes to its initial states.
Input format
First line: Two space-separated integers N and Q
Next line: N space-separated integers denoting the array elements.
Next
Q lines: Two space-separated integers in every line denoting the values of Li and Ri
Output format
For each query, print the required answer in a new line.
5 2
3 -1 4 2 -1
3 4
1 2
//output
8
9| Report Duplicate | Flag | PURGE
Facebook Software Developer - 2of 2 votes
AnswersGiven the root of a binary tree, print the nodes column wise and row wise.
..............6 ............/....\ ...........9......4 ........../..\......\ .........5....1.....3 ..........\........./ ...........0.......7
The answer would be 5 9 0 6 1 4 7 3.
- Champaklal October 26, 2018 in United States| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm - 0of 0 votes
AnswersExplain the difference between ORM and JDBC.
- mmoshikoo October 20, 2018 in United States
Provide some examples and when to use one over the other.| Report Duplicate | Flag | PURGE
Microsoft Software Developer General Questions and Comments - 0of 0 votes
Answersgiven two strings s1 and s2 we have to convert s1 into palindrome such that s1 contain s2 as a substring. in a minimum number of operation. wherein a single operation we can replace any word of s1 with any character.
- GB11 October 17, 2018 in India
constraint : |s1| <= 1000
|s2| <= |s1|
ex: s1 = "abaa" , s2 = "bb"
output : 1| Report Duplicate | Flag | PURGE
Walmart Labs Software Developer - 0of 0 votes
AnswersGiven an array which represents columns, find the position of two columns which when removed will trap the maximum amount of water. This is related to trapping raining water problem.
- Ashish October 17, 2018 in India| Report Duplicate | Flag | PURGE
Amazon Software Developer - 0of 0 votes
AnswersGiven an unsorted array find the maximum distance between two elements satisfying the condition A[i] < A[j] where i < j. There will always be a solution.
- Ashish October 17, 2018 in India
For eg. 6, 9, 3, 2, 10, 2, 3| Report Duplicate | Flag | PURGE
Amazon Software Developer - 0of 0 votes
AnswersDatabase query response times have increased. An API which is dependent on this database will see - *
- __Joker October 10, 2018 in India
This is a multi-select answer.
Increase in the latencies.
Increase in RAM utilisation on the API servers
Increase in CPU utilisation on the API servers
Increase in 200 response codes
Increase in 5xx responses| Report Duplicate | Flag | PURGE
unknown Software Developer Software Design - 0of 0 votes
AnswerSetting a value in cache is failing. What are the acceptable production practices? *
- __Joker October 10, 2018 in India
1. Raise an exception immediately
2. Retry in equal intervals of time until the set call succeeds
3. Retry with exponential back off until the set call succeeds
4. Retry 2 or 3 times with exponential back off.
5. Retry 2 or 3 times with equal intervals of time.
This is a multi-select question.| Report Duplicate | Flag | PURGE
unknown Software Developer System Design - 0of 0 votes
AnswerWe have a database that allows 2 concurrent writes and 3 concurrent reads. Each read/write operation takes 10ms to complete. What is the time taken to process all the requests in the orders mentioned (all requests can be assumed to be coming in at the same instant of time and are operating on a single row in a table) - 1. write, write, read, write, read, read, write, read 2. read, write, read, write, read: *
- __Joker October 10, 2018 in India
1. 30 ms 2. 10ms
1. 60 ms 2. 10ms
1. 10 ms 2. 10ms
1. 20 ms 2. 10ms
1. 10ms 2. 20ms
1. 60ms 2. 30ms| Report Duplicate | Flag | PURGE
unknown Software Developer Database - 1of 1 vote
AnswerGiven an array, coin of size n, coin[i] denotes the no. of coins on the position i. Can move any number of coins from the position i to (i+1) or (i-1). What is the minimum no. of moves required to redistribute the coins, so that each position i has at least 1 coin ?
- 00pzz October 06, 2018 in India
Note: Summation of total coins on the array is exactly n.| Report Duplicate | Flag | PURGE
Amazon Software Developer Arrays - 0of 0 votes
AnswersMorse code is a method of transmitting text information as series of long and short sounds or visual signals. Pauses are used during transmission to group letters and words. The common convention for writing morse code is to use dots (.) and dashes (-) for the short and long signals however without including pauses (e.g. as spaces) morse code quickly becomes ambiguous. For example the code -....--.... has 13 valid translations (bans, bates, bath, begs, digs, etc)
- K14 October 03, 2018 in India
Write a function getAllEnglishTranslations which takes a morse code without any pauses and returns all valid translations.
std::vector<std::string> getAllEnglishTranslations(std::string morseCode)
Output must be sorted in ascending alphabetical order.
Assume there are only 7 alphabets and below are their mappings
M = dash-dash (--)
C = dash-dot-dash-dot (-.-.)
O = dash-dash-dash (---)
D = dash-dot-dot (-..)
I = dot-dot (..)
N = dash-dot (-.)
G = dash-dash-dot (--.)
Assume input code is a valid morse code| Report Duplicate | Flag | PURGE
Software Developer - 0of 0 votes
AnswersGiven a bench with n seats and few people sitting, tell the seat number each time when a new person goes to sit on the bench such that his distance from others is maximum?
- shivamdurani220 September 22, 2018 in United States| Report Duplicate | Flag | PURGE
Google Software Developer