Coding Interview Questions
- 0of 0 votes
Answersgiven matrix like :
- Rahul Sharma December 18, 2014 in India
a b e d
b c f e
a b d d
….
find the longest path of consecutive alphabets given a starting alphabet. You can move in all 8 directions. for eg. a->b(right)->c(down)->d(diagnal down)… len = 4 , find max such len| Report Duplicate | Flag | PURGE
Amazon SDET Coding - 0of 0 votes
AnswersYou are given a rectangular grid with 2 rows and N columns. The top row is labeled 1 and the bottom row is labeled 2. The columns are labeled from 1 to N in increasing order. Each cell in the grid contains a single character.
- Rahul Sharma November 23, 2014 in India
Consider a hamiltonian walk in this grid. Meaning, pick a starting cell, say (i,j), and consider a path that starts from (i,j) and goes through every cell in the grid exactly once. Note that you can only walk to adjacent cells, or cells that you share a common edge with. There may be several such paths. Let us concatenate the characters in the order in which the cells are visited during a walk. The string formed can be called the string for the walk.
Among all the possible walks, and their respective strings, find out the lexicographically smallest string. We know that the length of the strings are all the same - to be precise, 2N. Thus, the lexicographically smallest string is simply the alphabetically smallest string if you compare the characters from left to right.
Input
The first line of input contains a number T, the number of test cases. Then follow T test cases. Each test case contains 3 lines. The first line contains the number N, the number of columns in the grid. It is well known of course that the grid contains 2 rows. The next two lines contain the description of the grid in the form of two strings; the string of N characters in row 1 from left to right and the string of N characters in row 2 from left to right, respectively. Each character will be a lowercase engish letter.
Output
Output a single line for each test case. The line must contain a string with 2N characters. This string should be the lexicographically smallest string for some hamiltonian walk in the grid.
Constraints
1 = T = 100
1 = N = 10
Sample Input
2
3
abc
def
10
ababaaabab
bababababa
Sample Output
abcfed
aaababababababababab
Explanation
In the first test the possible strings are { abcfed, adebcf, adefcb, badefc, bcfeda, cbadef, cfedab, cfebad, dabcfe, dabefc, defcba, edabcf, efcbad, fedabc, fcbade, fcbeda }. The smallest string is abcfed.| Report Duplicate | Flag | PURGE
Directi Intern Coding - 2of 2 votes
Answersgiven n > 0 fair dice with m > 0 "sides", write an function that returns a histogram of the frequency of the result of dice rolls. For example, for two dice, each with three sides, the results are:
- Aurelius October 29, 2014 in United States for BVal
(1, 1) -> 2
(1, 2) -> 3
(1, 3) -> 4
(2, 1) -> 3
(2, 2) -> 4
(2, 3) -> 5
(3, 1) -> 4
(3, 2) -> 5
(3, 3) -> 6
And the function should return:
2: 1
3: 2
4: 3
5: 2
6: 1| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Coding - 9of 9 votes
AnswersGiven a string (1-d array) , find if there is any sub-sequence that repeats itself.
- for.anonymous.usa October 22, 2014 in United States
Here, sub-sequence can be a non-contiguous pattern, with the same relative order.
Eg:
1. abab <------yes, ab is repeated
2. abba <---- No, a and b follow different order
3. acbdaghfb <-------- yes there is a followed by b at two places
4. abcdacb <----- yes a followed by b twice
The above should be applicable to ANY TWO (or every two) characters in the string and optimum over time.
In the sense, it should be checked for every pair of characters in the string.| Report Duplicate | Flag | PURGE
Google Software Engineer Intern Algorithm Brain Teasers C C++ Coding Data Structures Dynamic Programming Problem Solving String Manipulation - 0of 0 votes
AnswersImplement bool regex() Function.
- hprem991 October 11, 2014 in India for Chennei| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ Coding - 1of 1 vote
AnswersImplement bool isBST(Tree * root)
- hprem991 October 11, 2014 in India for Chennei| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C++ Coding - 3of 3 votes
AnswersYou are given a string S. Each character of S is either ‘a’, or ‘b’. You wish to reverse exactly one sub-string of S such that the new string is lexicographically smaller than all the other strings that you can get by reversing exactly one sub-string.
- Rahul Sharma October 09, 2014 in India
For example, given ‘abab’, you may choose to reverse the substring ‘ab’ that starts from index 2 (0-based). This gives you the string ‘abba’. But, if you choose the reverse the substring ‘ba’ starting from index 1, you will get ‘aabb’. There is no way of getting a smaller string, hence reversing the substring in the range [1, 2] is optimal.
Input:
First line contains a number T, the number of test cases.
Each test case contains a single string S. The characters of the string will be from the set { a, b }.
Output:
For each test case, print two numbers separated by comma; for example “x,y” (without the quotes and without any additional whitespace). “x,y” describe the starting index (0-based) and ending index respectively of the substring that must be reversed in order to acheive the smallest lexicographical string. If there are multiple possible answers, print the one with the smallest ‘x’. If there are still multiple answers possible, print the one with the smallest ‘y’.
Constraints:
1 ? T ? 100
1 ? length of S ? 1000
Sample Input:
5
abab
abba
bbaa
aaaa
babaabba
Sample Output:
1,2
1,3
0,3
0,0
0,4| Report Duplicate | Flag | PURGE
Google SDE-2 Coding - 7of 7 votes
AnswersGiven a number M (N-digit integer) and K-swap operations(a swap
- Rahul Sharma October 03, 2014 in India
operation can swap 2 digits), devise an algorithm to get the maximum possible integer?
Examples:
M = 132 K = 1 output = 312
M = 132 K = 2 output = 321
M = 7899 k = 2 output = 9987
M = 8799 and K = 2 output = 9987| Report Duplicate | Flag | PURGE
Google SDE-2 Coding - 0of 0 votes
AnswersSuppose you want improve the performance of search queries, using a cache. Each search queries is in form of a string and returns a list of ad id's in the form of longs.
- LCHammer September 25, 2014 in United States for Advertising
Design a class with the appropriate data structure(s) that can manage a cache of search queries.| Report Duplicate | Flag | PURGE
Amazon SDE1 Coding - 1of 1 vote
AnswersWrite a recursive method to get the multiplication of two numbers such that there are minimum number of addition operations.
- Rahul Sharma September 05, 2014 in India| Report Duplicate | Flag | PURGE
Adobe SDE-2 Coding - 5of 5 votes
AnswersGiven three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|, |b-c| and |c-a| are minimum
- Greg September 04, 2014 in United States
Please provide as efficient code as you can.
Can you better than this ???| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Arrays C++ Coding - 0of 0 votes
Answerswhat all design patterns are used in designing a shopping cart and explain?
- User August 26, 2014 in United States| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Coding - 0of 0 votes
AnswersGiven an array[0, n-1], each number of the array is positive int. Your task is adding the operators,"+","*", "(",")" (add, multiply, parenthesis) to maximize the result . The position in the array is Fixed.
- justtest August 19, 2014 in United States
For example, "2,1,1,2", you can get (2+1)*(2+1)=9.
Follow up, if the number may be negative , how to solve it ?| Report Duplicate | Flag | PURGE
Algorithm Brain Teasers Coding Data Structures Dynamic Programming - 5of 5 votes
AnswersWrite a function which, given two integers (a numerator and a denominator), prints the decimal representation of the rational number "numerator/denominator".
- loganwol August 18, 2014 in United States
Since all rational numbers end with a repeating section, print the repeating section of digits inside parentheses; the decimal printout will be/must be
Example:
1 , 3 = 0.(3)
2 , 4 = 0.5(0)
22, 7 = 3.(142857)
etc..| Report Duplicate | Flag | PURGE
Google SDET Coding - 1of 1 vote
AnswersWrite a program to find distinct value out of an array. If you didnt find any duplicates return a empty array.
- rockykumar1970 August 18, 2014 in India| Report Duplicate | Flag | PURGE
Ebay Software Engineer in Test Coding - 1of 1 vote
AnswersIf you run the same program twice, what section would be shared in the memory?
- farzanmoofty August 12, 2014 in United States for Price history
Follow up, is the text portion of memory share? Why not?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding Operating System - 0of 0 votes
AnswersWrite a function that accepts an n-dimension array and prints its values--For array of any dimension.
- farzanmoofty August 12, 2014 in United States for Price history
What is the layout of multi-dimensional array in the memory?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Arrays C++ Coding - 1of 1 vote
AnswersGiven a number n, write a function that writes a Fibonacci sequence to number n.
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding - 0of 0 votes
AnswersIt was part of a bigger question --a large piece of code.
- farzanmoofty August 12, 2014 in United States for Price history
Implement << operator. What are the differences of implementation as a member function and a non-member function| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding Object Oriented Design - 0of 0 votes
AnswersWhat does an iterator in C++ point to in case of a vector vs. list. Where would it point to if the prior links are deleted in the list? In case of a vector if it points to a specific index, where would it point to if the prior indexes are deleted?
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer Arrays C++ Coding Linked Lists - 0of 0 votes
AnswersWhat C++ data structures would you use to implement LRU cache? Show implementation.
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding - 0of 0 votes
AnswersHow would you implement this:
- farzanmoofty August 12, 2014 in United States for Price historyobject["String for a security name"]["another string"] = another_object
| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding - 0of 0 votes
AnswerWhat are the various ways of doing IPC in Unix/Linux? How do you implement it?
- farzanmoofty August 12, 2014 in United States for Price history| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C++ Coding Operating System unix system programmin - 0of 2 votes
AnswersDesign a system like friend's functionality in facebook. should have all features of facebook's friends functionality. like for each person , he can have any number of friends , he will get suggestions for new firends , showing common friends if we visits any other profile . algo should be scalable , robust .
- gopi.komanduri August 02, 2014 in United States| Report Duplicate | Flag | PURGE
Computer Scientist Algorithm Android Application / UI Design Arrays Bit Manipulation C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures Database Distributed Computing Dynamic Programming Hash Table Java Large Scale Computing Linked Lists Math & Computation Object Oriented Design Problem Solving Sorting SQL Stacks System Design Trees and Graphs XML - 3of 3 votes
AnswersFind the longest words in a given list of words that can be constructed from a given list of letters.
- Rohitraman2006 August 01, 2014 in United States
Your solution should take as its first argument the name of a plain text file that contains one word per line.
The remaining arguments define the list of legal letters. A letter may not appear in any single word more times than it appears in the list of letters (e.g., the input letters ‘a a b c k’ can make ‘back’ and ‘cab’ but not ‘abba’).
Here's an example of how it should work:
prompt> word-maker WORD.LST w g d a s x z c y t e i o b
['azotised', 'bawdiest', 'dystocia', 'geotaxis', 'iceboats', 'oxidates', 'oxyacids', 'sweatbox', 'tideways']
Tip: Just return the longest words which match, not all.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 2of 2 votes
AnswersWrite a code to test whether string s2 is obtained by rotating the string s1 by 2 places.
- Surekhag28 July 26, 2014 in India for Kindle
e.g S1="amazon" S2="azonam" return true
S1="quality" S2="lityqua" return false| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersWrite a code to find duplicate elements in array and total count of duplicate elements.
- Surekhag28 July 26, 2014 in India for Kindle
eg. arr={5,3,4,6,7,5,3,2,1}
Duplicate elements:- 5,3
Total duplicate count:- 2| Report Duplicate | Flag | PURGE
Amazon Quality Assurance Engineer Coding - 0of 0 votes
AnswersDesign a phone book such that fields are searchable with name , with number. Later enhanced teh question asking searchable with address as well.
- gopi.komanduri July 22, 2014 in India| Report Duplicate | Flag | PURGE
Analyst Algorithm Arrays Bit Manipulation Brain Teasers C# C++ Cache Coding Computer Architecture & Low Level Data Mining Data Structures