SDE1 Interview Questions
- 0of 0 votes
AnswerGive an N-length array with only 0 and 1 inside
- ajay.raj May 01, 2018 in United States
Requires to find the minimum number of conversions needed to convert the array to 0 before all 1.
The conversion is to change a 0 to 1 or a 1 to 0,
And the number of 0 and 1 in the converted array can be arbitrary.
Just find the minimum conversion step| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswerGiven list of schedules for different flights in a month, determine maximum number of flights that can be in the air anytime in that month.
- sanjureddy.v April 14, 2018 in United States
Input : list of schedules for flights.- spread over a month.
output: a number - maximum flights that can be in the air
Assumptions: 1. All the given times are in a specific timezone( like GMT).
2. Given Schedules can be any time in the month| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 0of 0 votes
AnswersTo an array and K, each element in the array can only move K positions to the left at most, no limit to the right, try to sort the array under the limit of K
- ajay.raj April 10, 2018 in United States
a = [5, 2, 4, 3, 1], k = 2
Return [2, 3, 1, 4, 5]| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven a function rand32() (random number range 0-2**32-1) that randomly generates a 32-bit int, design a new random function:
- ajay.raj April 09, 2018 in United States
Randn(n) generates a random distributed random number (0 - 2**n-1)
Rand3n(n) generates (0 - 3**n-1) the uniformly distributed random number| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerTopic: There is a set of coordinates. The original format of each coordinate is (1.3, 0.5). However, the comma and decimal point are gone. Only one string is left, allowing you to restore all possible combinations. For example, 123, possible (1, 23) (1, 2.3) (12, 3) (1.2, 3)
- ajay.raj April 09, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersImplement a method to check if a n-ary tree is unival
- ajay.raj April 04, 2018 in United States
class TreeNode {
int val;
List<TreeNode> children;
TreeNode(int val) {
this.val = val;
children = new ArrayList<>();
}
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven the length and width of a rectangle, how many ways can be used to go from the upper left corner to the upper right corner (each step can only go to the right, top right or bottom right):
- ajay.raj April 03, 2018 in United States
-follow up 1: If three points in the rectangle must be visited, how many ways
-follow up 2: If you are given an point H, and the path must go down below the H point, how to do it| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms an n-nary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night.
- ajay.raj March 31, 2018 in United States
Determine the maximum amount of money the thief can rob tonight without alerting the police.
/**
* Definition for a n-ary tree node.
* public class TreeNode {
* int val;
* List<TreeNode> kids;
* }
*/
class Solution {
public int rob(TreeNode root) {
}
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answerspreorder Traversing a n-ary tree without using recurrsion
- ajay.raj March 31, 2018 in United States
TreeNode<T> {
T val;
List<TreeNode> children;
}| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGiven two methods for the person class, one to find a dad and one to find a mother, using these two methods to achieve a method to determine whether the two people are related to blood, assuming a limited number of people.
- ajay.raj March 30, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersSelf-implemented data structures and methods, output all the heirs. To achieve birth (parent, name), dead (name), getAllSucession (). There is a king, you can use birth plus children, dead dead. The order of inheritance is the same as preorder except that this tree has multiple children.
- ajay.raj March 30, 2018 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - -2of 2 votes
AnswersQuestion 2: Given a number 'k', return the corresponding row, given the pattern:
- mche1987 March 27, 2018 in United States
k => output
0 => []
1 => ["0", "1", "8"]
2 => ["00", "11", "69", "96", "88"]
3 => ["000", "111", "101", "888", ...] // and so on ...| Report Duplicate | Flag | PURGE
Facebook SDE1 Algorithm - 0of 0 votes
AnswersQuestion 1: Given an input of an array of string, verify if, turned 180 degrees, it is the "same".
- mche1987 March 27, 2018 in United States
For instance:
[1, 6, 0, 9, 1] => return true
[1, 7, 1] => return false| Report Duplicate | Flag | PURGE
Facebook SDE1 Algorithm - 1of 1 vote
AnswersGiven a binary matrix, find if there is a path from the upper left corner to the lower right corner, meet the conditions each time the value of the cell must be different.
- ajay.raj March 06, 2018 in United States
Follow up if there is a path with the same number of 0 and 1?| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerThere are three threads and we want them to run
- ajay.raj March 05, 2018 in United States
one after the other. How can we do that?| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersIn a grid, you are given a position, and every location has some value.
- ajay.raj March 05, 2018 in United States
find the shortest length so that you can touch to any boundary of the grid.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersYou are given a graph and an algorithm that can find the shortest
- ajay.raj March 05, 2018 in United States
path between any two nodes
Now you have to find the second shortest path between same two nodes.| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswerFind product of distinct prime
- ajay.raj March 05, 2018 in United States
factor of all numbers .
Ex
10
12
7
prime factor of 10 = 2*5
prime factor of 12 = 2*2*3
prime factor of 7 = 7
SO distinct prime factor is 2*5*3*7 = 210| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answersencode binary in bytes is to give a matrix of size M * N,
- ajay.raj March 05, 2018 in United States
This matrix is encoded in bytes as a 4 * 4 bool matrix
[0 0 0 0
1 0 0 1
0 0 0 0
0 0 0 1]
Will be encoded as a byte array [9, 1].
Then write a function set_one (vector <byte> arr, int M, int N, int start_row, int start_col, int end_row, int end_col);
Set all of 0 from (start_row, start_col) to (end_row, end_col) to 1
for example
start_row = 1
start_col = 2
end_row = 2
end_col = 0,
Just that 4 * 4matrix will become
[0 0 0 0
1 0 1 1
1 0 0 0
0 0 0 1]
The byte array after encode should be rewritten as [11, 129].| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
Answersfind out all of the state machine will guaranteed to come to safe state
- ajay.raj March 05, 2018 in United States
ex
A -> [B, C, D, E]
B -> [A]
C -> [D, E]
D -> [E].
E -> [safe state]
Output [C, D, E] because once these states will eventually go to safe state| Report Duplicate | Flag | PURGE
Amazon SDE1 - 0of 0 votes
AnswersGive N socks, there is no guarantee that each can be paired, socks two colors, black and white, you need to pair them
- ajay.raj February 22, 2018 in United States| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
Answerscss color format # abcdef, another abbreviated color format # rgb
- ajay.raj February 22, 2018 in United States
(Converted to the previous format, ie, #rrggbb.) Now give your #abcdef, the first color format, to find the two least different colors, #rgb.| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
Answers/*Coding question: The customers for a particular business, required to use a webpage to select a Browse Node.
- pragramticProgrammer February 22, 2018 in United States
A Browse Node, is an element in the classification structure used to classify products in the Amazon webpage.
The products are classified in 8 categories. Each category has its own sub-classification that looks like a tree with many
children per node and many levels. The UI developer has a tool to paint such tree. He requires from you (You are the backend developer)
to implement 2 interfaces for him:
Node getRoot();
List<Node> getChildren(Node node);
The data is available for you in a text file with this format:
//nodeid, parent_node_id, nodename
Example:
//nodeid, parent_node_id, nodename
10, 1, Comedy Books
20, 2, Tablets
1, -1, Books
11, 1, Novels
12, 11, Terror novels
2, -1, Electronics
-1, 0, GlobalRoot
*/| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersA sequence of strings, printed first by column, on a screen of width K,
- ajay.raj February 06, 2018 in United States
Requires the first column of the same column by column alignment,
At least one character interval between columns and columns,
Ask how many lines at least?
such as:
The string sequence is {"abc", "de", "fghij", "k", "lmno", "p"}
The screen width is 10
The answer is at least 3 lines
abc k
de lmno
fghij p| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersGiven list of strings like “ crane, drain, refrain” and a pattern such as *an*
- tushr1388 February 05, 2018 in United States
where * can match any number of chracters.
Return the matching word in an efficient manner.
Answer to above question : crane| Report Duplicate | Flag | PURGE
Facebook SDE1 Java - 0of 0 votes
AnswersGiven a string, at each time, you can move any one of the char to the front,
- ajay.raj February 01, 2018 in United States
ask you to find the minimum such move to get the target string
example
source abc, target cba :
abc -> bac -> cba
return 2| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersMinimum Continuous Subsequence: targetList & availabletTagsList are two lists of string.
- pragramticProgrammer January 31, 2018 in United States
Input:
targetList = {"cat", "dog"};
availableTagsList = { "cat", "test", "dog", "get", "spain", "south" };
Output: [0, 2] //'cat' in position 0; 'dog' in position 2
Input:
targetList = {"east", "in", "south"};
availableTagsList = { "east", "test", "east", "in", "east", "get", "spain", "south" };
Output: [2, 6] //'east' in position 2; 'in' in position 3; 'south' in position 6 (east in position 4 is not outputted as it is coming after 'in')
Input:
targetList = {"east", "in", "south"};
availableTagsList = { "east", "test", "south" };
Output: [0] //'in' not present in availableTagsList
Note: targetList will contain Distinct string objects.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven one string s1, and then insert one char into this string at any place, to get s2, find the inserted char
- ajay.raj January 25, 2018 in United States
Could you do it in logn time| Report Duplicate | Flag | PURGE
Google SDE1 - -1of 1 vote
AnswersGiven a MxN matrix where each element can either be 0 or 1. We need to print the shortest path between a given source cell to a destination cell. The path can only be created out of a cell if its value is 1.
- ajay.raj January 15, 2018 in United States
BFS is trival, please solve it use DFS
public void print(int[][] matrix, int[] start, int[] end){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersYou are given with a large paragraph and N words.
- avi007 January 09, 2018 in India
You have to find a min length subparagraph of the paragraph which contain all those N words in any order. Here length of a paragraph is the count of words in the paragraph.| Report Duplicate | Flag | PURGE
Amazon SDE1