Software Engineer Interview Questions
- 0of 0 votes
AnswersWrite a program that reads a maze from a file and outputs from 'X' to 'O'. Example,
- mrsurajpoudel.wordpress.com September 30, 2016 in United StatesInput: ########## X # # # # # # # # O ########## Output: ########## +++#+++++# # +#+ # +# # +++ # ++ ##########
| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 3of 3 votes
AnswersFind the largest and smallest number in a list. The list is stored as two sections, one in ascending order and the other in descending order.
- uno September 29, 2016 in United States
input [ 2 3 4 5 6 7 10 9 8 7]
smallest : 2
Largest 10| Report Duplicate | Flag | PURGE
Google Software Engineer - 2of 2 votes
AnswersGiven an Array A with n elements. Pick maximum number of elements from given array following the rule:
- chan alex September 25, 2016 in United States
1. We cannot pick A[i] and A[j] if absolute value of (A[i] - A[j]) > absolute value of (i - j)
Example: {13,5,4}
Ans: 2
Pick 5 and 4.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersGiven: sorted array of integers
- 123georgedavid September 21, 2016 in United States
Return: sorted array of squares of those integers
Ex: [1,3,5] -> [1,9,25]
Integers can be negative.| Report Duplicate | Flag | PURGE
Facebook Software Engineer - -1of 1 vote
AnswersYou have a bidimensional space of area N that contains a circle of area M that could be placed anywhere in this space. What is the optimal way of finding the circle, drawing lines, considering you have a function that can tell you if a line is intersecting the circle?
- Ray September 14, 2016 in United States| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 0of 2 votes
AnswersReturns the zero based index of the first occurrence of any character of str2 in str1
- tikolo September 06, 2016 in United States
Input:
str1="adf6ysh"
str2="123678"
output: 3
I have solved this by taking second string in hashset and then iterating first string one by one but i need more optimized way.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Algorithm - 2of 2 votes
AnswersMr. Kim has to deliver refrigerators to N customers. From the office, he is going to visit all the customers and then return to his home. Each location of the office, his home, and the customers is given in the form of integer coordinates (x,y) (0≤x≤100, 0≤y≤100) . The distance between two arbitrary locations (x1, y1) and (x2, y2) is computed by |x1-x2| + |y1-y2|, where |x| denotes the absolute value of x; for instance, |3|=|-3|=3. The locations of the office, his home, and the customers are all distinct. You should plan an optimal way to visit all the N customers and return to his among all the possibilities.
- Loser September 03, 2016 in India
You are given the locations of the office, Mr. Kim’s home, and the customers; the number of the customers is in the range of 5 to 10. Write a program that, starting at the office, finds a (the) shortest path visiting all the customers and returning to his home. Your program only have to report the distance of a (the) shortest path.
You don’t have to solve this problem efficiently. You could find an answer by looking up all the possible ways. If you can look up all the possibilities well, you will get a perfect score.
[Constraints]
5≤N≤10. Each location (x,y) is in a bounded grid, 0≤x≤100, 0≤y≤100, and x, y are integers.
[Input]
You are given 10 test cases. Each test case consists of two lines; the first line has N, the number of the customers, and the following line enumerates the locations of the office, Mr. Kim’s home, and the customers in sequence. Each location consists of the coordinates (x,y), which is reprensented by ‘x y’.
[Output]
Output the 10 answers in 10 lines. Each line outputs the distance of a (the) shortest path. Each line looks like ‘#x answer’ where x is the index of a test case. ‘#x’ and ‘answer’ are separated by a space.
[I/O Example]
Input (20 lines in total. In the first test case, the locations of the office and the home are (0, 0) and (100, 100) respectively, and the locations of the customers are (70, 40), (30, 10), (10, 5), (90, 70), (50, 20).)
5 ← Starting test case #1
0 0 100 100 70 40 30 10 10 5 90 70 50 20
6 ← Starting test case #2
88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
10 ← Starting test case #3
39 9 97 61 35 93 62 64 96 39 36 36 9 59 59 96 61 7 64 43 43 58 1 36
...
Output (10 lines in total)
#1 200
#2 304
#3 366| Report Duplicate | Flag | PURGE
Samsung Software Engineer Algorithm - 0of 0 votes
AnswersTime Complexity ?
- Ragesh September 02, 2016 in United States for Seattle
a. Inserting a node in Linked List?
b. HashMap time complexity?| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswersFind missing number from sequence of numbers in an array? Time Complexity?
- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswerTime Complexity ?
- Ragesh September 02, 2016 in United States for Seattle
a. Inserting a node in Linked List?
b. HashMap time complexity?| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersFind missing number from sequence of numbers in an array? Time Complexity?
- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersReverse a String using Recursion and unit tests?
- Ragesh September 02, 2016 in United States for Seattle| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 2of 2 votes
AnswersConvert a number to English representation.
- coder145 August 09, 2016 in United States
Ex: Input : 100
Output : One Hundred.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 4 votes
AnswersYou have a bunch of light bulbs. Store them as you wish. Implement a function that tells you if the light is on or off given its index and another one that toggles the state of the light bulbs given a start and end index.
- ad09 August 09, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 3of 3 votes
AnswersGiven an input string and ordering string, need to return true if the ordering string is present in Input string.
- ranjith2jeeth August 04, 2016 in United States
input = "hello world!"
ordering = "hlo!"
result = FALSE (all Ls are not before all Os)
input = "hello world!"
ordering = "!od"
result = FALSE (the input has '!' coming after 'o' and after 'd', but the pattern needs it to come before 'o' and 'd')
input = "hello world!"
ordering = "he!"
result = TRUE
input = "aaaabbbcccc"
ordering = "ac"
result = TRUE| Report Duplicate | Flag | PURGE
Uber Software Engineer String Manipulation - -1of 5 votes
AnswersFollow-up to above question:
- / July 31, 2016 in United States
Can you augment a BST to return the number of elements with node values in a given range?
If not, what other data structure would work?| Report Duplicate | Flag | PURGE
Google Software Engineer Data Structures - -1of 3 votes
AnswersWrite a function that takes as input an array of integers A, and two integers low and high.
- / July 31, 2016 in United States
Your function has to output pairs of indices: {(i,j), ...}
Where each pair of indices denotes that the subarray of A[i...j] has a sum in the range low <= sum <= high.
Apparently there are algorithms better than O(N^2).| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 4 votes
AnswersYou are currently in practice mode. This is a demo only.
- New Grad July 30, 2016 in United States
A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.
A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
For example, consider the following array A consisting of N = 8 elements:
A[0] = -1
A[1] = 3
A[2] = -4
A[3] = 5
A[4] = 1
A[5] = -6
A[6] = 2
A[7] = 1
P = 1 is an equilibrium index of this array, because:
A[0] = −1 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7]
P = 3 is an equilibrium index of this array, because:
A[0] + A[1] + A[2] = −2 = A[4] + A[5] + A[6] + A[7]
P = 7 is also an equilibrium index, because:
A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0
and there are no elements with indices greater than 7.
P = 8 is not an equilibrium index, because it does not fulfill the condition 0 ≤ P < N.
Write a function:
int solution(int A[], int N);
that, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices. The function should return −1 if no equilibrium index exists.
For example, given array A shown above, the function may return 1, 3 or 7, as explained above.
Assume that:
N is an integer within the range [0..100,000];
each element of array A is an integer within the range [−2,147,483,648..2,147,483,647].
Complexity:
expected worst-case time complexity is O(N);
expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
Elements of input arrays can be modified.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 16of 20 votes
AnswersGiven two object arrays of "id,weight" (sorted by weight), merge them together and create a one single array. If the "id"s are same values should be merged. Final resulting array should be sorted by weight. Result should be O(nlogn) in time complexity.
- dee707 July 28, 2016 in Switzerland| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 2 votes
AnswersGiven a list of numbers of odd length, design an algorithm to decide whether it's possible to remove any number from the list and split the remaining numbers into two sets of equal length with the same sum.
- jakeb July 22, 2016 in United States
Example:
Input: [1, 1, 1, 1, 1]
Output: Yes
Input: [1, 2, 2]
Output: No| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 4of 4 votes
AnswersGiven a string return the longest palindrome that can be constructed by removing or shuffling characters.
- enkadi13 July 22, 2016 in United States
Example:
'aha' -> 'aha'
'ttaatta' -> ' ttaaatt'
'abc' -> 'a' or 'b' or 'c'
'gggaaa' -> 'gaaag' or 'aggga'
Note if there are multiple correct answers you only need to return 1 palindrome.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersA matrix is "Toepliz" if each descending diagonal from left to right is constant. Given an M x N matrix write the method isToepliz to determine if a matrix is Toepliz.
- enkadi13 July 22, 2016 in United States
Example:
Input:
67892
46789
14678
01467
Output:
True| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm Arrays - 0of 0 votes
AnswersHow to calculate sum of all numbers in a string. Example 11aa22bb33dd44 =110
- rageshpayyan July 21, 2016 in United States for Seattle
Note: Should not use Regex and replace| Report Duplicate | Flag | PURGE
Amazon Software Engineer Algorithm - 0of 0 votes
AnswersFind the index when slow and fast pointer meet in terms of n (length of list before cycle) and p ( length of loop in linked list).
- Deepak Agrawal July 16, 2016 in India
Let me meeting index is q then we should be able to find value of q when we pass n& p , there shouldn't be any extra variable.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersGiven Nodes such as
M-> N-> T-> D-> E | | | | C X Y L | | A Z
-> right pointer
- Raj July 14, 2016 in United States
| down pointer
Output should be
M->C->A->N->X->Z->T->Y->D-L>E
Write this to flatten
flatten(Node head) {
}
Node {
Node right;
Node down;
char a;
}| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 2 votes
AnswersGIven a list of words, and the number of rows and columns, return the number of words that can be fit into the rows and columns by stringing together each consecutive word. If the next word doesn't fit in the same line, it should move to the next line. Find an efficient solution for this. For eg.
- rucknrull July 14, 2016 in United States
List of words: { "Do", "Run" }
Number of columns: 9
Number of rows: 2
First row: "Do Run Do" (7 letters + 2 spaces fit into 9 columns)
Second row: "Run Do" (Only 2 words fit into 9 columns)| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersThe 64-bit representation of a 48-bit address is said to be in canonical form if bits 63 through 48 are either all ones or all zeroes. Implement X86IsCanonicalAddress().
- Mukesh July 07, 2016 in United States| Report Duplicate | Flag | PURGE
VMWare Inc Software Engineer Bit Manipulation - 0of 0 votes
AnswersImplement a function, set_bit_l_to_r(x,y,l,r).
- Mukesh July 07, 2016 in United States
For bits l to r (both inclusive), if they are set in x, also set them in y. Do not change bits of y, if they are not in range l to r, or those bits are not set in x. l and r are 0-based.| Report Duplicate | Flag | PURGE
VMWare Inc Software Engineer Bit Manipulation - 2of 2 votes
AnswersYou have rating (0-10) of the hotels per user in this format:
- theconqueror July 07, 2016 in United States
scores = [
{'hotel_id': 1001, 'user_id': 501, 'score': 7},
{'hotel_id': 1001, 'user_id': 502, 'score': 7},
{'hotel_id': 1001, 'user_id': 503, 'score': 7},
{'hotel_id': 2001, 'user_id': 504, 'score': 10},
{'hotel_id': 3001, 'user_id': 505, 'score': 5},
{'hotel_id': 2001, 'user_id': 506, 'score': 5}
]
Any given hotel might have more than one score.
Implement a function, get_hotels(scores, min_avg_score) that returns a list of hotel ids that have average score equal to or higher than min_avg_score.
get_hotels(scores, 5) -> [1001, 2001, 3001]
get_hotels(scores, 7) -> [1001, 2001]
*/
How to solve this in C++ and Python?| Report Duplicate | Flag | PURGE
Google Software Engineer - 0of 0 votes
AnswersThere is an input log file given as follows-
- theconqueror July 06, 2016 in United States
log = [
{ 'user': 'A', 'page': 1},
{ 'user': 'B', 'page': 5},
{ 'user': 'A', 'page': 2},
{ 'user': 'A', 'page': 1},
{ 'user': 'B', 'page': 2},
{ 'user': 'C', 'page': 7},
{ 'user': 'C', 'page': 3},
{ 'user': 'A', 'page': 3},
{ 'user': 'C', 'page': 1},
]
please implement
discover_site_map(log)
discover_site_map returns a representation of the links between pages, using whatever data structure you think is suitable:
1 -> 2, 3
2 -> 1
3 -> 1
5 -> 2
7 -> 3
How to solve this in C++ and Python?| Report Duplicate | Flag | PURGE
Amazon Software Engineer