SDE1 Interview Questions
- 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 - 0of 0 votes
AnswersGiven a two dimensional array of string like
- axaysd June 22, 2016 in United States
<”luke”, “shaw”>
<”wayne”, “rooney”>
<”rooney”, “ronaldo”>
<”shaw”, “rooney”>
Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2.| Report Duplicate | Flag | PURGE
Zoho SDE1 General Questions and Comments - 0of 0 votes
AnswersRotate the matrix elements
- axaysd June 22, 2016 in United States
For 3*3 matrix
Input
1 2 3
4 5 6
7 8 9
Output:
4 1 2
7 5 3
8 9 6
For 4*4 matrix
Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
5 1 2 3
9 10 6 4
13 11 7 8
14 15 16 12| Report Duplicate | Flag | PURGE
Zoho SDE1 General Questions and Comments - 0of 0 votes
AnswerGiven a set of numbers like <10, 36, 54,89,12> we want to find sum of weights based on the following conditions
- axaysd June 22, 2016 in United States
1. 5 if a perfect square
2. 4 if multiple of 4 and divisible by 6
3. 3 if even number
And sort the numbers based on the weight and print it as follows
<10,its_weight>,<36,its weight><89,its weight>
Should display the numbers based on increasing order.| Report Duplicate | Flag | PURGE
Zoho SDE1 General Questions and Comments - 0of 0 votes
AnswersGiven a list of numbers ex:(2,15,8) as a string with out any delimiters like space or ',' as str = "2158"; is there a way to parse the string an identify which one is double digit or single digit number ?? like 2,8 are single digit number and 15 is a double digit number
- coolcoder3 June 03, 2016 in India| Report Duplicate | Flag | PURGE
SDE1 Java - 1of 1 vote
AnswersThere are n number of conference rooms available in a company for the meeting. You need to book a meeting for a particular time slot. Write an algorithm to determine the number of conference rooms available for the meeting with given start time and end time.
- coder May 17, 2016 in United States for Devices
Hint: any conference room with non- overlapping meeting will be selected.| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 1of 1 vote
AnswersWrite a program to find all duplicate files within a folder.
- sw May 08, 2016 in United States| Report Duplicate | Flag | PURGE
Dropbox SDE1 Algorithm - 0of 0 votes
AnswersFinding Peak element in an array
- sivarasu.net May 03, 2016 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 - 1of 1 vote
AnswersThis is a question I received in an online challenge.
- sparked12345 April 22, 2016 in United States
A list of numbers are given. We need to find the total number of groups in which the digits of each number have same frequency.
For example if numbers are:
1
10
3
33
There are 4 groups:
G1={1}has one 1.
G2={3} has one 3.
G3={10}has one 1 and one 0.
G4={33}as two 3s.| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 0of 0 votes
AnswersDesign an Algorithm for Amazon Advertisement Page
- suneel March 10, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 2 votes
AnswersGiven N ropes of lengths L1, L2, L3, L4, …, LN. I had to join every rope to get a final rope of length L1 + L2 + … + LN.
- ash.taunk3 February 24, 2016 in India
However, I can join only two ropes at a time and the cost of joining the two ropes is L1 + L2. I was supposed to join ropes in such a way that the cost is minimum.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 3of 3 votes
AnswersGiven an array and an integer k, find the maximum for each and every contiguous subarray of size k.(Using DP)
- HimanshuP January 21, 2016 in United States| Report Duplicate | Flag | PURGE
SDE1 Algorithm - 0of 0 votes
AnswersYou have 10^9 user, 10^3 websites that users are subscribed to and 2000 servers. Some users will unsubscribe from certain websites. How would you architect this system to be scalable and performant?
- Ray January 20, 2016 in United States| Report Duplicate | Flag | PURGE
Google SDE1 System Design - 1of 1 vote
AnswersThis is was asked in Amazon SDE online test from Hacker rank.
- sandeepparekh9 January 20, 2016 in Hong Kong
Initech is a company which has CEO Bill and a hierarchy of employees. Employees can have a list of other employees reporting to them, which can themselves have reports, and so on. An employee with at least one report is called a manager.
Please implement the closestCommonManager method to find the closest manager (i.e. farthest from the CEO) to two employees. You may assume that all employees eventually report up to the CEO.
Tree structure:
Bill -> Dom, Samir, Michael
Dom -> Bob, Peter, Porter
Peter -> Milton, Nina
Sample Data:
CEO Bill has 3 employees reporting to him: {Dom, Samir, Michael}
Dom has three reports { Peter, Bob, Porter}
Samir has no reports {}
Michael has no reports {}
Peter has 2 reports {Milton, Nina}
Bob has no reports {}
Porter has no reports {}
Milton has no reports {}
Nina has no reports {}
Sample calls:
closestCommonManager(Milton, Nina) = Peter
closestCommonManager(Nina, Porter) = Dom
closestCommonManager(Nina, Samir) = Bill
closestCommonManager(Peter, Nina) = Peter| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersATM has x currency notes of 100 rupee,y currency notes of 500 rupee,and z currency notes of 1000 rupee notes.
- rajat sadh January 10, 2016 in India
Customer wants to withdraw n amount at any given time. as per bank rules,Customer can not withdraw more than INR.40000/-per transaction.
If ATM is running out of cash it should throw a message that insufficient Balance, Kindly enter multiple of m value of currency note.where m>=4000 and m<=total number of cash available in ATM.
An intelligent banker has found in customer survey that customer prefers to receive more than 5 currency notes 100 rupee,more than 2 currency noes of 500 rupee and rest of the currency notes is of 1000 rupee where ever possible.
If amount is less than 500,customer will receive 100 rupee currency notes. Bankers goal is to tender the minimum number of currency notes to save customer waiting time and increase customer satisfaction by following customer survey.Banker has hired you to program ATM dissaptch function.
FOR Example: Lets ATM has 200 currency notes of 100 rupees,90 currency notes of 500 rupee and 50 currency notes of 1000 rupee.Customer has placed a withdrawal request of Rs 22,200.00. Dispatch function has given him 7 currency notes of 100,3 currency notes of 500 and 20 currency notes of 1000 rupee| Report Duplicate | Flag | PURGE
Adobe SDE1 Algorithm - 0of 0 votes
AnswersDesign a datastructure which stores employee details Name,PhoneNumber,Addres and the employee details are(all the 3 given above) fetched when the user searches the data structure by Name or phone number
- Rajarathinam Antony December 29, 2015 in India| Report Duplicate | Flag | PURGE
ThoughtWorks SDE1 Algorithm - 2of 2 votes
AnswersWe have an iterator class as below:
class CIterator { int Next(); //Returns the value of the next element in the iteration by advancing the iterator bool HasNext() const; //check whether any next element for the current iterator };
We need a CPeekIterator class which is having below functionalities
Class CPeekIterator { int Next (); //Same as CIterator does bool HasNext() const; //same as CIterator does int Peek(); // Returns the next element in the iteration without advancing the iterator };
Write the CPeekIterator class
- johnsvakel November 24, 2015 in United States for GFS| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 0of 0 votes
AnswersHow can you read from disc such that you optimize the latency of the data read/writes?
- Ray November 21, 2015 in United States| Report Duplicate | Flag | PURGE
Google SDE1 Computer Architecture & Low Level - 0of 0 votes
AnswersBelow is almost correct program, there is only one line code is wrong, you have to fix it.
String str contains only a and b characters. below program checks whether str contains equal number of a and b characters.
- siva.sai.2020 November 18, 2015 in Indiavoid checkBalance(string str) { char temp[MAXLEN]; int i, j; for (i = j = 0; temp[i] = str[j]; j++) if (str[j] == temp[i]) i++; else i--; if (i == 0) printf("Balanced\n"); else printf("Not Balanced\n"); }
| Report Duplicate | Flag | PURGE
SDE1 Algorithm - 0of 0 votes
AnswersGiven string a and b, with b containing all distinct characters, find the longest common subsequence's
- siva.sai.2020 November 17, 2015 in India
length. Expected complexity O(nlogn).| Report Duplicate | Flag | PURGE
Uber SDE1 Algorithm Data Structures - 1of 1 vote
AnswersGiven a 4*n block, find number of different ways of filling it with 1*2 smaller blocks. Rotation of smaller blocks is allowed.
- siva.sai.2020 November 17, 2015 in India| Report Duplicate | Flag | PURGE
Uber SDE1 Algorithm Data Structures - 0of 0 votes
AnswersImplement ReentrantLock using simple locks.
- Ray November 09, 2015| Report Duplicate | Flag | PURGE
Google SDE1 Threads - 0of 0 votes
AnswersGiven a large that consists of millions of lines, retrieve only the first and last lines.
- adelabarra24 November 05, 2015 in United States| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - -1of 3 votes
AnswersGiven a 1D array, implement function Sum(x1,x2) where x1 and x2 are indices of array. Find sum of all elements in between the given indices inclusive of them. Do in Time complexity of O(1)
- lol12345 October 27, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 - 4of 4 votes
AnswersGiven a linkedlist, write an algorithm to divide the linkedlist into two linkedlists, the first contains the Fibonacci numbers in the list and the second contains the non-Fibonacci numbers.
- a.ahmed.shalabey October 23, 2015 in United States for Software Development
Test the algorithm after developing the code| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm C Data Structures
Open Chat in New Window