vodangkhoa
BAN USER
Graduated from UT Austin. Working for Amazon.com
- 0of 0 votes
AnswerWhat is a pointer?
- vodangkhoa| Report Duplicate | Flag | PURGE
Ebay Software Engineer / Developer Terminology & Trivia - -3of 3 votes
AnswersGiven a Starting Node and Ending Node in a Graph where each Node has a pointer to its parent and all its children nodes. Find all the leaf nodes between the Starting and Ending Node.
- vodangkhoa| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere are n petrol bunks arranged in circle. Each bunk is separated from the rest by a certain distance. You choose some mode of travel which needs 1litre of petrol to cover 1km distance. You can't infinitely draw any amount of petrol from each bunk as each bunk has some limited petrol only. But you know that the sum of litres of petrol in all the bunks is equal to the distance to be covered.
- vodangkhoa
ie let P1, P2, ... Pn be n bunks arranged circularly. d1 is distance between p1 and p2, d2 is distance between p2 and p3. dn is distance between pn and p1.Now find out the bunk from where the travel can be started such that your mode of travel never runs out of fuel.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersHow long it would take to sort 1 billion numbers? make any assumptions you wanted.. assume the computer would have more than 4 GB of RAM, so the array would fit in memory in its entirety, and the machine would run at 4 GHz.
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - 0of 0 votes
AnswersGiven a list A with n elements, produce a list B with n elements such that the ith element of B is equal to the product of all elements except the ith in list A. Example: Given list A = [1, 2, 3], make a function f(x) such that f(A) = [6, 3, 2].
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersSuppose you have a huge file (few million entries). Each line has a name; an id and age, all three separated by a space. How do you go about sorting this and writing this in a sorted order in another file? Of course you can't read the whole thing in memory.
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven an array having first n ints and next n chars.
- vodangkhoa
A= i1 i2 i3 ... in c1 c2 c3 ... cn
Write an in-place algorithm to rearrange the elements of the array as:
A = i1 c1 i2 c2 ... in cn| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven two binary trees T1 and T2 which store character data, duplicates allowed. You have to devise an algorithm to decide whether the T2 is a subtree of T1. T1 has millions of nodes and T2 has hundreds of nodes.
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersPrint all combinations of M members of a set of N elements in a sequence such that each set can be obtained from the previous set by deleting one member and adding one member.
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding Algorithm - 3of 3 votes
AnswersGiven a value and a binary search tree.
- vodangkhoa
Print all the paths(if there exists more than one) which sum up to that value. It can be any path in the tree. It doesn't have to be from the root.| Report Duplicate | Flag | PURGE
Microsoft Yahoo Software Engineer / Developer Trees and Graphs Coding Algorithm - 0of 0 votes
AnswersYou are given a the source to a application which is crashing when run. After running it 10 times in a debugger, you find it never crashes in the same place. The application is single threaded, and uses only the C standard library. What programming errors could be causing this crash? How would you test each one?
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Testing - 2of 0 votes
AnswersGiven a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1 using only one call to strstr routine?
- vodangkhoa
(eg given s1 = ABCD and s2 = CDAB, return true)
(given s1 = ABCD, and s2 = ACBD , return false)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding Algorithm - 0of 0 votes
AnswersThere is a building of 100 floors. If an egg drops from the Nth floor or above it will break. If it's dropped from any floor below, it will not break. You're given 2 eggs. Find N, and minimize the number of drops for the worse case.
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Highbridge Capital Software Engineer / Developer Financial Software Developer Brain Teasers Algorithm - 1of 1 vote
AnswersFor small dataset (less than 200 elements), why is unsorted array has better performance than binary tree? This wasn't the case 20 years ago. (Hint: It has to do with computer architecture.)
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Computer Architecture & Low Level Data Structures - 0of 0 votes
AnswersImplement Atoi(char *str)
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding - -2of 0 votes
AnswersMerge two sorted array
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven a binary tree where each node's value is a COLOR. A clump is formed when more than 3 COLORS are adjacent to each other. Return the total number of clumps in a binary tree.
- vodangkhoa| Report Duplicate | Flag | PURGE
National Instruments Software Engineer / Developer Coding - 1of 0 votes
AnswersA disk is partioned into two hemispheres colored in black and white and the disk is rotating.By appropriate positioning of sensors (A sensor can read the disk near it as black or white) we need to find the direction of the motion of the disk.
- vodangkhoa| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Computer Architecture & Low Level - 0of 0 votes
AnswersAsked me about XML. XML was on my resume but I don't know much about it. I only have used it a few times. Note to self - take anything that I don't know too well about off my resume.
- vodangkhoa| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer General Questions and Comments - 0of 0 votes
Answers3rd Interview - Technical. You have 5 basketball teams. You want them to play each other only once. Each team plays once a week. If a team plays a home game this week, They should play a aways game the coming week. How many weeks does it take for all the teams for play each other?
- vodangkhoa| Report Duplicate | Flag | PURGE
Intuit Software Engineer / Developer Math & Computation - 0of 0 votes
AnswersYour hardest class.
- vodangkhoa| Report Duplicate | Flag | PURGE
Boeing Software Engineer / Developer Experience - 0of 0 votes
AnswersQuestions about OOP, Design Patterns, Java, and C++. Just basic OOP questions like Pure Virtual Functions, Virtual Pointer Table, Abstract classes, Interfacce, Inheritance, Polymorphism.
- vodangkhoa| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Terminology & Trivia - 0of 0 votes
Answers100 closed lockers. You begin by opening all 100 lockers. Next, you close every second locker. Then you go to every third locker and close it if it is open or open it if it is closed (call this toggling the locker). After your 100th pass of the hallway, in which you toggle only locker number 100, how many lockers are open?
- vodangkhoa| Report Duplicate | Flag | PURGE
Infosys Microsoft Software Engineer / Developer Brain Teasers
7 Answers PIE
For some who don't know what PIE is, PIE stand for Programming Interviews Exposed. It's a very popular interview book. I highly recommend it. I have interviewed with plenty high companies and I usually get at least 1 technical question that this book talked about. The 2nd edition of this book was released recently.
- vodangkhoa April 29, 2007| Flag | PURGE
It's not too late. Since you already have some working experience, you can leave your GPA off if it's too low.
- vodangkhoa April 12, 2009It's not too late. Since you already have some working experience, you can leave your GPA off if it's too low.
- vodangkhoa April 12, 2009Please post your interview questions :). It would be useful to all of us.
- vodangkhoa August 31, 2008Find all the slopes for every pair on the plane which is N^2 algorithm. The slope that occurs the most would form the line that intersects the most points. Can anyone think of a better algorithm?
- vodangkhoa July 05, 2008It would be cool to have a feature to sort the questions by date
- vodangkhoa July 04, 2008int getQuotient(int numerator, int denom){
if (numerator < denom)
{
return 0;
}
else
{
return 1 + divide(numerator - denom, denom);
}
}
boolean containWord(Board board, String result, final String TOFIND){
if (result.equals(TOFIND)){
return true;
} else {
foreach (Char char: board){
foreach (Char c: getNeighbors(char))
boolean result = containWord(board, result + c) || containWord(board, result);
if (result){
return true;
}
}
}
return false;
}
Amazon would pay you more. At Amazon, I notice that many young engineers get promoted quickly if they do a good job.
- vodangkhoa May 29, 2008I have had similar experience with Bloomberg.
I wonder why they are so arrogant. The developers at Bloomberg claim to make a lot of money but they don't. And obviously they are not the most desirable company to work for for CS graduates.
Even though this question is easy, it has a lot of edge cases. You should think twice when questions look simple.
- vodangkhoa April 19, 2008Binary Heap is your answer.
- vodangkhoa April 10, 2008This is NP-Complete problem called Subset Sum. en.wikipedia.org/wiki/Subset_sum_problem
- vodangkhoa April 07, 2008Really?
If you user calls Enqueue 10 times then call dequeue, I think I have all the tasks at my hands, don't I? Am I misunderstanding something?
In any case, sorting is not the optimal solution. Hash table and binary heap are your friends for this problem?
It's not as hard as it seems.
It's just topological sort.
A) For all tasks that don't have dependencies, just sort the tasks by their priority.
B) For all tasks that have dependencies, just do topological sort. Then go to step A if there are multiple tasks without dependencies.
Good solution!
- vodangkhoa March 05, 2008I'm trying to make this website contains the most extensive interview questions on the web. This website was very helpful to me when I was interviewing. I just want to give something back. I'm also a moderator for this website too. If you search on blogsearch.google.com, you'll find many more interview questions from Amazon, Microsoft, and many other tech companies.
My intention for posting these interviewing questions isn't about generating discussion. I just want to expose to people who are interviewing with these tech companies to a different array of questions.
I work for Amazon so I might use any of these questions any day when I interview people. So you might potentially run into them. But yes, most of them are from MS, Amazon, and Google that I found on the web. Since we're not allowed to post Google interview questions on here, I'll put it under different companies. Why do you care so much about whether I put the correct company down?
There are 126 interview questions from Bloomberg on this website. I think this should be plenty.
- vodangkhoa January 30, 2008I would expect your base to be around 120k.
- vodangkhoa January 20, 2008Is there a range for these values?
- vodangkhoa January 05, 2008Yup! Good solution.
- vodangkhoa December 01, 2007It means the amount of memory your algorithm consumes doesn't depend on the input. Your algorithm should use the same amount of memory for all inputs.
- vodangkhoa November 21, 2007Hi Greatht
Can you explain your algorithm more in details? I still don't get why it works.
This is a typical combinatorial search algorithm. Find all possible subsets and only print out subset with length k.
- vodangkhoa November 13, 2007First go through the array and sum up the integers then divide it by two.
let half = sum(array)/2;
Now find a subset of integers in the array such that the sum is equal to half. There are cases where no solution exist.
As you can see, finding subset then sum up the subset has many redundancies. Using dynamic programming can make this problem faster.
There is a ACM UVA problem called Tug of War that is similar to this.
You can use Binary Search for this example. Whenever you hit a empty spot, just traverses left or right until you find a string. Use this string to determine where you're going next.
- vodangkhoa September 26, 2007opps! I didn't read it carefully. Look up Selection Algorithm.
- vodangkhoa June 17, 2007Look up counting sort. Using an approach similar to this would give you linear time.
- vodangkhoa June 13, 2007Find the max depth and min depth. The difference between these two numbers shouldn't be more than 1.
- vodangkhoa June 10, 2007That I don't have. Buy one from Amazon.com or your local bookstore.
- vodangkhoa June 06, 2007Suggest a cryptographic hash function, SHA1 or MD5. They are expensive but very good hash function.
- vodangkhoa June 05, 2007"maximum" means longest
- vodangkhoa May 14, 2007You are wasting memory on something that doesn't need random access. With a linked list, you're not wasting any memory.
"A Stack is usually implemented with a Linked List. You always Push and Remove at the head."
Everytime you push into the stack, make that element the Head. Everytime you pop from the stack, remove the Head. All constant time. No searching.
Using a linked list, you are wasting only a few more instructions compare to the array method but on a 1 gig machine, to execute a single instruction is 1 nsec = (1/1,000,000,000) sec. A few more instructions aren't that big of a deal.
Can you post some of those questions on this website? It would be helpful for anyone who wants to interview with those companies! Thanks!
- vodangkhoa May 10, 2007You need two more recursive calls to printPathsRecur where you don't subtract the sum. Something like this.
else {
printPathsRecur(node->left, path, pathLen, sum-node->left.data);
printPathsRecur(node->right, path, pathLen, sum-node->right.data);
printPathsRecur(node->left, path, pathLen, ORIGINAL_SUM);
printPathsRecur(node->right, path, pathLen, ORIGINAL_SUM);
}
ORIGINAL_SUM is the sum that was passed in at the beginning.
A Stack is usually implemented with a Linked List. You always Push and Remove at the head.
- vodangkhoa May 10, 2007nice solution. Another solution: Divide your array into 3 pieces of memory where each piece represent a linked list. Basically have 3 pointers each pointing to the beginning of each linked list. With this solution, you can shift these pointers around to create a bigger or smaller linked list to take advantage of the free space.
- vodangkhoa May 10, 2007About 1 year I think.
Microsoft, Expedia, RealNetworks, Redfin, Jobster.
Amazon interviews are very technical. There are more than 200 interview questions from Amazon on this website. Most of their questions are very similar. Try to solve all of them and you'll do well. Good luck!
- vodangkhoa April 29, 2007A few reasons why contiguous memory are better is because
1) You have random access.
2) Better locality - Whenever the OS brings data into memory, it loads a whole page. Less page fault. With linked list, different parts of the linked list are stored at different parts of memory.
Branch Prediction doesn't work as well with linked list. This causes the pipeline to be flushed more often which result in poor performance.
keep a counter for Parentheses, Bracket, and Curly.
let p = 0;
let b = 0;
let c = 0;
scanning from left to right on our sequence, if we see opening p or b or c, we increment by 1 the appropriate variable and decrement by 1 if we see a closing P or B or C.
From the above examples are not enough.
We check if the string is correct or not every time we see
1) A CLOSING sign. There are a few cases here.
2) an end of string character. p|c|b should all be zeros.
Here is the code.
Given: "1234" and N = 2
It would print out "13", "14", "24"
all other strings ("43","41"..) are just permutation of the above result.
Working code. Just copy and paste it to your favorite IDE then compile away.
#include <iostream>
#include <string>
void printComb(const char ar[], bool used[], int SIZE){
string str = "";
for (int i = 0; i < SIZE; ++i){
if (used[i]){
str += ar[i];
}
}
cout << str << endl;
}
//variable u keeps track of the number of
//characters in our result
void comb(const char ar[], bool used[], int index, int u, int N, int SIZE){
if (u == N){
printComb(ar, used, SIZE);
} else if (index >= SIZE){
return;
} else {
used[index] = true;
++u;
comb(ar, used, index + 2, u, N, SIZE);
used[index] = false;
--u;
comb(ar, used, index + 1, u, N, SIZE);
}
}
int main(){
int N = 2;
string str = "1234";
bool used[str.length()];
for (int i = 0; i < str.length(); ++i){
used[i] = false;
}
comb(str.c_str(), used, 0, 0, N, str.length());
}
is {1, 3, 10} and {10, 1, 3} equivalent? Should both be print out?
- vodangkhoa April 22, 2007That is a cool solution.
- vodangkhoa April 15, 2007Are the other elements in this array unique? If they are, I think I have the solution. What about memory requirement?
- vodangkhoa April 13, 2007
It really depends on what that code is doing. Branches usually indicate that that code is hard to read.
- vodangkhoa May 26, 2011Whenever you see a lof of if conditions, try to refactor it using a hashmap if it's all possible.