Algorithm Interview Questions
- 1of 1 vote
AnswersWrite a function, that given a list of integers and an integer s, prints any 2 numbers in the list that sum to s.
- overshine February 07, 2013 in United States
1, 2, 3, 4, 5 sum = 6 could print:
1 + 5 = 6
2 + 4 = 6
4 + 2 = 6
5 + 1 = 6| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersFind the number of substrings of a string that are palindromes.
- gats July 08, 2012 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersLet's say there is a file consists of billions of records data.
- aliciabondie23 July 05, 2012 in United States
The file cannot fit into memory, and you need to reverse each word in that huge file and then save the reversed words to another file.
How would you implement this?| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array of integers, design an algorithm that moves all non-zero integers to the end of the array. Minimize the number of writes or swaps.
- pygrammer January 21, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm Arrays - 1of 1 vote
AnswersGiven an array of n integers. MaxPrefix is defined as count of elements those are greater than the element and in the right side of array wrt to the element. Write a program to give the max of MaxPrefix Ex. Input 10 -4 6 2 8 9 4 Output is 5
- darklight June 19, 2016 in India| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersFind a duplicates in an array of length n. The values are positive integers in the range between 1 .. n-1
- tested.candidate July 14, 2015 in Switzerland| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersGiven a number A, find the smallest number which has only 1s and 0s as its digits which divisible by the number A. For example: if the given number A is 4, the smallest number with 1s and 0s is which is divisible by 4 is 100.
- xyz_coder February 06, 2015 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Arrays Coding - 1of 1 vote
AnswersGiven a sorted array, write a function to search first occurrence of a number in the array. If not found return -1.
- piyush290490 May 27, 2013 in India
Example::
{2,2,2,3,4,5,5,6,6,8,9}
search 6
should return 7.| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - 1of 1 vote
AnswersGiven a string, find the start position of the largest block of repeated charactes.
- hnrqbaggio January 24, 2013 in United States for Office
After the solution, I was asked to write down as many test cases I could to test the function as if it was created by someone else.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm Microsoft String Manipulation Testing - 1of 1 vote
AnswersWe have n number of sorted array for fixed length.
- Harsh123 November 04, 2012 in India for Kindle
Now we have to merge these and need to save finaly result array into given array.
Note- we can't use extra space except the given array.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays Data Structures Sorting - 1of 1 vote
AnswersGiven a dictionary and an char array print all the valid words that are possible using char from the array.
- neer.1304 December 02, 2016 in United States
Ex- char[] arr = {'e','o','b', 'a','m','g', 'l'}
Dict - {"go","bat","me","eat","goal", "boy", "run"}
Print - go, me, goal.
We can pre-compute as much we want but the query time must be optimal.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 1of 1 vote
AnswersUse the shorest unique prefix to represent each word in the array
- sunshihaosd October 25, 2014 in United States
input: ["zebra", "dog", "duck",”dot”]
output: {zebra: z, dog: do, duck: du}
[zebra, dog, duck, dove]
{zebra:z, dog: dog, duck: du, dove: dov}
[bearcat, bear]
{bearcat: bearc, bear: ""}| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersYou have two arrays of integers, where the integers do not repeat and the two arrays have no common integers.
- Billy Jim October 05, 2013 in United States
Let x be any integer in the first array, y any integer in the second. Find min(Abs(x-y)). That is, find the smallest difference between any of the integers in the two arrays.
Assumptions: Assume both arrays are sorted in ascending order.| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven N arrays with sizeof N, and they are all sorted, if it does not allow you to use extra space, how will find their common datas efficiently or with less time complexity?
- yingsun1228 February 04, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersRandomly return a node in a binary tree, program in C/C++, and define the class or struct of the binary tree by yourself.
- superffeng April 20, 2012 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a huge file 100 million integers. He further divided the file into 100 files with 1 million integers in each and each file is sorted. Needed to find the k smallest integers.
- pulkit.mehra.001 April 07, 2014 in India
I used the concept of min-heap. Take the first element from each file and construct a min-heap. Take the root,as it is the smallest element and insert the next element from the file which contains the root root element. Heapify the tree and repeat k times.
The interviewer asked if another efficient method exists?| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven a sorted array which contains scores range from 0 to 100. Write a program to find occurrence of given score.
- MaYanK July 29, 2010
eg. 1,1,1,40,40,40,100,100
input: 40
o/p : 3 (as 40 appear 3 times in array)| Report Duplicate | Flag | PURGE
Google Developer Program Engineer Algorithm - 1of 1 vote
Answers/*
- cheeyim October 28, 2016 in Singapore
# There's a room with a TV and people are coming in and out to watch it. The TV is on only when there's at least a person in the room.
# For each person that comes in, we record the start and end time. We want to know for how long the TV has been on. In other words:
# Given a list of arrays of time intervals, write a function that calculates the total amount of time covered by the intervals.
# For example:
# input = [(1,4), (2,3)]
# > 3
# input = [(4,6), (1,2)]
# > 3
# input = [(1,4), (6,8), (2,4), (7,9), (10, 15)]
# > 11
*/| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersGiven a number print the number of combinations you can derive from the number. 1=A, 2=B, 26=Z, 0=+.
- SHR March 14, 2016 in India
For example: 1123 can be represented by 1,1,2,3 which would stand for AABC.
Another representation - 11,23 - JW
Another representation - 1,1,23 - AAW
Another representation - 11,2,3 - JBC
For number 1123, there will be 5 combinations.| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 1of 1 vote
AnswersGiven a set of values 0-9, return all permutations of that set of length n. Example: n=2, set ={2,3,4} Return: {2,2}, {3,3}, {4,4}, {2,3}, {3,2}, {3,4}, {4,3}, {2,4}, {4,2}
- PradeepN October 27, 2015 in United States| Report Duplicate | Flag | PURGE
Google Algorithm - 1of 1 vote
AnswersGiven an array of numbers, find a pair whose sum is closest to zero.
- psuedo April 10, 2015 in India| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersGiven a n by m matrix of bits find the largest X that is formed in the matrix and return the size of the diagonal of that X. An X is defined as 2 equally sized diagonals that share a single 1.
- pretonesio September 02, 2013 in United States for Powerpoint
For instance, the matrix:
00100001
00010010
00001100
00001100
00010010
00100001
Will return a size of 1, because the given X is invalid as the middle part does not share a single 1. On the other hand, the following matrix
101
010
101
Will return a value of 3, as the diagonal is 3. Write such program,| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 1of 1 vote
AnswersYou given an array:
- SK July 07, 2013 in India
3, 2, 1, 6, 5, 4, 9, 8, 7
you have to find a 3 tuple which has property a < b < c, also a is before b, b is before c in array.
Answer can have multiple tuples, you have to find any one.
In this array, answer will be 3, 6, 9| Report Duplicate | Flag | PURGE
Flipkart Senior Software Development Engineer Algorithm - 1of 1 vote
AnswersReally like the linear solution of this problem. You have an array of 0s and 1s and you want to output all the intervals (i, j) where the number of 0s and numbers of 1s are equal.
- Martin May 27, 2011
Example
pos = 0 1 2 3 4 5 6 7 8
0 1 0 0 1 1 1 1 0
One interval is (0, 1) because there the number of 0 and 1 are equal. There are many other intervals, find all of them in linear time.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersFind the anagrams from a list of strings
- coder145 April 19, 2016 in United States
Input : {"tea", "ate", "eat", "apple", "java", "vaja", "cut", "utc"}
Output : {"tea", "ate", "eat","java", "vaja", "cut", "utc"}| Report Duplicate | Flag | PURGE
Twitter Senior Software Development Engineer Algorithm - 1of 1 vote
Answers/*
- thomascom136 August 03, 2013 in United States
Random set of WORD.
Criterion : Given a word find out if the word can be broken into smaller word, by removing one alphabet at a time.
a) all such word should be valid dictionary word.( Assume a function is there to test whether the word exist in dictionary)
b) Remove one alphabet at a time but the new word need to be in dictionary.
For eg :
restated -> restate -> estate -> state -> stat -> sat -> at -> a
fullfill the criterion. ( single alphabet assume belong to dict)
My solution below. I assume it can be done using dynamic programming or trie data structure
*/| Report Duplicate | Flag | PURGE
Google Java Developer Algorithm - 1of 1 vote
AnswersGiven N students, find the number of ways the students could be ranked. Also one or more students can have ties and can have the same ranks. I was stumped at this question. Seem like a dp question?? Any suggestions?
- amm February 25, 2011| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm