Coding Interview Questions
- 0of 0 votes
Answersswap kth element from the beginning and kth element from the end of linked list.
- anonymous June 21, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 0of 0 votes
Answersprint a decimal number in binary form. eg: number=10 or 2.22 or 0.876 ....
- anonymous June 21, 2013 in India
required to print only four number after decimal point| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 0of 0 votes
Answersfind all elements in the loop of an linked list....( linked list may or may not have loop)
- anonymous June 21, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 0of 0 votes
AnswersGiven a binary tree, for each node in the tree find the nodes with value greater than or equal to current node and sum them with the value of the current node. replace the node value with the above calculated sum....
- anonymous June 21, 2013 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 18of 18 votes
AnswersIf a=1, b=2, c=3,....z=26. Given a string, find all possible codes that string can generate. Give a count as well as print the strings.
- diffuser78 June 07, 2013 in United States
For example:
Input: "1123". You need to general all valid alphabet codes from this string.
Output List
aabc //a = 1, a = 1, b = 2, c = 3
kbc // since k is 11, b = 2, c= 3
alc // a = 1, l = 12, c = 3
aaw // a= 1, a =1, w= 23
kw // k = 11, w = 23| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm Coding - 0of 0 votes
AnswersWrite a MapReduce job that takes in two text files, and output the probability that those two files are identical (with 0% -> completely different, 100% -> completely different).
- tazo June 06, 2013 in United States
Clarification: Matching should not be a per-line diff, but it's about the content. One article could be 80 characters per line in one version, but could be 100 characters per line in another version, for the same content. In that case, it should be 100% match even though, if you are comparing line by line, they are totally different.| Report Duplicate | Flag | PURGE
Yahoo Coding - 0of 0 votes
AnswersGiven +ve numbers in an array . Put the even #s to the left of the array and the odd to the right side of the array . Don't use extra array.
- meek June 05, 2013 in United States| Report Duplicate | Flag | PURGE
VMWare Inc Java Developer Coding Java Probability - -5of 7 votes
Answersneed to implement a weather report functionality. user will provide the city name , need to return the weather report.
- gopi.komanduri May 29, 2013 in India
if weather station exists n functioning properly , will return the weather report of that station .
else ,
will return the nearest available weather station report.
interviewer looking for optimized manner.
looking for datastructures to stores the cities n algo to return the report.| Report Duplicate | Flag | PURGE
Mentor Graphics Analyst Algorithm Arrays Bit Manipulation Brain Teasers C C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Dynamic Programming General Questions and Comments Graphics Hash Table Ideas Linked Lists Math & Computation Object Oriented Design Problem Solving Sets Sorting Stacks String Manipulation Terminology & Trivia Threads Trees and Graphs XML - 0of 0 votes
AnswersWrite a function to evaluate a string that has only integers, and operators '+' & '*'. The evaluation should be done in a single pass. For example passing "3*2+5*6" should result in this function returning 36.
- jyothiprasadb May 21, 2013 in United States| Report Duplicate | Flag | PURGE
Expedia Software Engineer in Test Coding - -1of 1 vote
AnswersWrite a function fix a loop in the linked list based on the assumption that the linked list is sorted.
- jyothiprasadb May 21, 2013 in India| Report Duplicate | Flag | PURGE
Expedia Software Engineer in Test Coding - 0of 0 votes
AnswersWrite a function to perform string replace without using any inbuilt functions.
- jyothiprasadb May 21, 2013 in India| Report Duplicate | Flag | PURGE
Oracle Software Engineer in Test Coding - 0of 0 votes
AnswersFind the maxProduct of three numbers from a given integer array.
1. Handle all the cases
2. Interviewer was looking for a complete code
- anushvenki May 12, 2013 in Indiapublic int maxPro() { // -5, -4, -3, -2 , 0 Int array[] = new Int[]{4,5,6,0,-5,-7,-2,-10}; Arrays.sort(array); // -10,-7,-5,-2,0,4,5,6 int count =0; for(int i =0; i<array.length();i++){ if(array[i]<0) count = count+1; } int maxProduct =1; if ( array.length()<3){ return -1; } else if( array.length()>=3 ){ int a=1; b=2; if(count>=2){ a = array[0]*array[1]*array[array.length-1]; b = array[array.length-1]*array[array.length-2]*array[array.length-3]; maxProduct = Math.max(a,b); } else if (count == 0 || count == 1 || count == array.length()){ maxProduct = array[array.length-1]*array[array.length-2]*array[array.length-3]; } } return maxProduct; }
| Report Duplicate | Flag | PURGE
Amazon Applications Developer Coding - 1of 1 vote
AnswersGiven a string, find the longest possible even palindrome (length of palindrome is even) from it.
- arun_lisieux May 10, 2013 in India
Eg:
Input: abcicbbcdefggfed
Output: defggfed (length is 8)
Available palindromes are
1) bcicb - has odd length
2) cbbc - even length
3) defggfed - longest palindrome with even length
This question was asked in a telephonic interview for my friend. I will be posting his solution in a day.| Report Duplicate | Flag | PURGE
Groupon Software Engineer / Developer Algorithm Arrays Coding String Manipulation - 1of 1 vote
Answersfollowing coins: half dollar, quarters,dime, nickel and penny. Print all the possible combinations of coins that will equal to one dollar.(Ex : (2) half-dollar , (4) quarter dollar etc )..
- Algorithms_99 April 29, 2013 in United States| Report Duplicate | Flag | PURGE
Yahoo Applications Developer Coding - 0of 0 votes
AnswersFlatten a List<List<Integer>> in Java and implement the hasNext() and next() methods.
- Ana April 23, 2013 in United States
e.g. [[6,8],4] should return true when at 6, 8 and false at 4.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 4of 4 votes
AnswersImplement a simple regex parser which, given a string and a pattern, returns a boolean indicating whether the input matches the pattern. By simple, we mean that the regex can only contain one special character: * (star). The star means what you'd expect, that there will be zero or more of any character in that place in the pattern. However, multiple consecutive stars are allowed. Some examples of valid input (and expected output):
- DJ April 20, 2013 in United States
f(a*b, acb) => true
f(abc*, abbc) => false
f(**bc, bc) => true| Report Duplicate | Flag | PURGE
Microsoft Senior Software Development Engineer Coding - 0of 0 votes
AnswerWrite a service or services to support tic-tac-toe between two players, on an infinite board. Normal rules apply (i.e. three in a row to win), but the players are not limited to a 3X3 board and can choose to place an X or an O in any arbitrary, positive (i, j) position. Solution should be as space and time efficient as possible. Your service is only responsible for maintaining and updating the state of the board between two players, given their sequence of moves.
- DJ April 20, 2013 in United States| Report Duplicate | Flag | PURGE
Microsoft Senior Software Development Engineer Coding - 1of 1 vote
AnswersQ: Do you know what is a Binary tree? How would you go about coding for addition of a new element to Binary tree?
- Aditya April 14, 2013 in United States
A: I asked if they want a Binary Tree or a BST? When he said BST I just said we can have a recursive function in which we pass the root of the tree and see if the value to be added is smaller or bigger than the root, and depending on result, we go to left or right of the tree, assuming the left (or right) is not null. If null, just use new to create a memory location, put the value, and use the left reference of the root to link to this new memory. Simple basic stuff.| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Coding - 4of 4 votes
AnswersI Got this Crazy Question on PHONE INTERVIEW AT GOOGLE:
- hhh April 11, 2013 in United States
Design and implement a class to generate random numbers in an arbitrary probability distribution given by an array of integer weights, i.e. for int[] w return a number, n, from 0 to w.length - 1 with probability w[n] / sum(w). Using an existing random number generator with a uniform distribution is permitted.
Example distribution:
w = 1, 2, 3, 2, 1
Example probabilities:
w / sum = 1/9, 2/9, 1/3, 2/9, 1/9
Example results:
n = 0, 1, 2, 3, 4
Documentation:
Class java.util.Random
public int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All n possible int values are produced with (approximately) equal probability.
Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
the next pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive) from this random number generator's sequence
Throws:
IllegalArgumentException - if n is not positive| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 1of 1 vote
AnswersReverse words in a sentence.
- ami April 09, 2013 in United States
Ex:
Input: "reverse the word"
Output: "word the reverse"| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 0of 0 votes
AnswerHow can you implement queue?
- ami April 09, 2013 in United States
I told him about list, array, stack implementation of queue.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 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 - 0of 0 votes
AnswersSetup:
- bs March 23, 2013 in United States
Assume primitive Facebook. FB has Members.
class Member {
String name;
String email;
List<Member> friends;
}
Question:
Code printSocialGraph(Member m). Direct friends of m are Level 1 friends. Friends of friends are level 2 friends.....and so on
Print level 1 friends first. Then print level 2 friends....and so on
void printfriendsByLevel(Member m){
//Your code here
}| Report Duplicate | Flag | PURGE
Amazon Web Developer Coding - -1of 1 vote
Answerswrite a program to Generating Random Integer numbers without repetition ??
- ranjitha.2705 March 16, 2013 in United States| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersEach time a visitor requests a page from our website, our webserver writes a log entry recoding the visitor's identity and the kind of page requested. Entries are written in chronological order to a plain-text file, with one entry per line. The format of each entry is:
- jimmy514in March 14, 2013 in United States
user-id page-type-id
User IDs are arbitrary strings that uniquely represent a given user; if a user visits multiple pages, each log entry will have the same user ID. Page type IDs are arbitrary strings that uniquely represent a given kind of page on our site, such as the homepage, a product detail pages, or the shopping cart. Tons of users visit our website, but there are only a few dozen types of pages.
We can use our weblogs to answer questions about user behavior. One interesting question is: what is the most common three page sequence through the site? E.g., if the most common pattern is to buy items advertised on the home page of the site, we might see the most common three page sequence as "Homepage -> ProductDetailPage -> ShoppingCart". However, if customers spend a lot of time browsing the "Customers who bought this item also bought" feature, we might see the most common three page sequence as "ProductDetailPage -> ProductDetailPage -> ProductDetailPage".
Attached is a sample log file for your reference. Within the first 10 lines of the sample, customer "234" travels through the sequences "Listmania -> ProductDetail -> Checkout" and "ProductDetail -> Checkout -> HomePage" once each.
For the sake of this test feel free to assume that everything will fit in memory. Do keep in mind that given the size of our data sets, performance has to be considered, also, we will be looking at more than just correct output..| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Coding Java - -10of 12 votes
AnswersInput is a number of words. Construct a listing of valid 6-letter words. You have access to bool IsValid(const string& word); Implement Insert() and Get() for this listing.
- DJ March 09, 2013 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 0 votes
AnswersEscape strings. Convert special ASCII characters to form of ‘\ooo’, where ‘ooo’ is oct digit of the corresponding special character.
- ywdong8809 March 08, 2013 in China
The ascii characters that smaller than space are regarded as special characters.| Report Duplicate | Flag | PURGE
Google Developer Program Engineer Coding - 0of 0 votes
AnswersWrite a program to find the first occurance of one string into another : it is okay to write a O(n2) algorithm
- shubhra.datta March 05, 2013 in United States| Report Duplicate | Flag | PURGE
Intel Software Engineer / Developer Coding - 1of 3 votes
AnswersWrite a program to print the powerset.
- shubhra.datta March 05, 2013 in United States
E.g. given this set {1,2,3}, it will print {},{1},{2},{3},{1,2},{1,3}, {2,3}, {1,2,3}| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 4 votes
AnswersWrite a program to clone a graph
- shubhra.datta March 05, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding