Software Engineer Interview Questions
- 3of 3 votes
AnswersThis was a 3 hours coding round in which we had to code 1 problem having 50 test cases. Only those students were selected for the next round who passed all the test cases. Here is the question:
- jatinbansal321 September 08, 2017 in India
You’ll be given a grid as below:
0 1 0 2 0
0 2 2 2 1
0 2 1 1 1
1 0 1 0 0
0 0 1 2 2
1 1 0 0 1
x x S x x
In the grid above,
1: This cell has a coin.
2: This cell has an enemy.
0: It contains nothing.
The highlighted(yellow) zone is the control zone. S is a spaceship that we need to control so that we can get maximum coins.
Now, S’s initial position will be at the center and we can only move it right or left by one cell or do not move.
At each time, the non-highlighted part of the grid will move down by one unit.
We can also use a bomb but only once. If we use that, all the enemies in the 5×5 region above the control zone will be killed.
If we use a bomb at the very beginning, the grid will look like this:
0 1 0 2 0
0 0 0 0 1
0 0 1 1 1
1 0 1 0 0
0 0 1 0 0
1 1 0 0 1
x x S x x
As soon as, the spaceship encounters an enemy or the entire grid has come down, the game ends.
For example,
At the very first instance, if we want to collect a coin we should move left( coins=1). This is because when the grid comes down by 1 unit we have a coin on the second position and by moving left we can collect that coin. Next, we should move right to collect another coin( coins=2).
After this, remain at the same position( coins=4).
This is the current situation after collecting 4 coins.
0 1 0 2 0 0 1 0 0 0
0 2 2 2 1 -->after using 0 0 0 0 1
x x S x x -->bomb x x S x x
Now, we can use the bomb to get out of this situation. After this, we can collect at most 1 coin. So maximum coins=5.| Report Duplicate | Flag | PURGE
Samsung Software Engineer - -1of 1 vote
AnswersEmployees Per Department
- aonecoding September 05, 2017 in United States
Twitter Interview Online Test SQL
A company uses 2 data tables, Employee and Department, to store data about its employees and departments.
Table Name: Employee
Attributes:
ID Integer,
NAME String,
SALARY Integer,
DEPT_ID Integer
Table Name: Department
Attributes:
DEPT_ID Integer,
Name String,
LOCATION String
View sample tables:
https://s3-us-west-2.amazonaws.com/aonecode/techblog/50cfcdd1d61f1bd6002cf4d3b4a61deb-min.jpeg
Write a query to print the respective Department Name and number of employees for all departments in the Department table (even unstaffed ones).
Sort your result in descending order of employees per department; if two or more departments have the same number of employees, then sort those departments alphabetically by Department Name.| Report Duplicate | Flag | PURGE
Twitter Software Engineer SQL - 1of 1 vote
AnswersThe numbers on a telephone keypad are arranged thus:
1 2 3 4 5 6 7 8 9 0
Starting from any digit, and choosing successive digits as a knight moves in chess, determine how many different paths can be formed of length n. There is no need to make a list of the paths, only to count them.
- ajay.raj September 04, 2017 in United States
A knight moves two steps either horizontally or vertically followed by one step in the perpendicular direction; thus, from the digit 1 on the keypad a knight can move to digits 6 or 8, and from the digit 4 on the keypad a knight can move to digits 3, 9 or 0. A path may visit the same digit more than once.
Your task is to write a function that determines the number of paths of length n that a knight can trace on a keyboard starting from any digit .
public int findNumberOfPaths(int digit, int step){| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 1of 1 vote
Answers## This is the text editor interface.
- wonderkid September 02, 2017 in United States
## Anything you type or change here will be seen by the other person in real time.
# Implement the function that takes a board string
# and decodes it into the representative 2D array.
#
# |_|_|_|_|_|_|_|
# |_|_|r|_|_|_|_|
# |b|r|b|r|b|r|_|
# |b|b|b|r|r|b|_|
# |b|r|r|b|b|r|_|
# |r|b|b|r|r|r|b|
# CFN: 9_r4_brbrbr_3b2rb_b2r2br_r2b3rb
#
# This function should return a list of lists of strings.
# (i.e. a string[6][7]). The strings should be one of:
# * 'r' to indicate a red piece
# * 'b' to indicate a black piece
# * '_' to indicate an empty space
#
# The input string is not necessarily a valid
# CFN board string. It is guaranteed not-empty.| Report Duplicate | Flag | PURGE
Palantir Technology Software Engineer Python - 1of 1 vote
AnswerIII. Square root of a number?
- aonecoding August 30, 2017 in United States
IV. Expression operators? Add signs (+, -, *, /) to a string to form target
V. Top trending posts in last 5m, 1H, 1Day?| Report Duplicate | Flag | PURGE
Linkedin Software Engineer Algorithm - 0of 0 votes
AnswersI. Closest K nodes to a target in BST? (Do it in O(n)?)
- aonecoding August 30, 2017 in United States
II. Nested List sum?| Report Duplicate | Flag | PURGE
Linkedin Software Engineer Algorithm - 2of 2 votes
AnswersGenerate a random binary tree, with equal probability.
- pb August 30, 2017 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - -2of 2 votes
AnswersMedian of Stream of Running Integers
- anaghakr89 August 16, 2017 in United States
Note: The integers are in particular range from 1..n
The time complexity of the code should be o(n)| Report Duplicate | Flag | PURGE
Google Software Engineer - 1of 1 vote
AnswersIf you are given 2 infinitely large integers in the form of strings, given the length of the string, find the product of the two integers.
- Anon August 15, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersHow will you multiply two infinitely large integers.
- Anon August 15, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswerSolve the 24 Game
- aonecoding August 14, 2017 in United States| Report Duplicate | Flag | PURGE
Twitter Software Engineer Algorithm - 0of 0 votes
AnswerProblem:
- yangsuli August 13, 2017
Given 100 stones, two players alternate to take stones out. One can take any number from 1 to 15; however, one cannot take any number that was already taken. If in the end of the game, there is k stones left, but 1 - k have all been previously taken, one can take k stones. The one who takes the last stone wins. How can the first player always win?
My Idea
Use recursion (or dynamic programming). Base case 1, where player 1 has a winning strategy.
Reducing: for n stones left, if palyer 1 takes m1 stones, he has to ensure that for all options player 2 has (m2), he has a winning strategy. Thus the problem is reduced to (n - m1 - m2).
Follow Up Question:
If one uses DP, the potential number of tables to be filled is large (2^15), since the available options left depend on the history, which has 2^15 possibilities.
How can you optimize?
I don't have a great answer to the follow up question。。。| Report Duplicate | Flag | PURGE
Huawei Software Engineer Dynamic Programming - 3of 3 votes
AnswersRound4
- aonecoding August 09, 2017 in United States
Starting from num = 0, add 2^i (where i can be any non-negative integer) to num until num == N. Print all paths of how num turns from 0 to N.
For example if N = 4,
Paths printed are [0,1,2,3,4], [0,1,2,4], [0,1,3,4], [0,2,4], [0,2,3,4], [0,4].
[0,2,4] is made from 0 + 2^1 + 2^1. [0,1,3,4] from 0 + 2^0 + 2^1 + 2^0| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersRound3
- aonecoding August 09, 2017 in United States
For N light bulbs, implement two methods
I. isOn(int i) - find if the ith bulb is on or off.
II. toggle(int start, int end)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersRound1
- aonecoding August 09, 2017 in United States
Find if two people in a family tree are blood-related.
Round2
Given some nodes in a singly linked list, how many groups of consecutively connected nodes there is.
For linked list
0->1->2->3->4->5->6,
given nodes 1, 3, 5, 6
there are 3 groups [1], [3], and [5, 6].| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersExplain the linear piecewise function.
- anaghakr89 August 09, 2017 in United States for Nest Labs| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersExplain event driven programming in C with example
- anaghakr89 August 09, 2017 in United States| Report Duplicate | Flag | PURGE
Apple Software Engineer - 2of 2 votes
AnswersWe have N gas stations, and we are given all the distances between each pair of station. So we have nC2 distances provided to us. For example if I have 3 stations namely A, B, C the distances provided will be AB, AC, BC. We have to find the exact position of each gas station provided with these nC2 distances.
- logan9 August 05, 2017 in United States
eg. we have 5 stations so 5C2 distances are given in random order - 10, 20, 70, 80, 30, 20, 100, 70, 50, 90
Output the exact positions of gas stations A, B, C, D, E
i.e
A - 0
B - 10
C - 30
D - 80
E - 100
refer this image for more clarity
https://drive.google.com/open?id=0BxPkptdH01OBZzEwX29iRGI4cEU| Report Duplicate | Flag | PURGE
Google Software Engineer Problem Solving - 1of 1 vote
AnswersRound 5:
- aonecoding August 03, 2017 in United States
Given a set of synonyms such as (fast, quick), (fast, speedy), (learn, study), decides if two sentences were synonymous.
(The sentences were structurally the same and has the same number of words in them.
The synonymous relation [fast ~ quick] and [fast ~ speedy] does not necessarily mean [quick ~ speedy].)
Follow-up:
If the synonymous relation passes down so that [fast ~ quick] and [fast ~ speedy] implies [quick ~ speedy], decide if two sentences were synonymous.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersRound 4:
- aonecoding August 03, 2017 in United States
Implement a class Employment with these 3 methods: assignManager(p1, p2): assign p1 as p2's manager. beColleague(p1, p2): make p1 and p2 peer colleagues. isManager((p1, p2): decide if p1 is the manager of p2.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersRound 3
- aonecoding August 03, 2017 in United States
Given a matrix of 0s and 1s where 0 is wall and 1 is pathway, print the shortest path from the first row to the last row.
Can walk to the left, top, right, bottom at any given spot.
Follow-up:
If every pathway takes a cost (positive integer) to get through, print the minimum cost path from the first row to the last row.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersGoogle on-site June
- aonecoding August 03, 2017 in United States
Round 1
Leetcode 10
Round 2
Select a random point uniformly within a rectangle, (The side of rectangle is parallel to the x/ y grid).
Follow-up: Given multiple non-overlapped rectangles on the 2D grid, uniformly select a random point from the rectangles.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 2of 2 votes
AnswersPhone Interview Amazon, Seattle
- aonecoding July 28, 2017 in United States
I. Get the sum of all prime numbers up to N. primeSum(N).
Follow-up: If primeSum(N) is frequently called, how to optimize it.
II. OODesign Parking Lot| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 2of 2 votes
AnswersGiven a list of input tasks to run, and the cooldown interval, output the minimum number of time slots required to run them.
- neel.c July 26, 2017 in United States
// Tasks: 1, 1, 2, 1, 2
// Recovery interval (cooldown): 2
// Output: 8 (order is 1 _ _ 1 2 _ 1 2 )
=========
Tasks are task numbers in that order coming in for execution. Cooling time is time interval required to cool down the machine after executing a task. So it's like if CPU executed task 1 then it needs 2 cooling time intervals before executing another task 1 but meanwhile, it can execute other tasks which are not same as 1 and so on. So before executing any task, you have to check if you have executed same task number before and if yes, then if its cooling time interval is done or not.
The output is basically the number of cycles/time slots CPU took to execute these tasks in that order (including when task executed and cooling intervals).| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 2of 2 votes
AnswersApple Map Team
- aonecoding July 25, 2017 in United States
1. Given an array A and some queries, query(i, j) returns the result of Ai*...*Aj, in other words the multiplication from Ai to Aj.
The numbers in A are non-negative.
Implement query(i, j).
2. Flatten nested linked list
3. POI search design
4. LC238 & LC279| Report Duplicate | Flag | PURGE
Apple Software Engineer Algorithm - 3of 3 votes
AnswersYou are given an old touch smartphone numbers having dial pad and calculator app.
- neovivek14 July 23, 2017 in United States
Aim: The goal is to type a number on dialpad.
But as phone is old, some of the numbers and some operations can't be touched.
For eg. 2,3,5,9 keys are not responding , i.e you cannot use them
But you can always make a number using other numbers and operations in Calculator. There could be multiple ways of making a number
.Calculator have 1-9 and +,-,*,/,= as operations. Once you have made the number in Calculator you can copy the number and use it.
You have to find minimum number to touches required to obtain a number.
#Input:#
There will be multiple Test cases .Each test case will consist of 4 lines
1) First line will consist of N,M,O
N: no of keys working in Dialpad (out of 0,1,2,3,4,5,6,7,8,9)
M:types of operations supported (+,-,*,/)
O: Max no of touches allowed
2) second line of input contains the digits that are working e.g 0,2,3,4,6.
3) Third line contains the valued describing operations, 1(+),2(-),3(*),4(/)
4) fourth line contains the number that we want to make .
#Output:#
Output contains 1 line printing the number of touches required to make the number
#Sample Test Case:#
1 // No of test cases
5 3 5 // N ,M, O
1 2 4 6 0 // digits that are working (total number of digits = N),
1 2 3 // describing operations allowed (1--> '+', 2--> '-', 3--> '*' , 4--> '/' )(total number is equals to M)
5 // number we want to make
Answer 3
How 4? 1+4= , "=" is also counted as a touch
2nd Sample Case
3 // No of Test cases
6 4 5 // N ,M, O
1 2 4 6 9 8 // digits that are working (total number of digits = N),
1 2 3 4 // describing operations allowed (1--> +, 2--> -, 3--> , 4-->/)
91 // number we want to make
6 2 4 // 2nd test case
0 1 3 5 7 9
1 2 4 // +, -, / allowed here
28
5 2 10
1 2 6 7 8
2 3 // -, allowed
981
#Output:#
2 // 91 can be made by directly entering 91 as 1,9 digits are working, so only 2 operations
5// 35-7=, other ways are 1+3*7=
9//62*16-11=
Order for computation will be followed as symbols entered, if + comes, it will be computed first
One more example: lets say 1,4,6,7,8,9 works and +,-,* works.
2,3,5 and / doesn't work.
If you have to type 18-> 2 operations. (Each touch is considered an operation),br> If you have to type 5 -> '1+4=' that requires 4 operations. There could be other ways to make '5'.| Report Duplicate | Flag | PURGE
Samsung Software Engineer Algorithm - 0of 0 votes
AnswersComplete the puzzle which simulates generic directory structures.
- Sameer July 21, 2017 in United States
* The solution should be directory agnostic.
* Be succinct yet readable. You should not exceed more than 200 lines.
* Consider adding comments and asserts to help the understading.
* Code can be compiled with javac Directory.java
* Code should be executed as: java -ea Directory (-ea option it's to enabled the assert)
*/
/**
* change the code here.
*/
class Shell {
Shell cd(final String path) {
return this;
}
public String path() {
return "/";
}
}
public class Directory {
public static void main(String[] args) {
final Shell shell = new Shell();
assert shell.path().equals("/");
shell.cd("/");
assert shell.path().equals("/");
shell.cd("usr/..");
assert shell.path().equals("/");
shell.cd("usr").cd("local");
shell.cd("../local").cd("./");
assert shell.path().equals("/usr/local");
shell.cd("..");
assert shell.path().equals("/usr");
shell.cd("//lib///");
assert shell.path().equals("/lib");
}
}| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer - 2of 2 votes
Answers4/5 Round at Uber
- aonecoding July 20, 2017 in United States
Coding: Given a 2D array of either '\' or '/', find out how many pieces this rectangle is divided into graphically.
For a 2X2 matrix with
/\
\/
The matrix split into 5 pieces - the diamond in middle and the four corners. Return 5 as the answer.
5/5 Round at Uber
Design Excel.| Report Duplicate | Flag | PURGE
Uber Software Engineer Algorithm - 1of 1 vote
Answers2/5 Round at Uber
- aonecoding July 20, 2017 in United States
Bar raiser - Behavioral questions. Coding: Find if a set of meetings overlap. Meeting has a starttime and an endtime with accuracy to minute. All meetings take place in the same day. Do this in O(n) time.
3/5 Round at Uber
Coding: Subset sum. Follow-up: Optimize the solution.| Report Duplicate | Flag | PURGE
Uber Software Engineer Algorithm - 0of 0 votes
Answers1/5 Round at Uber
- aonecoding July 20, 2017 in United States
Manager : Behavioral questions. Basic system design concepts. Publish/subscribe model. Discussion on Uber architecture.| Report Duplicate | Flag | PURGE
Uber Software Engineer System Design
Open Chat in New Window