Algorithm Interview Questions
- 1of 1 vote
Answers
- sakshisharma April 03, 2015 in United Statespublic interface Triangle { /** * Three segments of lengths A, B, C form a triangle iff * * A + B > C * B + C > A * A + C > B * * e.g. * 6, 4, 5 can form a triangle * 10, 2, 7 can't * * Given a list of segments lengths algorithm should find at least one triplet of segments that form a triangle (if any). * * Method should return an array of either: * - 3 elements: segments that form a triangle (i.e. satisfy the condition above) * - empty array if there are no such segments */ int[] getTriangleSides(int[] segments); }
| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm - 1of 1 vote
AnswersThey conducted a hiring round and this was asked there ?
- Rahul Sharma August 30, 2014 in India
Hi friends This question was asked in recent hiring challenge at hackerearth , that is over now,Please discuss your strategies.I am not able to devise algorithm please provide some hints to solve it.
Pulkit is really good at maths. Recently, he came to know about a problem on matrices. Amazed by the problem he got, he asked Ashish the same problem. Ashish also being good at maths solved the problem within 5 minutes. Now, its your time to solve the problem.
You will be given n*m binary matrix. You need to tell if it is possible to delete a column such that after deleting that column, rows of the matrix will be unique. If yes than print "Yes" else print "No".
[Input]
First line contains an integer t denoting no.of test cases.
Next line contains 2 integers n and m denoting no.of rows and columns.
Next n line contains binary string of length m each.
[Output]
For each test case output "Yes" or "No".
[Constraints]
1<=t<=100
1<=n<=1000
2<=m<=1000
Sample Input (Plaintext Link)
2
3 3
101
000
100
2 2
11
11
Sample Output (Plaintext Link)
Yes
No| Report Duplicate | Flag | PURGE
Manhattan associates SDE-2 Algorithm - 1of 1 vote
AnswersWrite a method that takes a binary tree and return whether the tree is sorted.
- yu_stfx@hotmail.com July 30, 2014 in Canada| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 1of 1 vote
AnswersYou are given an array / sequence of colors. In this sequence / array, find a couple (both colors adjacent to each other) which are same color. Now, remove that pair. Now, after this removal, if there are further couple of same color then remove that as well and so on.
For a given array / sequence of colors, find the maximum number of couples.
- nilukush January 13, 2014 in IndiaFor eg., consider following array of colors : R G B B G R Y 1. BB is one couple, so remove it : R G G R Y 2. GG is one such couple after removing BB, so remove it : R R Y 3. RR is one such couple, so remove it : Y So, the maximum number of couples is 3. Input : Y R G G R R G G R Y Output : 5 (maximum number of couples)
| Report Duplicate | Flag | PURGE
Groupon Senior Software Development Engineer Algorithm - 1of 1 vote
AnswersThere is a server when a user can login.
- SK June 09, 2013 in India
A used can login multiple times.
you have to return number of unique users in last 10 minutes.
Retrieve unique user count operation should be as fast as possible.
Note:
A user who has done login in last 10 minutes more than once should be counted only 1.
It is possible that in a particular duration no user has logged in.| Report Duplicate | Flag | PURGE
Amazon Senior Software Development Engineer Algorithm - 1of 1 vote
AnswersGiven a BST, maximum and minimum value, find the sum of nodes with values between the above range
- bicepjai September 25, 2012 in United States for Google Engineering| Report Duplicate | Flag | PURGE
Google Site Reliability Engineer Algorithm - 1of 1 vote
AnswersThere is a sequence of increasing numbers that have the same number of
- gullu September 12, 2010
binary 1s in them. Given n, the number of 1 bits set in each number, write an algorithm
or C program to find the n’th number in the series| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Algorithm - 1of 1 vote
AnswersFind median of two sorted arrays.
- binu May 28, 2010| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm Arrays - 1of 1 vote
AnswersThere is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers. The odd numbers are to be sorted in descending order and the even numbers in ascending order. You are not allowed to use any extra array and it has to use a conventional sorting mechanism and should not do any pre or post processing.
- Anonymous January 17, 2010| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
AnswersThis problem is called Maximum contiguous sub sequence sum problem. I have been asked this question more than once at different interviews at Microsoft.
Given an array which can contain both positive and negative numbers, find the maximum contiguous sub sequence sum.
For example in an array = {2, -3, 4, -5, 6, -3, 8}, it should return 11.
Here was my solution.
- Daniel Johnson February 07, 2009maxsofar = 0 maxendinghere = 0 for i = [0, n) /* invariant: maxendinghere and maxsofar are accurate are accurate for x[0..i-1] */ maxendinghere = max(maxendinghere + x[i], 0) maxsofar = max(maxsofar, maxendinghere)
| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Algorithm - 1of 1 vote
AnswersAdd two numbers represented as LinkedList (not LeetCode 445 which uses ListNode)
- KelvinLong8897 November 17, 2018 in United States
e.g
inputs: '5'->'6'->'3'
'8'->'4'->'2'
output: '1'->'4'->'0'->'5'
method signature:
LinkedList<Integer> sumList(LinkedList<Integer> l1, LinkedList<Integer> l2)| Report Duplicate | Flag | PURGE
Facebook Android Engineer Algorithm - 1of 1 vote
AnswersGiven a string where in each word letters were randomly shuffled and after that words were written without spaces (lets call it X). Also you have a dictionary. The task is to return all possible strings S that can be transformed into the string X and all words in S are from dictionary.
- golyjivan February 19, 2016 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersWrite a function that takes a string as an input and outputs an integer, e.g. turning "1234" into 1234.
- forstupidshit150 April 20, 2015 in United States for Cloud+Enterprise| Report Duplicate | Flag | PURGE
Microsoft Software Engineer Algorithm - 1of 1 vote
Answers
- Phoenix November 22, 2014 in United KingdomThere are multiple rooms in a floor. There are one or more fire exits. Each door can be designed with an option of pull or push. For fire safety, a door should be designed so as to open (push) towards the fire exit. Design a data structure to represent the floor and door design. A person could start from any room and moves towards fire exit. Write an algorithm to check if all the doors are designed to be pushed towards fire exit.
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersTraveler wants to travel from city “A” to city “D”.
There is a path from city “A” to city “D”.
Path consists of steps, i.e. travel from city “A” to city “B”.
Path is encoded as sequence of steps.
Sequence is in incorrect order.
Your task is to restore order of steps in the path.
Input (unordered sequence):
C -> D
A -> B
B -> C
Output (Correctly ordered list which represents path):
A, B, C, D
Implement following API:
- abc June 20, 2014 in Indiaclass Step { String start; String finish; }; class Node { String value; Node next; } List<String> findPath(List<Step> steps) { }
| Report Duplicate | Flag | PURGE
Google Applications Developer Algorithm - 1of 1 vote
AnswersWrite a program to evaluate arithmetic/math expression
- focus March 25, 2014 in United States
"12 + 5*4 + 26" = 58
"5 * 4" = 20
"6 + 4" = 10
"12" = 12| Report Duplicate | Flag | PURGE
Amazon Algorithm - 1of 1 vote
AnswersWrite a method to print output of a^b
- careerCupguy10 January 25, 2014 in United States| Report Duplicate | Flag | PURGE
PayPal Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven 78 cents (target) you need to tell how many ways it is possible to make the change using 25 cents(quarter), 10 cents(nickel), 5cents(dime), 1cents(penny)
- juny December 12, 2013 in United States for Traffic| Report Duplicate | Flag | PURGE
Ebay SDE-2 Algorithm - 1of 1 vote
AnswersFind numbers which are palindromic in both their decimal and octal representations
- geekofthegeeks November 01, 2013 in India| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven N integer array, I want to fill the array with product of all numbers except the number in that cell.
- X July 04, 2013 in United States
What is the complexity ? Do not worry about 0's or negative numbers in the array.
[Interviewer was more interested in how the multiplication/division gets effected as number of bits required to represent the intermediate products increases.]| Report Duplicate | Flag | PURGE
Google Applications Developer Algorithm - 1of 1 vote
AnswersGiven an array of real numbers A of length n, and some integer k such that 0 <= k < n, write a function that returns the kth largest number in A, where k=0 refers to the largest number.
What is the time complexity? What is the space complexity? Can you optimize either?
- trunks7j February 15, 2013 in United StatesExample input: A = [0.5, 2.5, 1], n=3, k=1 Expected output: 1
| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array of Integers of size n, Find element appearing more than n/2 times
- azharu92 September 20, 2012 in India| Report Duplicate | Flag | PURGE
Directi Intern Algorithm - 1of 1 vote
AnswersGiven AAABBGFF should get an output 3{A} 2{B}1{G}2{F}
- spammer May 12, 2012 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 1of 1 vote
Answersstreaming byte data coming which can be intergers or characters
- Anonymous February 08, 2011
you have to sort both the integers and characters with there index intact.
for e.g you have c6b2e4a
your sorted array should be a2b4c6e| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Algorithm - 1of 1 vote
AnswersIn a sorted array of 0's and 1's ,find the first occurrence of a 1 in it....
- psp.reachable@gmail.com October 13, 2008
eg:
000111111111
must return 4| Report Duplicate | Flag | PURGE
Amazon Development Support Engineer Algorithm - 1of 1 vote
Answersgiven 2 strings A and B. generate all possible solutions when B is merged in A.
- JerryGoyal May 22, 2016 in India
Ex: A = "hey"
B: "sam"
then solutions are :
heysam,hseaym,hesaym,sahemy etc.
notice that order should be the same for both of strings while merging.| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 1of 1 vote
AnswersYou are given a file which contains 3 values - start time, end time, amount of water flowing between the start time and end time for one day
- arsragavan December 23, 2014 in United States
The start time and end time may overlap and are inclusive. The times are not in a sorted order
Example:
0,10,100
10,15,300
16,20,400
5,15,200
Find the max flow of water at any instant of time.
In the above example, the answer is 600 ( at instant 10)| Report Duplicate | Flag | PURGE
A9 Intern Algorithm - 1of 1 vote
AnswersGiven a start position and an target position on the grid. You can move up,down,left,right from one node to another adjacent one on the grid. However there are some walls on the grid that you cannot pass. Now find the shortest path from the start to the target.
- fmars September 07, 2014 in United States
(This is easy done by BFS)
Extend. If you can remove three walls, then what is the shortest path from start to the target. (I have no ideal except for enumerate all the possibility of three walls. It must be the silly solution.) Does anyone have any idea?| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm