Coding Interview Questions
- 2of 2 votes
AnswersYou are trying to control an on-screen keyboard (e.g. on a television) that looks like this:
- msamarch1980 March 20, 2014 in United States
a b c d e
f g h i j
...
You can issue the following commands to move the cursor and select letters:
‘u’ - up
‘d’ - down
‘l’ - left
‘r’ - right
‘!’ - select letter
You are given an input string and the length of the rows in the on-screen keyboard. You must produce the sequence of commands needed to type out the input string on the specified keyboard, e.g.:
“aci”, 5 -> “!rr!dr!”| Report Duplicate | Flag | PURGE
Software Engineer / Developer Coding - 0of 0 votes
AnswersWrite a function accepting a string with numbers and letters that reverses the letters of the string but leave numbers in the same position.
- radiohalo5 March 19, 2014 in United States
Example input: str1ngw1thnumb3rs
Example output: srb1mun1htwgn3rts| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersUnderstand the Elevator_Operations class definition below and expand the solution:
- mandalikasudhakar March 09, 2014 in India
class Elevator_Operations
{
private:
int number_of_persons;
public:
virtual void move_up() = 0;
virtual void move_down()= 0;
virtual void next_stop() =0;
void set_max_persons(int number_of_persons);
void set_max_weight(float weight_in_kilograms);
int get_current_floor();
int get_next_destination_floor();
virtual void overload_alert(int currentLoad)=0;
};
1) Program must be customizable for different buildings having varying number of floors
2) Method to set the maximum weight and number of persons an elevator can support
3) Method to display alert message when elevator is overloaded, along with the current load
4) At any part of the program current floor and next destination floor details must be made available
5) Code to control the movement of the elevator should be defined only in child class as the working
mechanism varies based on the usage.eg: elevator moves to the very next floor up/down or moves to the
floor which was chosen by the first user, then the next user etc
6) Once destination is reached write a code to open the door; similarly, to close the door after the user
decides
destination floor| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersProgram to check whether undirected graph is a tree or not?
- pavan February 27, 2014 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 1of 1 vote
AnswersGiven a number in an array form, Come up with an algorithm to push all the zeros to the end.
- kiranpm86 February 24, 2014 in India
Expectation : O(n) solution| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Algorithm Arrays C++ Coding - -1of 1 vote
AnswersGive 2 arrays of size 7 and 3 which are sorted such that the last 3 blocks in first array are empty, merge the arrays in a sorted manner in the most efficient way.
- kiranpm86 February 24, 2014 in India
E.g:-
a[7] = [4, 10, 11, 20__, __, __]
b[3] = [1,3,7]| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Algorithm Arrays C++ Coding - 1of 1 vote
AnswersIn Amazon's interview, Round 2 they asked question:
Write a program to print inorder traversal of two trees.
Both values must be printed alternatively.
e.g. if inorder traversal of tree 1 is 10, 15, 20 and tree 2 is 100, 150, 200 then it should print
10, 100, 15, 150, 20, 200.
I tried printing it recursively by calling 2 functions recursively (f1 calls f2, then f2 calls f1 and so on).
I don't know where my approach is going wrong? I know there are other ways to do it as well but in this approach what is the mistake?
- tihor February 22, 2014 in Indiapublic class HelloWorld{ //this is the Node used in the tree static class Node{ private int data; private Node left; private Node right; public Node(int data){ this.data = data; left = null; right = null; } public void setLeft(Node left){ this.left = left; } public void setRight(Node right){ this.right = right; } public Node getLeft(){ return this.left; } public Node getRight(){ return this.right; } public int getData(){ return this.data; } public boolean equals(Node n){ if(this.data ==(int) n.getData()) return true; else return false; } } public static void main(String[] args){ HelloWorld bts = new HelloWorld(); bts.run(); } //execute the test case public void run(){ Node root = new Node(10); insert(root,new Node(20)); insert(root,new Node(50)); insert(root,new Node(40)); insert(root,new Node(15)); Node node2 = new Node(100); insert(node2,new Node(200)); insert(node2,new Node(500)); insert(node2,new Node(400)); insert(node2,new Node(150)); //inOrderTraverse(node2); inOrderTraverse1(root, node2); } // insert a node to the binary search tree public void insert(Node root, Node n){ if(root == null|| n == null) return; if(root.getData() > n.getData()){ if(root.getLeft() == null){ root.setLeft(n); }else{ insert(root.getLeft(),n); } }else if(root.getData() < n.getData()){ if(root.getRight() == null){ root.setRight(n); }else{ insert(root.getRight(),n); } } } public void inOrderTraverse(Node node){ if(node != null){ if(node.getLeft() != null) inOrderTraverse(node.getLeft()); System.out.print(" "+node.getData()); if(node.getRight() != null) inOrderTraverse(node.getRight()); } } //in-order Traversal public void inOrderTraverse1(Node node1, Node node2){ if(node2 != null){ inOrderTraverse2(node1, node2.getLeft()); System.out.println(" "+node2.getData()); inOrderTraverse2(node1, node2.getRight()); } } public void inOrderTraverse2(Node node1, Node node2){ if(node1 != null ){ inOrderTraverse1(node1.getLeft(), node2); System.out.println(" "+node1.getData()); inOrderTraverse1(node1.getRight(), node2); } }
| Report Duplicate | Flag | PURGE
Amazon Member Technical Staff Coding - 0of 0 votes
Answerspublic interface Permutations {
- Anon February 19, 2014 in United States
/**
* Generate all permutations of given sequence of elements.
* Return a list of all distinct permutations.
*
* E.g.
* generate([1, 2, 3]) -> [1, 2, 3], [1, 3, 2], [2, 3, 1], [2, 1, 3], [3, 1, 2], [3, 2, 1]
*/
vector<vector<int>> generate(vector<int> items);
}| Report Duplicate | Flag | PURGE
Linkedin Software Engineer / Developer Coding - -1of 1 vote
AnswersThere is a string , where a character is missing.Print the missing character.The range is present in the string and the characters are case sensitive.
- write2bikash February 19, 2014 in India
For example:-If input is "baADfc".
Here the range is a to f.
The missing character to be printed is e.
.| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Coding - -1of 1 vote
Answersfind whether a number is palindrome or not if number is not palindrome ( i.e 112 ) make it in a palindrome form and check if it is palindrome or not.
- napender February 12, 2014 in India
Example - 121 this is a palindrome number but 112 is not palindrome so make it 121 and check.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 1of 1 vote
AnswersQuestion 2 / 2 (Weighted Stone Arrangement)
- kri1311 February 09, 2014 in India
You are given an infinite number of stones.
The 1st stone has the weight 1
The 2nd stone has the weight 3
The tth stone has the weight W(t) = 2 * W(t-1) + W(t-2)
Thus, the weights of the first 10 stones are
1, 3, 7, 17, 41, 99, 239, 577, 1393, 3363
Note that you only have one stone of each weight.
You have a weighing machine which is the age old 2-pan balance. You wish to use this machine to measure the weight of an item whose weight is T. The item will always be kept on the right pan. A stone may be kept on either one of the pans. Also, it is not required to use all the stones.
The stones have a weird magnetic property, due to which, the kth stone cannot be in the same pan as the (k-1)th stone. This means that the stone with weight 239 cannot be in the same pan as the stone with weight 99, or in the same pan as the stone with weight 577; and so on.
For example,
T = 11 can be measured as
LEFT PAN: 1, 17
RIGHT PAN: 7
Note that the other alternative
LEFT PAN: 1, 3, 7
RIGHT PAN:
is Illegal since 3 cannot be in the same pan as 1 (or 7 cannot be in the same pan as 3).
T = 21 can be measured as
LEFT PAN: 41
RIGHT PAN: 3, 17
It can be proven that to measure any weight T, there exists a unique arrangement of stones that satisfy the given constraints and measure weight T. Thus, T = 11 or T = 21 can only be measured by the respective arrangements above.
You are given T in the input. Output the arrangement of stones that measures T.
Input Specification
The input contains a single positive integer T.
Output Specification
Output the weights of the stones used on the left pan in increasing order, one number per line. Then output a blank line. Followed by the weights of the stones used on the right pan in increasing order. Note that it is assumed that the item will be kept on the right pan.
If there is no stone kept on the right pan, simply output the weights of the stones used on the left pan in increasing order as above, followed by a blank line.
Constraints
1 ≤ T ≤ 1015
Sample Input 1
11
Sample Output 1
1
17
7
Sample Input 2
21
Sample Output 2
41
3
17
Sample Input 3
1000
Sample Output 3
3
41
239
1393
99
577| Report Duplicate | Flag | PURGE
Directi Software Engineer / Developer Coding - 0of 0 votes
AnswerDirecti Off Campus Interview Process 2013-14
- kri1311 February 09, 2014 in India
.......................................................................
This is year 4096 and humans have found a medicine for immortality in the year 2048. Tukro a famous online social networking site founded in the year 3072 was celebrating its 1024th anniversary. To celebrate the occasion its CEO, Shark, and his team had launched a unique personalised video of length 17min 4sec for each user. The video consisted of a collage of all popular posts made by the user on Tukro.
Raka shared this video with all his friends without reviewing it. Immediately after he finished watching the 1024 second length clip he realised that he made a huge mistake. The video was made of all posts made by Raka, irrespective of the privacy settings of the individual post.
A post is compromised if a friend who was not supposed to see the original post, has seen it now. Raka wants to know how many of his posts have been compromised. Tukro provides the list of users who have watched the video till now. Help Raka find how many posts were compromised.
Raka has N friends, identified by a unique integer between 0 and N-1.
Raka has L lists of friends, identified by a unique integer between 0 and L-1.
Each list can be of length at the most N.
One friend cannot be added more than once to the same list.
A list must have at least one friend.
A friend may be added to multiple lists.
Visibility of a post in Tukro works through two filters
Include Filter: An array of lists, from the L lists above. Friends can view a post if they belong to any friend list, specified in the Include Filter.
Exclude Filter: An array of lists, from the L lists above. Friends can view a post if their name does not belong to any friend list, specified in the Exclude Filter.
Some caveats of the above are
If no Filter is active, the post is visible to all friends
If only Include Filter is active, a friend can see the post only if he is present in at least one of the lists of Include Filter.
If only Exclude Filter is active, a friend can see the post only if he is not present in any of the lists of exclude filter.
If both Include and Exclude Filters are active, a friend can see the post if and only if
he is present in at least one of the lists of include filter and
he is not present in any of the lists of exclude filter
if he is present in both an include filter list, and exclude filter list, he should not be able to see the post
Input Specification
First line contains a single integer N, the number of friends.
Second line contains a list of integers separated by a single space. The first integer V, represents the number of friends who viewed the video. There are V other integers in the line representing the ID's of friends who viewed the video.
Third line contains a single integer L representing the number of lists.
L lines follow. Each line representing a list. The first integer of the line A, denotes the size of the list; followed by A integers, each denoting the friends in the list.
Next line contains a single integer P denoting the number of posts in the video. 2 * P lines follow. Each pair denoting the Include Filter and Exclude Filters of one post respectively.
First two lines denote the Include and Exclude Filters for first post
Next two lines denote the Include and Exclude Filters of second post
and so on..
An include filter is represented by a list of space separated integers. The first integer B represents the number of lists in the filter. B may be 0, to denote that the include filter is not active. If B is more than 0, the include filter is active and the next B integers in the line denote the ID's of lists present in the include filter.
Exclude filters are also represented in the same format.
Output Specification
Print a single integer specifying the number of posts that are compromised according to the definition above.
Constraints
1 ≤ N ≤ 10000
1 ≤ V ≤ N
1 ≤ L ≤ 6
1 ≤ P ≤ 100000
Note that the constraints on N and P are large.
Your solution will exceed time limits if its complexity is O(N*P).
Even O(V*P) solutions may exceed time limit!
Note the small constraint on L.
Sample Input 1
10
8 1 2 5 6 0 9 8 7
4
2 4 3
2 7 6
3 0 1 5
3 2 8 9
4
0
1 0
1 1
0
0
0
3 1 2 3
0
Sample Output 1
1
Explanation
There are 10 friends. Their ID's are from 0 to 9
8 of them viewed the video = {0,1,2,5,6,7,8,9}
There are 4 lists
List-0 has 2 friends {3,4}
List-1 has 1 friend {7,6}
List-2 has 3 friends {0,1,5}
List-3 has 3 friends {2,8,9}
There are 4 posts
Post-0 doesn't have any include filter but has List-0 - {3,4} - in exclude filter
3, or 4, have not seen the video
Hence Post-0 is not compromised
Post-1 has an include filter of List-1 - {7,6} - and no exclude filter.
But other friends have seen the video
Hence Post-1 is compromised
Post-2 doesn't have any filters. Such a post was intended to be seen by anyone.
Hence Post-2 is not compromised.
Post-3 has a include filter of List-1, List-2 and List-3.
Their union is {0,1,2,5,6,7,8,9}
These are the exact friends who saw the video
Hence Post-3 is not compromised
Hence only 1 post is compromised.
Sample Input 2
5
2 2 3
5
1 0
1 1
1 2
1 3
1 4
4
3 2 3 4
1 0
3 1 2 3
0
3 0 1 3
0
3 2 3 4
1 0
Sample Output 2
1| Report Duplicate | Flag | PURGE
Directi Software Engineer / Developer Coding - 0of 0 votes
AnswersShow whether two integer ranges are overlapping or not. If so, return the overlap range
- mpss.umbc January 29, 2014 in United States for Android| Report Duplicate | Flag | PURGE
Samsung Software Engineer Intern Coding - 0of 0 votes
AnswersWrite a prog in any language you are comfortable, which takes 2 strings as an input and then finds the first occurrence of the first string in the second string. The function should return the index in the second string where the match was found.
- Jey January 24, 2014 in India
Tip : The basic algorithm here is to iterate through the second string and when the char matches the first char in the 1st string., check if subsequent substring is a match, and return if it is.| Report Duplicate | Flag | PURGE
Amazon Technical Support Engineer Coding - 0of 0 votes
AnswerGiven a binary tree, link every node's sibling pointer to its next sibling on the same level so these sibling pointers consist a single linked list on each level. Requirement: use O(1) space.
- jiangok2006 January 24, 2014 in United States| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersYou need to write this program again, without using any library methods. Take the following inputs from user and print the following output.
- pal January 22, 2014 in India
1 1
1 11
0 011
1 0111
0 00111
0 000111
0 0000111
i.e if user types 1 then 1 will be at printed right shift, and 0 will be printed left shift.
Note: There is no definite count of number of Inputs user wants to give, or sequence of inputs user wants to give. User can give any number of inputs, and it should display the result as above.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersYou have got 2 strings(S1, S2) and 1 character(c1). All inputs to be taken from user. You need to check for the character c1 in String S1, and wherever you find the character, you need to replace it with the string S2.
- pal January 22, 2014 in India
Next Write all possible test cases to test the program.
It can be possible that the character c1 is appearing more than once in the String s1.
Clause - You are not allowed to use any Java Library methods in it. Not even charAt() method.| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersFirst find out the number 1's in the binary digit of a given integer. Then find out an integer which is greater than the given integer and contains same number of binary 1's
- Arunkumar V January 21, 2014 in India| Report Duplicate | Flag | PURGE
Software Engineer in Test C Coding - 1of 1 vote
Answers
- Srigopal Chitrapu January 15, 2014 in United StatesIn given array find zero and replace the entire row and column with zeros E.g Input: 1 2 3 4 5 6 7 8 9 10 0 11 12 13 14 15 Output: 1 2 0 4 5 6 0 8 0 0 0 0 12 13 0 15
| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Arrays Coding Matrix - 0of 0 votes
AnswersGiven an array of integers and the target as an input E.g.
- AA January 11, 2014 in United States
input = {5,2,1,4,3,6,7,8} .. target : 333 it should true as (5 +214 + 36 + 78) if the target does not match it should return false.... Eg. of false input : {5,5} target:60 ... It should return false as the combinations possible are 5+5 = 10 and 55| Report Duplicate | Flag | PURGE
A9 Software Engineer / Developer Coding - 0of 0 votes
Answerswrite Fibonacci series with recursion.
- contacttovimal January 11, 2014 in India for Risk Management/CMOT| Report Duplicate | Flag | PURGE
Citigroup Java Developer Coding - -1of 1 vote
Answershow you will design directory so your search will faster, provide solution so my search time is efficient.
- contacttovimal January 11, 2014 in India for Risk Management/CMOT| Report Duplicate | Flag | PURGE
Citigroup Java Developer Coding - -2of 2 votes
Answersclass NoName { children = new Hashtable() name = "" boolean hasChild(child: string) { return this.children.hasKey(child) } NoName addChild(child: string) { var childnode = new NoName() childnode.name = child this.children[child] = childnode return childnode } NoName getNode(child: string) { if this.hasChild(child) return this.children[child] else return this.addChild(child) } void addList(input: string) { var currentNode = this.getNode(input[0]) input = input.SubString(1, input.Length ? 1) if (input.Length < 1) currentNode.getNode("") else currentNode.addList(input) } string scan() { if (this.children.Values.Length == 0) return this.name if (this.children.Values.Length == 1) return this.name + this.children.Values[0].scan() var temp = new Array() foreach(child in this.children.Values) temp.Add(child.scan()) return this.name + "{" + temp.Sorted().JoinArray(",") + "}" } } var x = new NoName() x.addList(’/home/user/foo’) x.addList(’/home/user/bar’) x.addList(’/home/user/baz/one’) x.addList(’/home/user/baz/two’) print x.scan()
Is there anyone can help me translate these code to java or tell me the result ,I will really appreciate it.Thanks
- miller9977 January 10, 2014 in United States| Report Duplicate | Flag | PURGE
Hewlett Packard Java Developer Coding - -1of 1 vote
AnswersWrite a business_days_from_now() method, which takes as an input a number of business days, and returns a Date object which is that many business days from now. For this, a business day is only a weekday and not a weekend.
- prabhashrathore January 09, 2014 in United States
for example:
Today is Wednesday the 8th.
business_days_from_now(5)
Current Date: Jan 8, 2013 Wednesday
Output:
Wednesday the 15th| Report Duplicate | Flag | PURGE
Netflix Senior Software Development Engineer Coding - 0of 0 votes
Answers//Online Coding Assignment
As a member of the cab finder app team, you are tasked with implementing a CabFinder class that has the following minimal public interface:class CabFinder implements CabStatusListener { /** * Initiates CabFinder. Called only once per app startup. * @app An application object providing services implemented by * the rest of the application. * @maxCabs Nearest number of cabs that can be returned to the user */ public void initialize(CabApp app, int maxCabs) { //Insert code here... } /** * Gets nearest cabs within 1km of the current user’s location. * These must be the *nearest possible* @maxCabs in the 1km area. * @return An unordered list of the nearest cabs. */ public Cab[] getNearestCabs() { //Insert code here... } /** * Asynchronous Callback per CabStatusListener (see below). Called when the position of a cab has changed. */ void onCabPositionChanged(Cab cab) { //Insert code here… } /** * Asynchronous Callback per CabStatusListener (see below). Called when a cab’s availability changes. * @cab The cab whose availability has changed * @isAvailable true if the cab is now available, false otherwise */ void onCabAvailabilityChanged (Cab cab, boolean isAvailable) { //Insert code here… } }
Supporting Classes:
Here are the classes and utilities that are available for your use (you are not required to write any implementation for these classes)
/**
* Coordinates on a 2D map with a one meter granularity.
*/class Position { public int x; public int y; } interface Cab { /** * Unique identifier of a cab. */ int getID(); /** * Gets the current position of the cab */ Position getCabPosition(); /** * Returns whether or not the cab is available */ boolean isAvailable(); }
/**
- chandeepsingh85 January 08, 2014 in United States
* Provides services implemented by the rest of the Cab Application.
*/
interface CabApp {
/**
* Gets the current location of the user
*/
Position getUserPosition();
/**
* Returns an iterator that gives access to the list of all cabs in the city
*/
Iterator<Cab> getCabs();
/**
* Registers a CabStatusListener object for change notifications of cab object data.
*/
void register(CabStatusListener listener);
}
/**
* The CabStatusListener interface
*/
interface CabStatusListener {
/**
* Called when the position of a cab has changed.
* @cab The cab object
*/
void onCabPositionChanged(Cab cab);
/**
* Called when a cab’s availability changes.
* @cab The cab object
* @isAvailable true if the cab is available, false otherwise
*
*/
void onCabAvailabilityChanged (Cab cab, boolean isAvailable);
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 7of 7 votes
AnswersYou need to develop the game Snake. What data structures will you use? Code your solution.
- GeorgyBoy December 30, 2013 in Israel| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Coding Java Problem Solving - 2of 4 votes
AnswersGiven a sorted array of integers, write a function that will return the number with the biggest number of repetitions.
- GeorgyBoy December 30, 2013 in Israel
(Asked to refine the solution to be more efficient)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Arrays Coding Data Structures Problem Solving Sorting - 3of 3 votes
AnswersGiven a board made of 2 x n squares, and boards made of 2 x 1 squares, write a function that will calculate the number of possible ways to arrange the 2 x 1 boards on the 2 x n board, in a way that will fill it completely.
- GeorgyBoy December 30, 2013 in Israel
(Asked to refine the solution to be more efficient)| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Coding Problem Solving - 0of 0 votes
AnswersYou are given two arrays, how to you find the common elements in them?
- rchala December 14, 2013 in United States
My answer: Make a hashmap for one array with the entries as keys and their presence (0 or 1) as values. Then run through the elements of the other array to see which elements match.
Complexity: O(m+n) where m and n are the lengths of each array.| Report Duplicate | Flag | PURGE
Amazon Research Scientist Coding