Recent Interview Questions
- 0of 0 votes
AnswersGiven pre order traversal of a tree. It has only 2 type of nodes, N & L (non-leaf, leaf).. Also, every node either has zero or two children.
- P January 24, 2012 in India
Produce the tree.
Eg: Pre-order NNLLL
Tree;
N
/ \
N L
/ \
L L| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven a list of words, L, that are all the same length, and a string, S, find the starting position of the substring of S that is a concatenation of each word in L exactly once and without any intervening characters. This substring will occur exactly once in S..
- topcoder99 January 06, 2012 in United States
.
Example:.
L: "fooo", "barr", "wing", "ding", "wing".
S: "lingmindraboofooowingdingbarrwingmonkeypoundcake".
fooowingdingbarrwing.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere is integer array like {1,2,4,5,6,1,2,4,3,5,7,2,1}. I want to find the possible combination of pair which sum is 4.
- amitnagar21 January 03, 2012 in India
input : {1,2,4,5,6,1,2,4,3,5,7,2,1}
output : {1,1,2}, {2,2}, {3,1}, {1,2,1}...etc which make the sum as 4| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm PHP - 0of 0 votes
AnswersLongest palindrome of the string
- Barney Stinson May 31, 2011| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersThere is an array in an external system (i.e. u cannot access the array elements directly). The system exposes 3 functions of O(1) :
- arun March 06, 2011
length() - returns the length of the array.
get(i) - returns the element at index i.
reverse(i,j) - reverses the elements in the array from index i to index j (both indexes inclusive).
Can you sort the array in the best possible way using only these 3 operations?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 2of 2 votes
AnswersImplement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.
- abhishek January 01, 2011| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
Answersgiven a set of positive and negative integers group all the positive integers on one side and negative integers on one side...
- Anonymous October 06, 2010
numbers should be in the same order they appear....| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times.
- Anonymous November 07, 2009
I gave the hashmap solution. He was looking for a bitwise operator solution.| Report Duplicate | Flag | PURGE
Amazon Algorithm - 0of 2 votes
AnswersHow would you traverse a linked list with complexity O(n^0.5)?
- Murhty September 22, 2009| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer Linked Lists - 0of 0 votes
AnswersWithout using an additional linked list arrange elements such that all even numnbers are placed after odd numbers
- Vaishnavi September 15, 2009| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Linked Lists - 0of 0 votes
AnswersGiven a M*N matrix A in which all the elements in a row and all the elements in a column are strictly increasing. Find a path from the smallest element (ie A[0][0]) to the largest element (ie A[M-1][N-1]) such that the sum of the elements in the path is maximum. Time Complexity O(m+n). Use efficient space.
- Anonymous August 25, 2009| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersConvert a binary search tree to a circular sorted linked list. The highest valued node should point to the lowest valued node at each step.
- prolificcoder April 27, 2009| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test C++ Coding Data Structures Linked Lists - 0of 0 votes
AnswersWrite code to remove duplicates from an *unsorted* linked list. Let's say a temporary buffer is not allowed. Find as many solutions as possible. Can you do better than the O(n^2) solution? Construct test cases.
- Sach (Sachin) April 22, 2006| Report Duplicate | Flag | PURGE
Microsoft Testing Algorithm - 1of 1 vote
AnswersYou are given 2 strings: string, strong. Find the common alphabets in two strings and print it.
- amu0dha May 04, 2017 in United States
i/p: string , strong
o/p: strng| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Quality Assurance - 1of 1 vote
AnswersFind the maximum consecutive 1's in an array of 0's and 1's.
- nidhi.prakash.410 January 23, 2017 in India
Example:
a) 00110001001110 - Output :3 [Max num of consecutive 1's is 3]
b) 1000010001 - Output :1 [Max num of consecutive 1's is 1]| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersYou have a string aaabbdcccccf, transform it the following way => a3b2d1c5f1
- Blank October 29, 2016 in United States for Infrastructure
ie: aabbaa -> a2b2a2 not a4b2| Report Duplicate | Flag | PURGE
Salesforce Intern String Manipulation - 1of 3 votes
AnswersGiven an array A = [3, 7, 2,5,6,4] for a number N, print the pairs from that array A that sums up to N. You should print each pair once.
- nonameno October 29, 2015 in England| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer Intern - 2of 2 votes
AnswersYou are given a permutation arr[N]. E.g. arr[3] = {2, 1, 0} or arr[5] = {0,1,2,4,3};
- emb October 05, 2015 in United States
Then you can prepare somehow and then start serving requests: request(a, b, k) = sorted(arr[a:b])[k], that is, k-th order statistic on slice [a:b] of arr.
E.g. if arr is [3,4,5,0,1,2] and a = 2 and b = 5, then arr[a:b] = [5,0,1] and let k = 2, so we sort it - get [0,1,5] and take k-th element, that is - 5.
Implement request(a, b, k) function. You can preprocess input data, that is, assume there will be only one array and many request() calls.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersGiven a singly linked list, swap the list items in pairs (reconnect the pointers, not simply swap the values). For example:
- Kiara April 22, 2015 in United States
Before: A->B->C->D
After: B->A->D->C| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 3of 3 votes
AnswersFind popular item in sorted array of natural numbers.
- dreamchaser1984 February 25, 2015 in United States
An item is popular is if its repeated n/4 times or more.
For Ex:
Input: 123444445678
Popular item is 4.
Liner scan is O(n), but solution needs to be in O(logN) complexity and O(1) space complexity.| Report Duplicate | Flag | PURGE
Google Principal Software Engineer Algorithm - 4of 4 votes
AnswersYou are given an unsorted sequence of integers 'a'. Find the longest subsequence 'b' such that elements of this subsequence are strictly increasing numbers. Elements in the subsequence 'b' must appear in the same relative order as in the sequence 'a'. You may assume that 'a' can fit to the memory.
- autoboli February 24, 2015 in United States
Example:
input: a = [-1 2 100 100 101 3 4 5 -7]
output: b = [-1 2 3 4 5]| Report Duplicate | Flag | PURGE
Google - 0of 0 votes
AnswersYour are given two strings str1 and str2, you have to generate another unique string str3, which can only generated by these two string str1 and str2, no other string can generate that string str3. Some later point you have to retrieve back those two string str1 and str2 form that unique string str3.
- neelabhsingh February 20, 2015 in India for Hyderabad| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 4of 4 votes
AnswersYou are given an array of integers 'a' that can fit in a memory. Write a method that retuns an array of the same lenght such that each element 'i' of this array is a sum of 'a' except the element a[i]. You are not allowed to use '-' operator.
- autoboli January 13, 2015 in United States| Report Duplicate | Flag | PURGE
Google - 1of 1 vote
Answersboolean checkPattern(String str)
- NIC January 03, 2015 in India
{
// Implementation
}
Implement the method checkPattern. str is a string argument.
Return true: if the string is following any pattern
example: xyzxyzxyz
Here "xyz" is the pattern
return false: String is not following pattern
example: xyzxyzA
A is not in part of pattern.| Report Duplicate | Flag | PURGE
Interra System Software Engineer / Developer Algorithm - 5of 5 votes
AnswersWrite a function which, given two integers (a numerator and a denominator), prints the decimal representation of the rational number "numerator/denominator".
- loganwol August 18, 2014 in United States
Since all rational numbers end with a repeating section, print the repeating section of digits inside parentheses; the decimal printout will be/must be
Example:
1 , 3 = 0.(3)
2 , 4 = 0.5(0)
22, 7 = 3.(142857)
etc..| Report Duplicate | Flag | PURGE
Google SDET Coding - 3of 3 votes
AnswersCode for computing a^b and optimize it.
- AlgoAlgae April 25, 2014 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
Answersfind the Maximum product subset with negative and positive integer
- intervyou April 23, 2014 in United States| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer - 0of 2 votes
AnswersIn a Binary tree, every element(node's value) must contain the sum of its left and right sub-trees.
- pavi.8081 March 08, 2014 in India
Follow up question: how would you solve this if you can ONLY increment the value of a node
Eg. If a node’s value is 20 and its sub-tree sum is 10, the node’s value can’t be set to 10 because you can only increment.
How would you solve this if you can ONLY increment the value of a node
Further clarifications.
1. You can make assumption that leaf nodes retain their original value and does not change.
2. "Sum of its left and right subtrees" means sum of all nodes' values in its left subtree + sum of all nodes' values in its right subtree.
PS: I am asking this question coz I am not sure of its solution myself. Hence seeking experts' advice.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
Answersgiven 2 arrays wrds[] , chars[] as an input to a function such that
- goldy_ssb February 06, 2014 in United States
wrds[] = [ "abc" , "baa" , "caan" , "an" , "banc" ]
chars[] = [ "a" , "a" , "n" , "c" , "b"]
Function should return the longest word from words[] which can be constructed from the chars in chars[] array.
for above example - "caan" , "banc" should be returned
Note: Once a character in chars[] array is used, it cant be used again.
eg: words[] = [ "aat" ]
characters[] = [ "a" , "t" ]
then word "aat" can't be constructed, since we've only 1 "a" in chars[].| Report Duplicate | Flag | PURGE
Apple Software Engineer in Test