Recent Interview Questions
- 0of 0 votes
AnswersGiven an unsorted array.
- Shobhit October 07, 2012 in United States
With each number, we can associated a sum which is equal to the sum of all the numbers, less than the current number.
We've to find the total sum of all those numbers.
e.g. unsorted array :1, 5, 3, 6, 4.
for a[0]=1, sum[0]=0
for a[1]=5, sum[1]=1
for a[2]=3, sum[2]=1
for a[3]=6, sum[3]=1+5+3
for a[4]=4, sum[4]=1+3
total sum =sum[0]+sum[1]+sum[2]+sum[3]+sum[4] = 15| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays - 0of 0 votes
AnswersWrite a function that given a Binary tree, can find out if its a Binary Search Tree
- mlm09k October 02, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array of integers. Re arrange the numbers such that odd numbers occupy odd position and even numbers occupy even position. The order of numbers should not change and it is to be done in-place.
- Nascent September 16, 2012 in India| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer - 2of 2 votes
Answerstwo BST are given find common elements in both....
- abhishek September 09, 2012 in India for idc| Report Duplicate | Flag | PURGE
Microsoft Intern Trees and Graphs - 0of 2 votes
AnswersOn a 2-D grid, the positions (x,y) of 3 persons are given. Find the meeting point such that sum of distances of each person from meeting point is minimized.
- Andy2000 September 04, 2012 in United States
Now generalize this to N persons and solve.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a array, find the largest contiguous sub-array having its sum equal to N. ( optimal solution only)
- sam August 28, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answersgiven an array of sorted integers with duplicate values , sort the array so that there are only unique values left in sorted order ( do not use any additional data type , do inplace sort )
- Tester August 09, 2012 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Coding - 0of 0 votes
AnswersGiven the Pre-order of the BST .check if each non-leaf node has only one child.Linear Time is expected.
- grave July 31, 2012 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 0of 0 votes
AnswersGiven an array of positive integers of 2*n elements, you need to divide the array in two equal halves such that the sum of two halves are closest(or the difference of the sum is least). For e.g
- shivi116 June 30, 2012 in India
Array = {1,2,3,4,5,6,7,8,9,10}
The desired two halves will be :
{1,4,6,7,10} and {5,2,3,8,9}
Difference between two halves = |28 - 27 | = 1 which is least among all other combination's.
You can safely assume that sum of whole array < 10^6| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersYou have been given three arrays A,B and C.
- Ajax May 21, 2012 in India
You have to find out all the elements in A and B such that the A[i]-B[j]=C[k]| 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 - 0of 0 votes
AnswersGiven a list, L, of size k. L contains elements between 1 and n. Also given a function RND() such that this function returns a number between 1 and INT_MAX.
- Him53 January 10, 2012 in India
Now generate number between 1 and n, using RND(), such that the element should not be there in the list L. All elements should have a uniform probability.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an Array A={-2,4,30,-50,90,-60,100,120}
- cmsuraj007 October 20, 2011 in United States
The array index represents time of day.
Say 0-9 A.M, 1- 10 A.M....etc
And value represents stock price at that time.
Get the max profit. i.e in this input,
best buying price=-60
best selling price=120| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Arrays - 0of 0 votes
Answersfind the index of the highest bit set of a 32-bit number (without loops obviously)
- pavel.em October 18, 2011 in -| Report Duplicate | Flag | PURGE
Microsoft Bit Manipulation - 0of 0 votes
AnswersGiven an unsorted array of numbers. Find if the array consists of consecutive numbers after sorting. Do this in linear time.
- Anonymous March 15, 2011
Example 1: If array has 5,2,3,1,4
after sorting we get 1,2,3,4,5 which represents consecutive numbers
Counter Example:
If the array has 34,23,52,12,3 after sorting we get 3,12,23,34,52 which are not consecutive| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 2 votes
AnswersLongest Common Prefix from N strings of max length "m".
- Ajeet March 14, 2011
I gave a naive approach of O(n.m) and O(m.logn) with some adjustments but Interviewer wanted something O(n+m) or better than O(n.m).
Please suggest solutions.
eg:
Flower
Flow
Flight
Output:
Fl| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere are two poles of equal height 15mts. One cable with length 16mts is hanging between that two poles. The height from center of the cable to earth is 7mts then what is the distance between that two poles.
- coolGuy March 04, 2011
How to solve this ?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Brain Teasers - 0of 0 votes
AnswersGiven a random function that generates a random number between 1 and 5 inclusive, write a function to generate a random number between 1 and 7 inclusive.
- Alzaadi shau neum December 24, 2010| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer - 0of 0 votes
AnswersGiven a unordered array of numbers, remove the fewest number of numbers to produce the longest ordered sequence. Print count of fewest numbers to be removed, and the remaining sequence.
- Anonymous November 30, 2010
For example, if input is 1 2 3 4 5 6 7 8 9 10, no (zero) numbers are removed, and input is the longest sequence.
If input is, 1 2 3 8 10 5 6 7 12 9 4 0, then fewest number of elements to be removed is 5 is the fewest number to be removed, and the longest sequence is 1 2 3 5 6 7 12.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array in place [do not use any extra space].
- coder November 01, 2010
e.g. If input array is [1,3,6,8,-5,-2,3,8] It should be converted to: [-5,-2,1,3,3,6,8,8]| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Coding - 0of 0 votes
AnswersA robot has to move in a grid which is in the form of a matrix. The robot can go 1) A(i,j) to A(i,j+1) or 2) A(i,j) to A(i+1,j). Find an efficient way of computing the unique number of paths from A(0,0) to A(m-1,n-1) for the grid represented by the matrix A mxn
- InterviewMeLikeNeverBefore October 21, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
AnswersPrint all edge nodes of a complete binary tree anti-clockwise.
- Mahesh September 01, 2010
That is all the left most nodes starting at root, then the leaves left to right and finally all the rightmost nodes.
In other words, print the boundary of the tree.
Variant: Print the same for a tree that is not complete.
(I traversed the tree twice, but interviewer said there is a recursive way to solve this)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersQ. There is an array
- Anonymous August 29, 2010
A[N][M] =
1 2 3
4 5 6
The array is rotated so that
A'[M][N] =
3 6
2 5
1 4
is obtained.
Establish the relation between A and A' by using i, j, M, N
A[i][j] = A'[_][_]| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Arrays