Recent Interview Questions
- 2of 2 votes
AnswersGiven a string we have to find first non-repeating character in the string....
- varunesh.88 December 07, 2012 in India
Example: str="aabbbccccddeffffgg";
Answer is : e| Report Duplicate | Flag | PURGE
Morgan Stanley Intern C - 2of 2 votes
AnswersGiven an array, find all maximal sub-arrays in which all pairs have their sum greater than k. DP would give us a O(n^2) algorithm. Can we do better.
- Vikas October 29, 2012 in United States
suppose k = 4
-4 9 10 4 -3 8 9 -2
Answer is:
-4 9 10
9 10 4
-3 8 9
8 9 -2| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
Answersn numbers (both +ve and -ve) are arranged in a circle. find the maximum sum of consecutive nos. Do this in O(n) time
- codez July 03, 2012 in United States
E.g.: {8,-8,9,-9,10,-11,12}
max = 22 (12 + 8 - 8 + 9 - 9 + 10)| Report Duplicate | Flag | PURGE
Microsoft - 0of 0 votes
AnswersGiven an Array With random 0s and non 0 numbers, shift all the 0s to the beginning and non 0s to the rear.
- soundararajanaravind March 06, 2012 in India
Eg: 1,9,8,4,0,0,2,7,0,6,0
Out put 0,0,0,0,1,9,8,4,2,7,6
i.e order of numbers not to change. Do it in place| Report Duplicate | Flag | PURGE
Microsoft Student student Arrays - 0of 0 votes
AnswersGiven (i) a non-empty binary search tree with double values (e.g. 3.5) in each node and (ii) a key value K
- mihirk February 15, 2012 in United States
Write a method to find the closest value to K.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Coding Data Structures Java Trees and Graphs - 1of 3 votes
AnswersGiven an inorder traversal only for a binary tree (not necessarily a
- Bugaboo December 27, 2011 in United States
BST), give a pseudo code to generate all possible binary trees for
this traversal sequence.
Firstly, how many binary trees can be generated given an in-order
traversal? I know that given 'n' nodes, number of BTs possible is
(2^n)-n. But if we are given a specific in-order sequence, can we cut
down on this number?| Report Duplicate | Flag | PURGE
Google - -1of 1 vote
AnswersHow do you remove the duplicate characters in a given string without using any additional buffer. Give the Algo., write code and list the test cases.
- Sadineni February 26, 2007| Report Duplicate | Flag | PURGE
Microsoft Coding Algorithm - 8of 8 votes
AnswersGiven an array int32 arr[] of size n, return the number of non-empty contigious subarrays whose sum lies in range [a, b]
That is, implement the following naive algorithm faster than O(n^2)def naive_algorithm(lst, a, b): result = 0 for i in xrange(len(lst)): for j in xrange(i, len(lst)): if a <= sum(lst[i:j + 1]) <= b: result += 1 return result
Examples:
count([1,2,3], 0, 3) = 3 # [1], [2], [3], [1, 2], [3] count([-2,5,-1], -2, 2) = 3 # [-2], [-1], [-2, 5, -1]
You may assume that there are no overflows, that is sum(|x_i|) <= MAX_INT - 1
- emb September 26, 2015 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer - 5of 5 votes
AnswersGiven two strings, return boolean True/False, if they are only one edit apart.Edit can be insert/delete/update of only one character in the string. Eg:
- abkr990 October 31, 2014 in United States
-True
xyz,xz
xyz, xyk
xy, xyz
-False
xyz, xyz
xyz,xzy
x, xyz| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an input string, write a function that returns the Run Length Encoded string for the input string.
- sharma October 14, 2014 in India
For example, if the input string is “wwwwaaadexxxxxx”, then the function should return “w4a3dex6″.| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Algorithm - 6of 8 votes
AnswersGiven a NxN matrix which contains all distinct 1 to n^2 numbers, write code to print sequence of increasing adjacent sequential numbers.
- talktomenow July 14, 2014 in United States
ex:
1 5 9
2 3 8
4 6 7
should print
6 7 8 9| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 5of 5 votes
AnswersLet's say you have 10,000 servers, each with a billion integers. How do you find the median?
- 352905 July 03, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a community of people, find out a person who could be a potential mayor. Constraints as below.
- AVK September 22, 2013 in United States
1) Mayor does not know any of the people in the community.
2) All the people in the community must know the mayor, that is he has to popular.
My apologies, I forgot to mention that the interviewer had also given me a function called " knows(int a, int b) " that returns a boolean value if a knows b.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven an array write a function to print all continuous subsequences in the array which sum of 0.
- Mukesh August 13, 2013 in United States
e.g:
Input:
Array = [-1, -3, 4, 5, 4]
output:
-1, -3, 4| Report Duplicate | Flag | PURGE
Facebook Algorithm - 2of 2 votes
AnswersGiven an virtual 4x4 boggle board, and some 4 letter words, determine if the words are in the board
- rosie March 22, 2013 in United States
ex.
S M E F
R A T D
L O N I
K A F B
STAR- no
TONE- no
NOTE- yes
SAND- yes
etc.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern - 5of 5 votes
AnswersGiven two strings .Print all the interleavings of the two strings.
- grave July 10, 2012 in India
Interleaving means that the if B comes after A .It should also come after A in the interleaved string.
ex-
AB and CD
ABCD
ACBD
ACDB
CABD
CADB
CDAB| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm String Manipulation - 0of 0 votes
Answers1.sort array {0,1,1,0,1,0,1,0,0,1,1,1,0} of binary numbers in O(n) time complexity using property of binary numbers.(no counting here)
- sujita July 06, 2012 in India for GGN| Report Duplicate | Flag | PURGE
Oracle Labs247 Quality Assurance Engineer Site Reliability Engineer Arrays - 0of 0 votes
AnswersGiven two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's
- Googler May 03, 2010
say they are decreasingly sorted), we define a set S = {(a,b) | a \in
A
and b \in B}. Obviously there are n^2 elements in S. The value of such
a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs
from S with largest values.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 2of 0 votes
AnswersA number is called 'desirable' if all the digits are strictly ascending eg: 159 as 1<5<9. You know that your rival has a strictly numeric password that is 'desirable'. Your close ally has given you the number of digits (N) in your rival's password. WAP th\hjtat takes in 'N' as input and prints out all possible 'desirable' numbers that can be formed with N digits.
- Anonymous October 19, 2008| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Coding - 1of 1 vote
Answersgiven a binary tree ,find the largest sub-tree which is a BST...(largest means subtree having largest no of nodes in it)...this is a wonderful question.....
- psp.reachable@gmail.com October 13, 2008| Report Duplicate | Flag | PURGE
Amazon Development Support Engineer Trees and Graphs - 0of 0 votes
AnswersGiven two input arrays, return true if the words array is sorted according to the ordering array
- releb February 28, 2018 in United States
Input:
words = ['cc', 'cb', 'bb', 'ac']
ordering = ['c', 'b', 'a']
Output: True
Input:
words = ['cc', 'cb', 'bb', 'ac']
ordering = ['b', 'c', 'a']
Output: False| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 1of 1 vote
AnswersReverse an array in subset of N. Example:
- Prashant May 22, 2016 in India for Kindle
input: Array = [1,2,3,4,5,6,7,8,9], N = 3
output: [3,2,1,6,5,4,9,8,7]| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer - 4of 4 votes
AnswersSparse number is an integer if there are no adjacent 1 in it's binary representation.
- Rahul Sharma March 30, 2015 in United States
Like: 5 -> 101 (no adjacent 1)
9 -> 1001 (no adjacent 1)
while 6-> 110 is not sparse number.
Now you are given an integer find the NEXT BIGGER sparse number.Please mind 'it is next bigger'.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - 5of 5 votes
AnswersI recently, appeared for second phone interview with CloudEra, the interviewer asked me to
- gravityrahul June 28, 2014 in United States
write a function which takes in an array of integers and returns the highest positive product
possible by multiplying 3 distinct numbers. NO SORTING is ALLOWED
PS: Please write a solution in JAVA or Python. (Not interviewer request)
example:
[1, 3, 5, 2, 8, 0, -1, 3]
=> 8 * 5 * 3 = 120
[0, -1, 3, 100, -70, -5]
=> -70*-50*100=350000| Report Duplicate | Flag | PURGE
Cloudera Software Engineer in Test Algorithm - 11of 13 votes
Answersinput [2,3,1,4]
- balahana March 07, 2014 in United States
output [12,8,24,6]
Multiply all fields except it's own position.
Restrictions:
1. no use of division
2. complexity in O(n)| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 3of 3 votes
Answerssuppose a string is consists of a, b, and c
- codingfunnyguy November 25, 2013 in United States
Now given a integer N, output the amount of all possible strings of length N that don't of have consecutive a,b,c.
e.g. given N=5, string bacca is invalid since the first 3 letters have consecutive a,b,c. and bbbbb is valid.| Report Duplicate | Flag | PURGE
Google Algorithm - 13of 19 votes
AnswersWrite a program to find whether a given number is a perfect square or not. You can only use addition and subtraction operation to find a solution with min. complexity.
- Purushotham Kumar June 12, 2013 in Ireland
i/p : 25
o/p : True
i/p : 44
o/p: False| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test - 1of 1 vote
AnswersIf an N X N matrix is given, print it in spiral order.
- GKR April 07, 2013 in United States
Example: Below is 5 X 5 matrix
i l o v e
d i n t e
n i e e p
a v w r i
m a x e c
Print in spiral order. Output is iloveepicexamandinterview| Report Duplicate | Flag | PURGE
Epic Systems Algorithm C C++ C# Coding Java