Coding Interview Questions
- 0of 4 votes
AnswersTake an example of the traditional Iterator interface which has the following methods
- lks May 17, 2016 in United States
Interface Iterator<E>{
public boolean hasNext() {}
public E next() {}
public E remove() {}
}
You are given a list of iterators. You have to design a InterleaveIterator class which implements this
interface and implement the methods:
hasNext() and next()
such that these 2 methods returns interleaved values for the list of iterators:
Implement:
class InterleaveIterator<E> implements Iterator<E>{
@override
public boolean hasNext() {}
@override
public E next() {}
}
Example:
ArrayList<Integer> i1 = [1,2,3,4,5].iterator()
List<Node> i2 = [n1,n2].iterator()
Collection<E> i3 = [e1,e2,e3].iterator()
next() method of InterleaveIterator, should return in this sequence [1,n1,e1,2,n2,e3,3,e3,4,5]
Make this InterleaveIterator class generic and make sure that the class can accept a list of iterators
and interleave them| Report Duplicate | Flag | PURGE
Google SDE-2 Coding - 2of 2 votes
AnswersWrite a method to count the number of 2s between 0 and n.*
- xankar May 12, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Developer Coding - 0of 0 votes
AnswersDesign an algorithm to figure out if someone has won in a game of tic-tac-toe.
- xankar May 12, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Developer Coding - 0of 0 votes
AnswerGiven is an algebraic expression involving only positive integers and the operators +
- rahul123jadhaav March 30, 2016 in India
and - . Design a greedy O(n) and dyamnic O(n3) solution.
For example, 5 + 3 − 6 − 7, the maximum possible value of the
expression is 7. One way of achieving this value is by parenthesizing as follows: (5 +
(3 − (6 − 7)))| Report Duplicate | Flag | PURGE
StartUp Intern Coding - 0of 0 votes
AnswersFind a sub string in a given string and replace it with another string?
- sharathvadla March 29, 2016 in India| Report Duplicate | Flag | PURGE
Persistent Systems Software Engineer / Developer Coding - 1of 1 vote
AnswersMaximize the expression value which consists of numbers and +,- operators. Write a program using Greedy approach in linear complexity and Dynamic approach with O(n3) complexity.
- rahul123jadhaav March 26, 2016 in India| Report Duplicate | Flag | PURGE
Morgan Stanley Software Engineer Intern Coding - 9of 9 votes
AnswersGiven a packed file with 1Tb of 64-bit doubles (first 8 bytes are first double, next 8 bytes are next, etc) find the exact value of median. For simplicity assume the number of doubles is odd.
- emb March 19, 2016 in United States
You can't modify the file and you have only 8Gb of free memory.
Update: you may use no more than two passes through file and your algorithm shouldn't rely on some nature of file - it should work in all cases.| Report Duplicate | Flag | PURGE
Google Software Developer Coding - 0of 0 votes
AnswersWrite a program to check if a chess move is valid. The api should be extendible to cover cases like castling and pawn promotion.
- ffish January 25, 2016 in India| Report Duplicate | Flag | PURGE
Flipkart Software Engineer Coding - 0of 0 votes
Answersthere is a chess board of dimension n X n. You are given with 2 squares on that board S(x1,y1) ;M(x2,y2). S is a fixed point. M can move diagonally. it can move any number of steps or jumps in 1 move . Find the minimum number of moves M needs to reach S
- mohapatrasandeep60 January 09, 2016 in India| Report Duplicate | Flag | PURGE
Amazon SDE-2 Coding - 0of 0 votes
AnswersPlease analyze the two slightly obfuscated Tcl procedures below and document the code as it should be. Please change the symbol names to reasonable descriptive names. In addition, an explanation of why these procedures might or might not be useful or suggestions for improvements would be most welcome. This code comes from the application you would be working on. I replaced the names and removed the comments to make the challenge. Feel free to do research and experimentation, but please do not ask anyone else to solve it for you. proc f1 {a} { set n [llength $a] set p {} for {set i 0} {$i < $n} {incr i} { for {set j [expr {$i + 1}]} {$j < $n} {incr j} { lappend p [list [lindex $a $i] [lindex $a $j]] } } return $p }
- raghu.aok December 16, 2015 in Indiaproc f2 {fn lst {vn {}\}} { set result {} lassign $fn a b n if {$n eq {}} { set n {::} } set cl {} foreach n $vn { upvar 1 $n v set cl "${cl}set $n {$v}\n" } set cfn [list $a "${cl}${b}" $n] foreach item $lst { lappend result [apply $cfn $item] } return $result }
| Report Duplicate | Flag | PURGE
SDE-2 Coding - 0of 0 votes
AnswersFind if the characters of the sample string is in the same order in the text string.. Give a simple algo..
- sachin.and3 October 18, 2015 in United States
Eg.. TextString: abcNjhgAhGjhfhAljhRkhgRbhjbevfhO
Sample string :NAGARRO| Report Duplicate | Flag | PURGE
Nagarro Java Developer Algorithm Arrays Brain Storming Brain Teasers Coding Hash Table String Manipulation - 0of 0 votes
AnswersThere is a garden of strawberry plants represented by a 2D, square array.Each plant represents an element in the matrix ie it has a number of strawberries. If a plant doesnt have strawberries it is denoted by 0. If 0 is encountered you cannot travel through that path.
- topCoder September 27, 2015 in United States
You can start from any cell along the left border of this ground (i.e the matrix) and travel until it finally stops at one cell in the right border, and you can only move to up/down/right. You can only visit each cell once. Calculate the maximum number of berries is obtained.
Backtracking using Dynamic programming is one of the methods i have thought of.
Also there some special conditions:
a.Even in the left border and right border, we can go up and down.
b. When we are at the top cell of one column, we can still go up, which demands us to
pay all current strawberries , then we will be teleported to the bottom cell of this column and vice
versa.
Input: user enters dimensions of ground ie size of matrix and the matrix itself
Output: is the maximum number of strawberries collected without encountering 0; in case we do we display 0.
Till now i have managed to find the largest value in the first column of the matrix but i am facing difficulty in testing the neighbours of that cell.
Also i am not able to store the position of the cell which i started from or even mark it.
Input
4 4
-1 4 5 1
2 -1 2 4
3 3 -1 3
4 2 1 2
output
23
Input
4 4
-1 4 5 1
2 -1 2 4
3 3 -1 -1
4 2 1 2
output
22| Report Duplicate | Flag | PURGE
Walmart Labs Algorithm C++ Coding Dynamic Programming - 0of 0 votes
AnswersCreate a function Demo that takes input a function f and a parameter k, and returns a function that behaves the same as f except it caches the last k distinct accessed results of f.
- cv September 23, 2015 in India
Demo_f = Demo(f,2)
demo_f(arg1) - computed and cached
demo_f(arg1)- returned from cache
demo_f(arg2) - computed and cached
demo_f(arg3) - computed and cached, f(agr1) is evicted
I think its related to python decorators. Some one can give a hint how can I get started with this| Report Duplicate | Flag | PURGE
StartUp Data Scientist Coding - 2of 2 votes
AnswersEvaluate the value of an expression given in Reverse Polish notation
- varun.venu September 22, 2015 in United States| Report Duplicate | Flag | PURGE
Linkedin Senior Software Development Engineer Coding - 1of 1 vote
AnswersThis question was asked in the first coding round on-site.
- varun.venu September 22, 2015 in United States
Give two sorted lists List<Integer> a and List<Integer> b.
Find
the Union of these two lists -> the union list should also be sorted
the Intersection of these two lists -> Intersection list should also be sorted.| Report Duplicate | Flag | PURGE
Linkedin Senior Software Development Engineer Coding - 1of 1 vote
AnswersThose who've attended on-site interview with LinkedIn might know that there are 2 rounds of coding interviews. This question was asked in my 2nd round of coding interview,
- varun.venu September 22, 2015 in United States
Given two valid dictionary words of same length, write a function which returns the minimum number of steps to go from the first to the second word.
You can change only one character at a time. Also, the word formed at every step should be a valid dictionary word.
Eg: Provide minimum steps to go from 'cat' to 'dog'
cat -> bat -> bet -> bot -> bog -> dog
Ans: 5| Report Duplicate | Flag | PURGE
Linkedin Senior Software Development Engineer Coding - 0of 0 votes
AnswersGiven two numbers L and R, find the highest occurring digit in the prime numbers present between L and R (both inclusive). If multiple digits have the same highest frequency print the largest of them. If there are no prime no.s between L and R, print -1.
- ps.sarath21 July 18, 2015 in India| Report Duplicate | Flag | PURGE
Coding - 2of 2 votes
AnswersRound 6
- sonesh July 12, 2015 in United States
Question 3 : You are given a word document, you have to print the words with frequencies. Now print the kth rank word in terms of frequency. Print top k words as well by frequencies| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Arrays Coding Sorting - 0of 0 votes
AnswersRound 2
- sonesh July 12, 2015 in United States
Question 3 : You have to implement an external iterator which iterate the binary tree InOrder. You have to figure out what kind of iterator one should use, and implement each of those function. required complexity is O(N) time + O(log(N)) space| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding Data Structures Trees and Graphs - 0of 0 votes
AnswersYou are given a large array of 10,000,000 bits. Each bit is initially 0. You perform several operations of the type "Flip all the bits between start_index and end_index, inclusive". Given a sequence of several such operations, perform all the operations on the array. Finally, split the array into sets of 4 bits - first four, next four, then next four and so on. Each set can represent a hexadecimal integer. There will be exactly 2,500,000 hexadecimal integers. Calculate the frequency of each of the hexadecimal integers from '0' to 'f' among the 2,500,000 integers, and print it. See Input / Output and explanation of Sample Input / Output for clarity.
- Rahul Sharma July 12, 2015 in India
Input
The first line of input contains an integer T (1 ≤ T ≤ 10), the number of test cases. Then follows the description of T test cases. You should assume that the array has exactly 10,000,000 bits and that the bits are all unset at the start of each test case. The first line of each test case contains an integer N (1 ≤ N ≤ 10,000), the number of operations performed. The next N lines contain two integers separated by a space, the start_index and end_index for the respective operation. Note that the flip operation is performed from start_index to end_index, inclusive. Also, the array is 1-indexed - meaning, the smallest index is 1 and the largest index is 10,000,000.
Output
For each test case, output 16 integers on a single line, separated by single space characters. The first integer should represent the number of times 0 occurs among the 2,500,000 hexadecimal integers created according to the problem statement. The second integer should represent the number of times 1 occurs among the 2,500,000 hexadecimal integers created according to the problem statement, and so on.
Constraints
1 ≤ start_index ≤ end_index
start_index ≤ end_index ≤ 10,000,000
Sample Input
2
2
1 4
9999997 10000000
2
3 6
5 8
Sample Output
2499998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2
2499998 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0
Explanation
In the first test case, after we perform the two operations and split the array into 2,500,000 groups of 4 bits, the first and the last group will have all 4 bits set - representing 'f' hexadecimal digit. All the other groups will have all 4 bits unset - representing '0' hexadecimal digit.
In the second test case, after we perform the two operations and split the array into 2,500,000 groups of 4 bits, the first two groups will have the state 0011. This represents the hexadecimal digit '3'. All the other groups will have all the 4 bits unset - representing '0' hexadecimal digit.| Report Duplicate | Flag | PURGE
Directi SDE-2 Coding - 0of 0 votes
AnswersDescribe the different ways to determine if an integer is a power of 2.
- Yev July 10, 2015 in United States
He was looking for a solution other than dividing by 2.
I suggested initially log2X. They said it has some rounding issues in certain environments. I continued to doing bitwise arithmetic.| Report Duplicate | Flag | PURGE
Vail Systems Software Engineer / Developer Coding - 0of 0 votes
AnswersRound 3
Question 1, you are given a puzzle, You can check the image herehttps://drive.google.com/file/d/0B6-TjTC-KfTqQThBamxPa0NwNGM/view?usp=sharing
You have to write a program to provide a solution for this.
- sonesh July 02, 2015 in United States| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Coding Data Structures Puzzle - 0of 0 votes
AnswersRound 2
- sonesh July 02, 2015 in United States
Question 1: Design a traffic signalling system for a city.
1.a : think as you were asked this question in a high level meeting with leadership teams, what would you do at that time ?
1.b : what are the check-list/to-do you will do before start of your project.
1.c : how will you go over each and every check-list/to-do
1.d : Once you have done all this, what are the design principle you will follow.
1.e : what kind of system you would choose(I gave distributed/centralized)
1.f : Tell me the pros and cons of these type which you have listed
1.g : how do you go over your goal.
1.h : how will you make the cons go away from one system which out changing it to another type(like possible modification).
1.i : How will to achieve your goal which was given to you by LT team.
1.f : Now lets write the code for a road intersection, make it generic enough both in terms of colors, and ordering, so what it can be used anywhere.
Note that : a road intersection may have many traffic lights one for each side of the roads| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Coding Data Structures Software Design System Design - 1of 1 vote
AnswersDesign a cache module for an image server. The server accepts image requests from users and sends them back the images. The cache should always hold in-memory the 10 most recently requested images. The cache should also support multiple requests simultaneously
- assaf.keret1 June 28, 2015 in Switzerland| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Coding - 0of 0 votes
AnswersTech Screening round
- sonesh June 25, 2015 in United States
Q.1 : a non decreasing sorted array is rotated by some random amount, write a routine to figure out this random amount.you can consider the clockwise rotation.
Write the test cases for it.
Interviewer wanted to see prod ready code.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm Arrays Coding - 0of 0 votes
AnswersWhat's the use of concurrency list in java? What are various locking mechanism in java?
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Coding Threads - 0of 0 votes
Answerswhat's use of equals and hashcode function?
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Ebay Software Developer Coding Hash Table Java Object Oriented Design - 0of 0 votes
Answershashmap implementation?
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Ebay Software Developer Algorithm Coding Hash Table Java - -1of 1 vote
Answervector vs arraylist
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Ebay Software Developer Coding Java Object Oriented Design - 0of 0 votes
Answerhashtable vs hashmap
- Tom Walker June 07, 2015 in United States| Report Duplicate | Flag | PURGE
Ebay Software Developer Coding Hash Table Java