SDE1 Interview Questions
- 0of 0 votes
AnswerDelete files of size more than 100mb in a folder which are older than 90 days.
- priyanka.mandal1691 February 08, 2017 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Unix - 0of 0 votes
AnswersGiven a comma separated file print the last but one column of every line.
- priyanka.mandal1691 February 08, 2017 in India
e.g:
a,b,c,d,e,f
1,2,3,4
w,x,y,z
output should be
e
3
y| Report Duplicate | Flag | PURGE
Amazon SDE1 Unix - 0of 0 votes
AnswersA binary tree and a number, say k are given. Print every path in the tree with sum of the nodes in the path as k.(A path can start from any node and end at any node, i.e. they need not be root node and leaf node; and negative numbers can also be there in the tree)
- SIVA R February 07, 2017 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 1of 1 vote
AnswersGiven an integer target and binary tree (not a binary search tree!) each of whose nodes contains an integer (which may be positive or negative), find the set of all subtrees whose sum equals the given target. The sum of a subtree is just the sum of the integers contained in its nodes. Note that the subtree does not have to contain all child nodes - it can be any set of connected nodes.
- Aloo February 03, 2017 in India| Report Duplicate | Flag | PURGE
SDE1 Data Structures - 1of 1 vote
AnswerYou are given an array A[] with n elements. You are given S[], E[] and H[] array with each M elements.
- Richa Tibrewal February 01, 2017 in India
Apply an operation such that all the elements from A[ S[i] ] and A[ E[i] ] will be less than H[i].
Example :
given array A[] = [2,4,8,6,7]
S[0] = 1
E[0] = 4
H[0] = 5
So, after doing an operation, the resulting array is A[] = [ 2,4,5,5,5]
Thus, u need to do the same thing for all i.
After doing this, find out the maximum element in the array.| Report Duplicate | Flag | PURGE
Directi SDE1 Algorithm - 1of 1 vote
AnswersPrint elements of a matrix in spiral form.
- yasharonline January 12, 2017 in United States for Azure| Report Duplicate | Flag | PURGE
Microsoft SDE1 Matrix - 0of 0 votes
AnswersIt was an over email interview:
- yasharonline January 11, 2017 in United States
Write a program that takes as input a sufficiently large text document (several are available online for testing; e.g. via Project Gutenberg), and produces as output (via stdout) an alphabetical listing of each unique word in the document (case insensitive and space separated, though be careful to consider hyphenated words), along with the lines from the input document that the word appears on. Each unique word (and the list of lines that it appears on) should be on a separate line in the output.
For example, taking the following text as input:
This is
some kind OF text it
Is an example of text
The following would be the output:
an 3
example 3
is 1 3
it 2
kind 2
of 2 3
some 2
text 2 3
this 1| Report Duplicate | Flag | PURGE
Apkudo SDE1 Sorting - -3of 3 votes
AnswersC++ Questions
- anony December 23, 2016 in United States| Report Duplicate | Flag | PURGE
Morgan Stanley SDE1 - 1of 5 votes
AnswersFind sum of n elements after kth smallest element in BST. Tree is very large, you are not allowed to traverse the tree.
- gvikram244 December 06, 2016 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven a nxn matrix, with partially filled cells of numbers from 1..n and the rest with 0's. Fill the cells such each row and column has numbers 1 to n without any repetition.
- faizvf November 14, 2016 in United States
Eg:
[
[1, 2, 0],
[0, 1, 0],
[0, 0, 1]
]
[
[1, 2, 3],
[3, 1, 2],
[2, 3, 1]
]| Report Duplicate | Flag | PURGE
Yahoo SDE1 Algorithm - 1of 1 vote
AnswersGiven an NxN grid with an array of lamp coordinates. Each lamp provides illumination to every square on their x axis, every square on their y axis, and every square that lies in their diagonal (think of a Queen in chess). Given an array of query coordinates, determine whether that point is illuminated or not. The catch is when checking a query all lamps adjacent to, or on,…
- ad09 October 16, 2016 in United States| Report Duplicate | Flag | PURGE
Google SDE1 - 0of 0 votes
AnswersYou are a string conscious guy. You categorise strings into 3 types: good, bad, mixed. If a string has 3 consecutive vowels or 5 consecutive consonants or both, it is bad. Else it is good. If a string has ‘?’, that can be replaced with any character. Thus, string ‘?aa’ can be bad if ‘?’ is vowel or good if consonant. Thus, it is mixed. Implement function which takes string s as input and returns good, bad or mixed
- novicedhunnu October 11, 2016 in India| Report Duplicate | Flag | PURGE
Adobe SDE1 Algorithm - 0of 0 votes
AnswersYou are a musician who plays different songs at different volumes. You have a particular difference that needs to be present for new song, but you don't care if it is more or less. You are given initial volume l, array of volume changes where arr[i] is volume change required after i-th song, max_vol h (min vol always 0), array size n. You need to find the max possible volume for the last song. But if at any point change is not possible, return -1. Format: n, arr[n], l, h. Ex: 3, 1 1 1, 0, 5. Ans: 3. Ex: 4, 9 1 5 4, 8, 15. Ans: -1. Ex: 3, 5 3 7, 5, 10. Ans: 10.
- novicedhunnu October 11, 2016 in India
Input explanation :
First number = size of array,
then next ‘n’ numbers of array.
Then ‘l’ means initial volume
Then ‘h’ means max volume.
Eg. 3, 1 1 1, 0, 5 means n = 3, arr = {1,1,1}, l = 0, h = 5,
Output explanation: initially you play music at vol 0, then for first arr element. Arr[0] inc. by 1,
Arr[1] inc. by 1, arr[2] inc by 1 total = 3| Report Duplicate | Flag | PURGE
Adobe SDE1 Algorithm - 0of 0 votes
AnswersImplement method:
Lìst<Range> getRanges(Lìst<Shard> shards, Lìst<Key> keys)
That returns list of ranges. Each range represents multiple keys aggregated over a shard:
n-keys —> 1-shard —> l-range
Method should return no more than 1 range per shard that spans all keys or their parts belonging to this shard.
Each of the ‘Range` , 'Shard’ and ‘Key’ classes have ‘end’ and ‘start’ fields of int type, where ‘start’ is inclusive and ‘end’ is exclusive.
Example:
- ermilanardeshana September 21, 2016 in United States1—9, 12—59, 100—999 <— shards (input) 2—3, 6—8, 11—20, 200—220 <— keys (input) 2—8, 12—20, 200—220 <— ranges (output)
| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 1of 1 vote
AnswersA list of words is given and a bigger string given how can we find whether the string is a permutation of the smaller strings.
- novicedhunnu September 15, 2016 in India
eg- s= badactorgoodacting dict[]={'actor','bad','act','good'] FALSE
eg- s= badactorgoodacting dict[]={'actor','bad','acting','good'] TRUE
The smaller words themselves don't need to be permuted. The question is whether we can find a ordering of the smaller strings such that if concatenated in that order it gives the larger string
One more constraint - some words from dict[] may also be left over unused| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 0of 0 votes
AnswersGiven the following inputs, return a list of rooms that are available and large enough:
- MM August 04, 2016 in United States
# of people
Start Time
End Time
You should return
total list of rooms
capacity of each rooms
availability| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersThe stepping number:
- abhishek.agar2 July 31, 2016 in India
A number is called as a stepping number if the adjacent digits are having a difference of 1. For eg. 123,121,9878 are all stepping numbers. While 890, 098,012 are not i.e. a number should not start with 0.
Also all 1-digit numbers are stepping numbers.
Find out how many stepping numbers exist with number of digits =N (input given)| Report Duplicate | Flag | PURGE
Toppr SDE1 Algorithm - 2of 2 votes
Answers10000 cameras, 100 hours of video each. 30 fps. Police need to input a plate number and find the path of a suspicious vehicle. (Estimate the size of the video, e.g., blueray disc is 2 hours and 20 GB. No need to scan all of the videos. Estimate the time that a vehicle can be seen between 2 traffic cameras, e.g., 0.3 miles and 30 miles per hour, then select 1 out of 100). Web client, load balancer, servers, db.
- kwangrand July 31, 2016 in United States for Kindle| Report Duplicate | Flag | PURGE
Amazon SDE1 System Design - 0of 0 votes
AnswersHow do I solve this simple geometrical programming problem?
- axaysd July 30, 2016 in United States
https://s32.postimg.org/sm75dimol/hurdle1.jpg| Report Duplicate | Flag | PURGE
Microsoft SDE1 - 1of 1 vote
AnswersHow do I find the longest possible route in a matrix?
- axaysd July 30, 2016 in United States
There are some hurdles in the path.
Details in image : https://s31.postimg.org/7nwp4gmzv/hurdle1.jpg| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersProblem : Christmas Tree
- axaysd July 30, 2016 in United States
Chirag is a boy. And his one and only dream is to meet Santa Claus. He decided to decorate a Christmas tree for Santa on coming Christmas. Chirag made an interesting Christmas tree that grows day by day.
The Christmas tree is comprised of the following
Parts
Stand
Each Part is further comprised of Branches. Branches are comprised of Leaves.
How the tree appears as a function of days should be understood. Basis that print the tree as it appears on the given day. Below are the rules that govern how the tree appears on a given day. Write a program to generate such a Christmas tree whose input is number of days.
Rules:
If tree is one day old you cannot grow. Print a message "You cannot generate christmas tree"
Tree will die after 20 days; it should give a message "Tree is no more"
Tree will have one part less than the number of days.
E.g.
On 2nd day tree will have 1 part and one stand.
On 3rd day tree will have 2 parts and one stand
On 4th day tree will have 3 parts and one stand and so on.
Top-most part will be the widest and bottom-most part will be the narrowest.
Difference in number of branches between top-most and second from top will be 2
Difference in number of branches between second from top and bottom-most part will be 1
Below is an illustration of how the tree looks like on 4th day
https://s31.postimg.org/5s1txk4zf/christmas_tree.jpg
https://s32.postimg.org/i2c6i850l/christmas_tree_2.jpg| Report Duplicate | Flag | PURGE
Google SDE1 - 2of 2 votes
AnswersGiven some resources in the form of linked list you have to canceled out all the resources whose sum up to 0(Zero) and return the remaining list.
- ganesh.eng2015 July 24, 2016 in India
E.g-->> 6 -6 8 4 -12 9 8 -8
the above example lists which gets canceled :
6 -6
8 4 -12
8 -8
o/p : 9
case 3 : 4 6 -10 8 9 10 -19 10 -18 20 25
O/P : 20 25| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersIn an incoming stream of +ve integers, return true if 2 numbers with sum equal to 10 has occurred till now.
- ganesh.eng2015 July 24, 2016 in India
How to handle stream of numbers| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersGiven an array,find all valid ip-address form this array.
- ganesh.eng2015 July 24, 2016 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersFind the number of column-swaps required to find the largest rectangle of all ones in a matrix.
- novicedhunnu July 19, 2016 in India for N/A
The question is similar to the one in this link-
http://www.geeksforgeeks.org/find-the-largest-rectangle-of-1s-with-swapping-of-columns-allowed/
But we need to find the number of minimum swaps required| Report Duplicate | Flag | PURGE
Walmart Labs SDE1 - 0of 0 votes
AnswerWrite a function that takes a string of javascript code as parameter and returns a new string with these literals standardized on double quotes.
- MM July 07, 2016 in United States
For example if the input is
/* This method says 'hello'*/
function sayHello()
{alert('hello')}
The out put should be
/* This method says 'hello'*/
function sayHello()
{alert("hello")}
The quoted text in the code section of the function should be changed to double quotes. The quotes used in the comments section should be left alone.
static string standardizeJavaScript(string inputJavaScript)
{
string temp = string.Empty;
if (string.IsNullOrEmpty(inputJavaScript))
return inputJavaScript;
bool updateQuote = false;
string output = string.Empty;
string[] split = inputJavaScript.Split('\n');
for (int i = 0; i < split.Length; i++)
{
if (split[i].Contains("{"))
updateQuote = true;
//if (split[i].Contains("{"))
// updateQuote = false;
if (updateQuote)
{
split[i] = split[i].Replace("'", "\"");
output = output +"\n" + (split[i]);
}
}
return output;
}| Report Duplicate | Flag | PURGE
First Orion SDE1 - 0of 0 votes
AnswersWrite a function that will give the number of intersections between 2 strings. The function should take two string parameters which represents 2 words that may or may not intersect.The method should return the count of intersections which are found. For example, if the input is word 1 - Sales, word 2 - isles. The out put should be 4.
The word sales and isle intersects in 4 places.
1. The 2nd letter of isle intersects with the 1st letter of sales.
2. The 2nd letter of isle intersects with the 5th letter of sales.
3. The 3rd letter of isle intersects with the 3rd letter of sales.
4. The 4th letter of isle intersects with the 4th letter of sales.
- MM July 07, 2016 in United Statesstatic int numberOfIntersections(string word1, string word2) { if (string.IsNullOrEmpty(word1) || string.IsNullOrEmpty(word2)) return 0; string shorterWord = string.Empty; string longerWord = string.Empty; //Identify the shorter word and the longer word if (word1.Length < word2.Length) { shorterWord = word1.Trim(); longerWord = word2.Trim(); } else { shorterWord = word2.Trim(); longerWord = word1.Trim(); } //Create a dictionary with the characters of the shorter word Dictionary<char, int> lookup = new Dictionary<char, int>(); Dictionary<char, int> duplicates = new Dictionary<char, int>(); foreach (char c in shorterWord) { if (!lookup.ContainsKey(c)) lookup.Add(c, 0); else { if (!duplicates.ContainsKey(c)) duplicates.Add(c, 1); else duplicates[c] += 1; } } //update the count of characters if the character is present in the longer word foreach (char c in longerWord) { if (lookup.ContainsKey(c)) { lookup[c] += 1; } } //get the count of letters that has value greater than 0 var totalCount = lookup.Sum(l => l.Value); int dupCount =0; //get the letters that are common and have duplicates foreach(KeyValuePair<char,int> d in duplicates) { if(lookup[d.Key] > 0) { dupCount += (lookup[d.Key] * duplicates[d.Key]); } } return totalCount + dupCount; }
| Report Duplicate | Flag | PURGE
First Orion SDE1 - 2of 2 votes
AnswersYou want to design a Cab system which will show you nearest 5 taxis.
- Shanky.Q3 July 04, 2016 in United States
Each taxi will continuously emit (x,y) coordinates.
You need to print the nearest 5 taxis from (p,q).| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersAlternate sorting: Given an array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum.
- axaysd June 23, 2016 in United States
Eg.) Input : {1, 2, 3, 4, 5, 6, 7}
Output : {7, 1, 6, 2, 5, 3, 4}| Report Duplicate | Flag | PURGE
Zoho SDE1 Algorithm