Recent Interview Questions
- 6of 6 votes
AnswersIn a certain language which has same alphabets as in english language (ie. a-z), but the order of the alphabets is different (for eg 's' is the first character, 'g' is second, and likewise). Given a dictionary of this new language (which has words arranged according to new alphabetical order), FInd out the order of alphabets in this language.
- sgarg June 09, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Google SDE1 Software Engineer / Developer SDE-2 Algorithm - 1of 3 votes
AnswersYou are given an array of 1's 2's and 3's. Sort this list so the 1's are first, the 2's come second, and the 3's come third.
- Aasen May 23, 2013 in United States
Ex: Input [1, 3, 3, 2, 1]
Output [1, 1, 2, 3, 3]
But there is a catch!! The algorithm must be one pass, which means no merge/quick sort. Also no extra list allocations are allowed, which means no bucket/radix/counting sorts.
You are only permitted to swap elements.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 0of 0 votes
AnswersGiven an array find the next greatest element to the right of it. [4, 5, 2, 25]
- firefox April 02, 2013 in United States
Element NextGreatestElement
4 --> 5
5 --> 25
2 --> 25
25 --> -1
i gave o(n^2), but was
asked to solve in o(n)..You can take extra space...| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven an array, find all unique three-member subsets, with unique being that [0,2,3] and [3,2,0] are the same set. Should run in faster than 2^n time
- shailpatel2 April 01, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersHow will you remove duplicate characters in a string
- enthusiast November 15, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Intern Algorithm - 3of 3 votes
AnswersYou are given an array of N elements.arrange array in such a way that sum of any cunsucative k numbers are divisible
- dilip kasana October 25, 2012 in India
by NUM.if not possible print -1.(it may possible that there are many solution possible then return any one)
For example:
N=6
k=3
NUM=63
array={80,17,90,82,27,19}
Answer:{19,17,27,82,80,90}
any 3 cunsucative no. like (27+82+80)%63=0
another solution={27,19,17,90,82,80}
may be a hint :try to group all no.'s in mod NUM map and use vector and map.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
Answersgiven linked list a->b->c->d->e convert to
- rockstar September 06, 2012 in India
b->a->d->c->e without creating new node.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGive the output of the following code:
- akash1600 July 24, 2012 in United States#include<iostream> using namespace std; int main() { int a=10,b=2; b=a+++a; cout<<b<<" "<<a"\n"; return 0; }
| Report Duplicate | Flag | PURGE
Microsoft Intern C - 0of 0 votes
AnswersFind preorder successor in BST.
- ninja July 07, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon - 0of 0 votes
Answersgiven 3 arrays, array a, array b, array c.
- sb June 28, 2012 in India
find all pairs where a[i] + b[j] = c[k]
a, b , c are sorted.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 0of 0 votes
Answersinput linked list is : 1->9->3->8->5->7->7
- ashish April 10, 2012 in India for hyderabad
do you see any pattern in this input ?
odd placed nodes are in increasing order and even placed nodes are in decreasing order.
write a code that gives the the following linkedlist:
output linked list should be 1->3->5->7->7->8->9
?? can it be done inplace ?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Linked Lists - 0of 0 votes
AnswersYou are at a political convention with n delegates, each one a member of exactly one political
- rohit_dayal March 25, 2012 in United States
party. It is impossible to tell which political party any delegate belongs to; in particular, you will
be summarily ejected from the convention if you ask. However, you can determine whether any
two delegates belong to the same party or not by introducing them to each other—members of the
same party always greet each other with smiles and friendly handshakes; members of different
parties always greet each other with angry stares and insults.
(a) Suppose a majority (more than half) of the delegates are from the same political party.
Describe an efficient algorithm that identifies a member (anymember) of the majority party.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou have a circular track containing fuel pits at irregular intervals. The total amount of fuel available from all the pits together is just sufficient to travel round the track and finish where you started. Given the the circuit perimeter, list of each fuel pit location and the amount of fuel they contain, find the optimal start point on the track such that you never run out of fuel and complete circuit.
- jerry January 12, 2012 in United States| Report Duplicate | Flag | PURGE
Google Brain Teasers - 0of 0 votes
AnswersIf there is a n-digit, print the digits one by one without using temporary storage and how will you do it efficiently?
- javacode7 October 07, 2011 in United States
Example:
if the number is 1054
print:
1
0
5
4| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersJump Game:
- Anonymous August 10, 2011
Given an array start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array. Optimum result is when u reach the goal in minimum number of jumps.
For ex:
Given array A = {2,3,1,1,4}
possible ways to reach the end (index list)
i) 0,2,3,4 (jump 2 to index 2, then jump 1 to index 3 then 1 to index 4)
ii) 0,1,4 (jump 1 to index 1, then jump 3 to index 4)
Since second solution has only 2 jumps it is the optimum result.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere is a doubly linked list with next pointer and arbitrary pointer( points to an arbitrary node in list). You have to make a copy of the linked list and return. In the end original list shouldn't be modified. Best time O(n).
- cracker April 06, 2011| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Linked Lists - 0of 0 votes
AnswersGiven an integer n , you have to print all the ways in which n can be represented as sum of positive integers
- tt February 15, 2011| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer - 0of 0 votes
AnswersA special type of tree is given, Where all leaf are marked with L and others are marked with N. every node can have 0 or at most 2 nodes. Trees preorder traversal is given give a algorithm to build tree from this traversal.
- mail2maulish January 10, 2011| Report Duplicate | Flag | PURGE
Amazon Trees and Graphs - 0of 0 votes
Answersfind LCA (lowest common ancestor) for non binary tree.
- Anonymous October 23, 2009| Report Duplicate | Flag | PURGE
Amazon Microsoft Software Engineer / Developer Algorithm Trees and Graphs - 0of 0 votes
AnswersGiven an array of positive, unique, increasingly sorted numbers A, e.g. A = [1, 2, 3, 5, 6, 8, 9, 11, 12, 13]. Given a positive value K, e.g. K = 3. Output all pairs in A that differ exactly by K.
- simplysou October 06, 2015 in United States
e.g. 2, 5
3, 6
5, 8
6, 9
8, 11
9, 12
what is the runtime for your code?| Report Duplicate | Flag | PURGE
Facebook Software Developer - 0of 0 votes
AnswersFind the longest running positive sequence in an array -
- coderhacker April 15, 2015 in United States
Eg - [1,2,-3,2,3,4,-6,1,2,3,4,5,-8,5,6]
It should return 5, with start index : 8| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Arrays - 5of 15 votes
AnswersGiven a function
- mabid.mahmood July 15, 2014 in United States
getRandomTripplet()
which returns a random triplet of letters from a string. You don't know the string using calls to this function you have to correctly guess the string. the length of the string is also given.
Lets say the string is helloworld the function getRandomTriplet will return things like
hlo
hew
wld
owo
the function maintains the relative order of the letters. so it will never return
ohl since h is before o in the string.
owe since w is after e
The string is not known you are only given length of the string.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 4 votes
AnswersTwo finite, strictly increasing, integer sequences are given. Any common integer between the two sequences constitute an intersection point. Take for example the following two sequences where intersection points are
- blackfever June 29, 2014 in India
printed in bold:
First= 3 5 7 9 20 25 30 40 55 56 57 60 62
Second= 1 4 7 11 14 25 44 47 55 57 100
You can ‘walk” over these two sequences in the following way:
1. You may start at the beginning of any of the two sequences. Now start moving forward.
2. At each intersection point, you have the choice of either continuing with the same sequence you’re currently on, or switching to the other sequence.
The objective is finding a path that produces the maximum sum of data you walked over. In the above example, the largest possible sum is 450 which is the result of adding 3, 5, 7, 9, 20, 25, 44, 47, 55, 56, 57, 60, and 62
this is the same problem which I saw in SPOJ Problem Set| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 0 votes
AnswersYou are given an array of N elements. Each element in the range Min of int to Max of Int. You need to find the length of longest sequence in this array such that difference of largest and smallest element of that sequence is 1. The sequence need not be sequential.
- northernlight May 06, 2014 in United Kingdom
For e.g. array[]={6,10,6,7,8,9,0}
seq {6,10} = diff is 4 len 2
seq { 10,7,8} diff is 3 len 3
seq { 7,8,9} diff 2 len 3
seq {6,6,7} diff is 1 len 3
In this example the program should return 3 .
Complexity N*longN| Report Duplicate | Flag | PURGE
Amazon Algorithm Arrays C C++ - 2of 2 votes
AnswersGiven an array of words, write a method that determines whether there are any words in this array that are anagrams of each other.
- valheru April 23, 2014 in United States
Sample #1: @[@"bag", @"bat", @"tab"]; // output TRUE
Sample #2: @[@"gab", @"bat", @"laf"]; // output FALSE| Report Duplicate | Flag | PURGE
Facebook iOS Developer Algorithm - 0of 2 votes
AnswersGiven an array say [0,1,2,3,5,6,7,11,12,14,20]
- i_learn April 11, 2014 in India
given a number say 5.
Now find the sum of elements which sum to 5
eg:2+3=5, 0+5=5 etc.
I guess the interviewer wanted all possible combinations eg 0+2+3=5, etc| Report Duplicate | Flag | PURGE
Amazon Testing / Quality Assurance Algorithm Android Application / UI Design Arrays Coding Data Structures Dynamic Programming Perl Sorting test Testing - 0of 0 votes
AnswersWrite a multi threaded C code with one thread printing all even numbers and the other all odd numbers. The output should always be in sequence
- gjp February 24, 2014 in United States
ie. 0,1,2,3,4....etc| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern C Threads - 0of 2 votes
AnswersHow will you find if a string is a substring of another string in O(n) complexity. For example, "tl" is substring of bottle.
- Madan November 26, 2013 in United States| Report Duplicate | Flag | PURGE
Google SDE-2 Algorithm - 3of 3 votes
AnswersGiven a bst and a group of numbers g, check whether all the elements of g occur in the same path.
- thebiker925 September 12, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer