Algorithm Interview Questions
- 1of 1 vote
AnswersAlternate sorting: Given an array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum.
- axaysd June 23, 2016 in United States
Eg.) Input : {1, 2, 3, 4, 5, 6, 7}
Output : {7, 1, 6, 2, 5, 3, 4}| Report Duplicate | Flag | PURGE
Zoho SDE1 Algorithm - 0of 0 votes
AnswersThere is a famous algorithm on geeksforgeeks to specify the minimum number of insertions to convert a string to palindrome.
- guptasunny158 June 22, 2016 in India
http://www.geeksforgeeks.org/dynamic-programming-set-28-minimum-insertions-to-form-a-palindrome/
But the question that was asked to me was one step ahead, interviewer asked to tell the characters that need to be appended to the string to make it a palindrome.| Report Duplicate | Flag | PURGE
Snapdeal Senior Software Development Engineer Algorithm - 4of 4 votes
AnswersYou have rand2() function which returns 0 or 1 with equal probability. You should implement rand3() using rand2().
- nfokin June 20, 2016 in Russia| Report Duplicate | Flag | PURGE
Yandex Software Engineer Algorithm - -8of 8 votes
AnswersGiven set of characters and a dictionary find the minimum length word that contains all the word from the given word
- darklight June 19, 2016 in India| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 1of 1 vote
AnswersGiven an array of n integers. MaxPrefix is defined as count of elements those are greater than the element and in the right side of array wrt to the element. Write a program to give the max of MaxPrefix Ex. Input 10 -4 6 2 8 9 4 Output is 5
- darklight June 19, 2016 in India| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswerGiven M nodes and at most one outgoing edge from any node. Given Q operations where an operation is either
- lifeenergy999 June 19, 2016 in India
i) 1 Z where Z represent the source node, print the terminal node if a coin travels through edges. In case, if node Z lies in a cycle, print LOOP. 1 is the operation type
ii) 2 Z where Z represents node for which the outgoing edge is removed and 2 is operation type.
Operations are performed in order in which they are given.
M <= 3*10^5, Q <= 3*10^5
Input
First line contains integer M.
Second line contains M integers, where ith integer represents outgoing edge from ith node. If outgoing edge is 0, that means there is no outgoing edge from this node.
Third line contains integer Q followed by Q lines where each line is either 1 Z, or 2 Z where Z is node number. Nodes are 1-indexed.
This question was asked in coding test. Can somebody please help me with this problem with the given constraints?| Report Duplicate | Flag | PURGE
Software Developer Algorithm - 1of 1 vote
AnswersWrite a class to take in a large arbitrary number, also provide a function to increment the number. The number will be passed on as an array of integers.
- pushpinder2751 June 17, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 2of 2 votes
AnswersGiven a rectangle with top-left(a,b) and bottom-right(c,d) coordinates. Also given some coordinates (m,n) of sensors inside the rectangle. All sensors can sense in a circular region of radius r about their centre (m,n). Total N sensors are given. A player has to reach from left side of rectangle to its right side (i.e. he can start his journey from any point whose y coordinate is b and x coordinate is a<=x<=c. He has to end his journey to any point whose y coordinate is d and x coordinate is a<=x<=c).
- ankit3600 June 14, 2016 in India
Write an algorithm to find path (possibly shortest but not necessary) from start to end as described above.
Note: all coordinates are real numbers
(a,b)
|----------------------------------------------|
|.......................................................|end
|.......................................................|
|start................................................|
|.......................................................|
|----------------------------------------------|(c,d)
Edit: You have to avoid sensors.
Also u can move in any direction any time.| Report Duplicate | Flag | PURGE
Google SDE-2 Algorithm - -2of 2 votes
AnswersGiven a matrix which is spirally sorted. Remove an element and insert another element maintaining the sorted order.
- neer.1304 June 14, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 0of 0 votes
AnswersGiven two sets of strings A and B. Find the
- neer.1304 June 14, 2016 in United States
(A-B) U (B-A) ( U = union ). The answer should be in lexicographical order and A’s elements should appear before B’s.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 0of 0 votes
AnswerGiven a few points in first quadrant – (x1,y1) …..(xn,yn) and given another set of points (a1,b1…..an,bn), determine whether all the points (a1,b1…an,bn) have already occured in (x1,y1)…..xn,yn)
- neer.1304 June 14, 2016 in United States| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - 0of 0 votes
AnswersGiven a graph where every two nodes are either friends or enemies with each other. Find a way to go from one node to the other.
- neer.1304 June 14, 2016 in United States
Restrictions:
1) You can also travel from one node to next if they are friends with each other
2) You have some “magic potions”. You can convert an enemy path to a friend path with a magic potion.
Find the path with min number of magic potions required.| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Algorithm - -1of 1 vote
AnswersConsider a string, s = "abc". An alphabetically-ordered sequence of substrings of s would be {"a", "ab", "abc", "b", "bc", "c"}. If we reduce this sequence to only those substrings that start with a vowel and end with a consonant, we're left with {"ab", "abc"}. The alphabetically first element in this reduced list is "ab", and the alphabetically last element is "abc". As a reminder:
- guptasunny158 June 12, 2016 in India
Vowels: a, e, i, o, and u.
Consonants: b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y, and z.
Complete the findSubstrings function in your editor. It has 1 parameter: a string, s, consisting of lowercase English letters (a − z). The function must find the substrings of s that start with a vowel and end with a consonant, then print the alphabetically first and alphabetically last of these substrings.
Input Format
The locked stub code in your editor reads a single string, s, from stdin and passes it to your function.
Constraints
3 ≤ length of s ≤ 5 × 105
Output Format
Your function must print two lines of output denoting the alphabetically first and last substrings of s that start with a vowel and end with a consonant. Print the alphabetically first qualifying substring on the first line, and the alphabetically last qualifying substring on the second line.
Sample Input 1
aba
Sample Output 1
ab
ab
Explanation 1
"ab" is the only possible substring which starts with a vowel (a) and ends with a consonant (b). Because we only have 1 qualifying substring, "ab" is both the alphabetically first and last qualifying substring and we print it as our first and second lines of output.
Sample Input 2
aab
Sample Output 2
aab
ab
Explanation 2
There are 2 possible substrings which start with a vowel and end with a consonant: "aab" and "ab". When ordered alphabetically, "aab" comes before "ab". This means that we print "aab" (the alphabetically first qualifying substring) as our first line of output, and we print "ab" (the alphabetically last qualifying substring) as our second line of output.
Sample Input 3
rejhiuecumovsutyrulqaeuouiecodjlmjeaummaoqkexylwaaopnfvlbiiiidyckzfhe
Sample Output 3
aaop
utyrulqaeuouiecodjlmjeaummaoqkexylwaaopnfvlbiiiidyckzfh
Explanation 3
There are 4830 substrings of s, but only 676 of them start with a vowel and end with a consonant. When ordered alphabetically, the first substring is "aaop" and the last substring is "utyrulqaeuouiecodjlmjeaummaoqkexylwaaopnfvlbiiiidyckzfh".| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - 0of 0 votes
Answersgenerate and print first N binary palindromes .
- razkverma June 09, 2016 in India
ex first 4 are as follow
1
11
101
111| Report Duplicate | Flag | PURGE
AMD Associate Algorithm - 0of 0 votes
AnswersFind the % match of a string given a list of strings. See below example:
- localghost June 07, 2016 in United States
// Input: String word, List<String> glossary
// Output: % match
// 'catdog', ['dog', 'frog', 'cat'] => 100%
// 'cardog', ['dog', 'frog', 'cat'] => 50%| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 1of 1 vote
AnswersWrite a program that takes an integer and prints out all ways to multiply smaller integers that equal the original number, without repeating sets of factors. In other words, if your output contains 4 * 3, you should not print out 3 * 4 again as that would be a repeating set. Note that this is not asking for prime factorization only. Also, you can assume that the input integers are reasonable in size; correctness is more important than efficiency.
- xankar June 07, 2016 in United States
Eg: PrintFactors(12) 12 * 1 6 * 2 4 * 3 3 * 2 * 2| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm - 0of 0 votes
AnswersFind the longest cycle in a directed graph in java
- shivamdev31 June 07, 2016 in United States
I/P -> 23 --> O/P 6
Elements : 4, 4, 1, 4, 13, 8, 8, 8, 0, 8, 14, 9, 15, 9, -1, 10, 15, 22, 22, 22, 2
longest cycle -> 4, 13, 11, 9, 8, 0
Its the value and value at that index.| Report Duplicate | Flag | PURGE
Developer Program Engineer Algorithm - 3of 3 votes
Answers# take an array and print non over lapping in order pairs. example:
- thegeek21 June 05, 2016 in United States# [1,2,3,4] => input # output below is in order combination # (1234) # (1)(234) # (1)(23)(4) # (1)(2)(34) # (12)(34) # (12)(3)(4) # (123)(4) # (1)(2)(3)(4)
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou are given a range [first, last], initially white. You need to paint it black.
For this purpose you have a set of triples
[(f, l, cost), ...] - where each triple means that you can paint range [f, l] for `cost` coins (limitations: cost is floating point >= 0, f, l, first, last are integers).
Find minimum cost needed to paint the whole range [first, last] or return -1 if it's impossible
Example:[first, last] = [0, 5] and set of triples is [[0, 5, 10], [0, 4, 1], [0, 2,5], [2, 5, 1]]
Clearly the answer is to take [0, 4, 1] and [2, 5, 1] - the total cost will be 2.
Another example:[first, last] = [0, 5] triples are [[1,4, 10], [2, 5, 6]]
answer is -1, because it's impossible to color whole range.
- emb June 05, 2016 in United States| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswersHow will you test the efficiency of a unsupervized algorithm?
- starsgazing June 04, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - 0of 0 votes
AnswersWhat is the difference between supervised and unsupervised algorithms?
- starsgazing June 04, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - -1of 3 votes
AnswersA man just finished painting his house and needs something more. At the hardware store the clerk shows him what he wants and says "one is $1".
- WonderWoman June 04, 2016 in United States
The man states I need 600 for $3. What did the man buy?| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - -1of 3 votes
AnswersIf a teenager and a half can eat a pizza and a half in a day and a half. How many pizza's can 9 teenager eat in 3 days?
- WonderWoman June 04, 2016 in United States| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - -1of 1 vote
AnswersWhat is the next number
- WonderWoman June 04, 2016 in United States
-3 24 -168 1008 -5040| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - -1of 1 vote
AnswersPhysician : Symptoms
- WonderWoman June 04, 2016 in United States
Detective: Clue
Mason: Brick
Dispatch: Taxicab
Pharmacist:Drugs| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - -2of 2 votes
AnswerWeight: Scale as to
- WonderWoman June 04, 2016 in United States
Volume: Sound
Image: Microscope
Distance: odometer
Calibration: Measurements
Inch:Feet| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - 0of 0 votes
AnswersBand: Musician as
- WonderWoman June 04, 2016 in United States
Team:Fans
Stage:Dancers
Family: Sisters
Cast: Actors
Circus: Jugglers| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - 0of 0 votes
AnswersBiography:Life is as
- WonderWoman June 04, 2016 in United States
Story:Imagination
Chronicle: Events
Memoir:Reader
Song:Composer
Pose:Poem| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - 0of 0 votes
AnswerRenovate: Dilapidated is as
- WonderWoman June 04, 2016 in United States
Sacrifice: fortified
Revere: Admirable
Revitalize: fatigued
Restore: Irreparable
Modify: Altered| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm - 0of 0 votes
AnswersHearten: Courage is as
- WonderWoman June 04, 2016 in United States
repay: Installment
demote: rank
educate: knowledge
agree: quarrel
punish: wrongdoing| Report Duplicate | Flag | PURGE
Epic Systems Student Algorithm