Algorithm Interview Questions
- 1of 1 vote
AnswersIn a series of 1 to N, two numbers are missing. Find the missing numbers? Quickest way?
- xankar March 16, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Algorithm - 1of 1 vote
AnswersWrite a program to sum two binary numbers represented as strings.
- rodrigoreis22 February 11, 2013 in United States
Input: "110", "01101"
Output: "10011"
Method signature:
public String addBinaryNumbers(String num1, String num2);| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven 2 arrays A,B, where x(A.length) < y(B.length), we want to
- An0nemous October 08, 2012 in -
insert (y - x) 0's to A at various places such that A*B is minimum. For instance, if A = (1, -1) and
B = (1,2, 3, 4), then inserting two 0's in the middle of A such that A = (1, 0, 0, -1) would minimize
A*B. I think he was looking for a dynamic problem solution.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array of sorted integers and find the closest value to the given number. Array may contain duplicate values and negative numbers.
- Vijay November 17, 2017 in India
Example : Array : 2,5,6,7,8,8,9
Target number : 5
Output : 5
Target number : 11
Output : 9
Target Number : 4
Output : 5| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm Arrays Coding Data Structures - 1of 1 vote
AnswersYou are given a string "abc" which is encoded like "123" where alphabets are mapped like a => 1 to z => 26. Now find out how many string can be formed by reverse engineering encode string "123".
- sachin323 May 16, 2016 in United States
For ex. given string "123" we can form 3 string "abc"(1,2,3), "lc" (i.e 12,3), "aw"(1,23).
for string "1234" we have following possible combinations, I might be missing some of them but you get the idea
{12, 3, 4}
{1, 23, 4}
{1, 2, 3, 4}| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersGiven n. Generate all numbers with number of digits equal to n, such that the digit to the right is greater than the left digit (ai+1 > ai). E.g. if n=3 (123,124,125,……129,234,…..789)
- codr December 26, 2013 in United States| Report Duplicate | Flag | PURGE
Epic Systems Algorithm - 1of 1 vote
Answersgenerate permutations of a string without duplicates and without using hashtable to memorize the permutations.
- Andi December 05, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
Answersfind longest increasing sub sequence in 2d array.
- nagyuga August 22, 2012 in United States
(bit more expl..)
ex: finding length of the snake in snake game
---------
the sequence must not be diagonally.
but it can be any like top-bootm,bottom-left-top ........
increasing means one step
ex: 10,11,12,13 (correct)
12,14,15,20(wrong)
Ex: input: consider 4x4 grid
2 3 4 5
4 5 10 11
20 6 9 12
6 7 8 40
output : 4 5 6 7 8 9 10 11 12| Report Duplicate | Flag | PURGE
Epic Systems Software Development Manager Algorithm - 1of 1 vote
AnswersYou are given an array, that is sorted, however was rotated to the right by a certain distance. The array may contain duplicated values. Find the index of a given element in the array.
- joe kidd August 03, 2014 in India
Example: {3, 9, 9, 9, 8, 10, 12, 13, 1, 2, 3}, element = 3, returns, any of indexes that 3 is present.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersFind all unique pairs of element in an array that sum to S. For ex. If array = {2,4,6,4,6} and S = 8 then answer is {(2,6), (4,4)}
- irraju July 12, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Site Reliability Engineer Algorithm - 1of 1 vote
AnswersGiven the start and an ending integer as user input, generate all integers with the following property.
- lucky March 21, 2012 in United States
Example : 123 , 1+2 = 3 , valid number
121224 12+12 = 24 , valid number
1235 1+2 = 3 , 2+3 = 5 , valid number
125 1+2 <5 , invalid number| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 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 - 1of 1 vote
AnswersYou are given n dices each with heads numbered from 1 to m. You are to throw the n dices and note down the sum of the numbers on each of the n dices. You'll be give a number x and its a win if the sum obtained is greater than x. The problem is the find out the winning probability given n, m and x.
- ALgeek September 28, 2012 in India
Note 1<=n<=100,
1<=m<=10,
m<=x<=n*m.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersWrite Program to find longest common contiguous intersection from 2 lists provided to the function.
- aaz February 29, 2012 in United States for Intern
Example: list1: abcrfghwetf
list2: abrfghwwetxyab
Longest common intersection here is: fghw
Need Effecient Algorithm to implement this in Java or C, not using arrays.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm C Data Structures Ideas - 1of 1 vote
AnswersConvert an array "a1 a2 a3...an b1 b2 b3...bn c1 c2 c3...cn" to "a1b1c1 a2b2c2...anbncn", inplace.
- max October 12, 2011 in -| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersA rooted binary tree with keys in its nodes has the binary search tree
- Rahul June 09, 2011
property (BST property) if, for every node, the keys in its left
subtree are smaller than its own key, and the keys in its right
subtree are larger than its own key. It has the heap property if, for
every node, the keys of its children are all smaller than its own key.
You are given a set of n binary tree nodes that each contain an
integer i and an integer j. No two i values are equal and no two j
values are equal. We must assemble the nodes into a single binary tree
where the i values obey the BST property and the j values obey the
heap property. If you pay attention only to the second key in each
node, the tree looks like a heap, and if you pay attention only to the
first key in each node, it looks like a binary search tree.Describe a
recursive algorithm for assembling such a tree| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Data Structures Trees and Graphs - 1of 1 vote
AnswersDesign an algorithm to find whether a given string is formed by the interleaving of two given strings or not.
- Aditya December 07, 2007
s1= aabccabc
s2= dbbabc
s3= aabdbbccababcc
Given s1,s2,s3 design an efficient algorithm to find whether s3 is formed from the interleaving of s1 and s2.| Report Duplicate | Flag | PURGE
Deshaw Inc Financial Software Developer Data Structures Coding Algorithm - 1of 1 vote
AnswersGiven the array of integers containing equal number of even and odd numbers. Rearrange
- zammer May 26, 2015 in India
the array such that even number is at even place and odd number is at odd place.
Example : [2,1,3,4,7,9,24,98]
Answer : 1,2,3,4,7,24,9,98| Report Duplicate | Flag | PURGE
VMWare Inc SDET Algorithm - 1of 1 vote
AnswersYou are given a grid of numbers. A snake sequence is made up of adjacent numbers such that for each number, the number on the right or the number below it is +1 or -1 its value. For example,
- T December 07, 2012 in United States
1 3 2 6 8
-9 7 1 -1 2
1 5 0 1 9
In this grid, (3, 2, 1, 0, 1) is a snake sequence.
Given a grid, find the longest snake sequences and their lengths (so there can be multiple snake sequences with the maximum length).| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an N x M matrix having only positive values, we have to nullify the matrix i.e make all entries 0.
- anurag.gupta108 September 20, 2012 in United States
We are given two operations
1) multiply each element of any one column at a time by 2.
2) Subtract 1 from all elements of any one row at a time
Find the minimum number of operations required to nullify the matrix.
Note: no range of input was given| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array which contains the parent of the ith element in the n-ary tree.Parent[i] = -1 for root.
- grave July 07, 2012 in India
Find the height of the tree.
Gave O(n2) ,space O(1).
Expected Complexity- Linear
You can use extra space if you want.
Example-
{-1 0 1 6 6 0 0 2 7}
0 1 2 3 4 5 6 7 8
0 is the root here.
0 is the parent of 1 5 6
1 is parnt of 2
6 is parent of 3 4
2 is of 7 which is parent of 8.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Data Structures Hash Table Trees and Graphs - 1of 1 vote
AnswersThere is very long array of ints, and you are given pointer to base addr of this array.. each int is 16bit representation... you need to return the pointer to tht "bit" inside array where longest sequence of "1"s start
- gradStudent June 16, 2010| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays Bit Manipulation Computer Architecture & Low Level - 1of 1 vote
AnswersGiven a N*N chess board, a robot starts from the left-up corner and ends at right-down corner. It can only move one cell per time and the direction must be right or down.
- crazystone April 10, 2008
Give the algorithm that count all possible paths.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a list L of video names and their watch rates, write a function that will return the videos with the top 10 watch rates. Video names may appear more than once.
- neer.1304 July 03, 2019 in United States
Example:
L = [(‘abc’, 10), (‘def’, 15), (‘ghi’, 10), (‘abc’, 12), …, (‘xyz’, 100)]
The function should return [‘xyz’, ‘abc’, …, ‘def’, ‘ghi’]| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersGiven a string S, print the longest substring P such that P > S lexicographically.
- emb March 16, 2016 in United States
You may assume that such substring exists.| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersReverse string except spaces. A string has mix of alphabets and spaces. Your task is to reverse the string, but preserve the positions of spaces. For example, reverse of " a if" is " f ia".
- sg July 22, 2015 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm - 1of 1 vote
AnswersWrite a program to generate all palindrome dates by taking the beginning and the ending dates as an input from the user. The format of the date is given as MMDDYYYY.
- lucky March 21, 2012 in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an input array of integers of size n, and a query array of integers of size k, find the smallest window of input array that contains all the elements of query array and also in the same order.
- Ankul Garg August 28, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Algorithm - 1of 1 vote
AnswersYou have an array of unique integer numbers and only one operation: MoveToFront(x) that moves given number to the beginning of the array.
- emb July 02, 2016 in United States
Write a program to sort the array using the minimum possible number of MoveToFront() calls.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersSort a singly-linked list of unknown size using constant space.
- trunks7j March 25, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm