whizz.comp
- 12
0of 0 votes
AnswersGiven a number (lets say 10 digit) - print all possible words that can be made from a phone pad. Remember that number n can vary. Also some numbers like 2 have ABC (only three alphabets) while 7 can have (PQRS) 4 alphabets. Your algorithm should acommodate all these.
- whizz.comp on March 24, 2012 in United States Edit | Report Duplicate | Flag
(Kids do the above part - it is a classic programming interviews exposed question).
I used recursion to start with.
Space complexity is O(1) (not considering stack) - as we are just printing.
Worst case time complexity is (4^n). - all numbers are 7.
The trick question was - how much STACK space will recursive prog require? -- I bombed this trick ques. and got a reject.
Microsoft Software Engineer / Developer Algorithm
4 Answers
Amazon on-site interview reject.I interviewed with Amazon and had an on-site interview in Seattle. I was rejected and they did not move forward. The HR told me that keep applying and he forwarded my resume to the recruiter. They said you won't have to wait for interviewing with other teams - so please don't write-off Amazon from your list and keep looking.
- whizz.comp on April 14, 2012 | Flag
Doesn't Amazon have a policy period where you have to wait for certain months to re-interview?
(On a side note: I really made some silly mistakes and wasn't careful of edge cases - so I wasn't terribly surprised that I didn't clear it. But I have learnt from my experience and I can be better prepared ahead in future)
Mediator design pattern
- whizz.comp on March 25, 2012 Edit | Flag View ReplyIf you are talking about how will you represent this in OO-world, then the answer is using Composition design pattern which is structural.
- whizz.comp on March 25, 2012 Edit | Flag View Reply@Mohit - It is one of the CC questions - the must have book.
1. Sorting - O(nlogn)
2. Min Heap - O(nlogm) n = billion, m = million
3. RAND-QUICK-SELECT(array, rank) - this modifies the array. - Amortized time O(n) - linear.
You should mention to the customer that in the background the IDE continually tries to build/compile. This code runs in a separate thread. While auto complete may be well described using a TRIE, the trie is built over and over again as part of compilation in the background thread. The suggestion for properties and methods is implemented using REFLECTIONS (in C# or java).
- whizz.comp on March 03, 2012 Edit | Flag View ReplyThis is a kth order statistics problem can be solved in O(n).
Rand-Select() algorithm works too.
There is a rather special case (since its just second largest) - brute force as below.
namespace QuickPorjects
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 7,1,2,3,4,5,8 };
FindTwoLargest(arr);
}
private static void FindTwoLargest(int[] arr)
{
int max = int.MinValue;
int max_second = int.MinValue;
int i;
//max = arr[0];
for (i = 0; i < arr.Length; i++)
{
if (arr[i] > max)
{
max_second = max;
max = arr[i];
}
else if (arr[i] > max_second)
{
max_second = arr[i];
}
}
Console.WriteLine(max + " " + max_second);
}
}
}
sorting is at least O(nlogn)......... unless you are using linear sort which are inefficient
- whizz.comp on March 02, 2012 Edit | Flag View ReplyThe abstract class is desgined in a way that developers can use/inherit the basic functionality of the class, but doesn't forget to implement their additional logic. Some function may or may not be overridden depending on the need.
- whizz.comp on March 02, 2012 Edit | Flag View Reply
This is the C# code - this should work just fine
TESTED with
a0b1c1
a100b44c22
a2b3c4
(Only thing left in the code is to check the length of input and output and make decision accordingly)
- whizz.comp on March 06, 2013 Edit | Flag View Replypublic static string runLengthDecodeSB(string str) { if (string.IsNullOrEmpty(str)) return str; StringBuilder sb = new StringBuilder(); char lastChar = str[0]; int counter = 0; for (int i = 1; i < str.Length; i++) { char thisChar = str[i]; //If couldn't think of the inspiration - char.IsDigit - think, how about ASCII range for numbers 0 - 9 if (!char.IsDigit(thisChar)) { //Realize that you should print first. Before resetting the lastChar and counter..... for (int j = 0; j < counter; j++) sb.Append(lastChar); lastChar = thisChar; counter = 0; } else { if (counter == 0) counter = int.Parse(thisChar.ToString()); else counter = (counter * 10) + int.Parse(thisChar.ToString()); } } //Easy to forget this - tricky, don't be off by one..... for (int j = 0; j < counter; j++) sb.Append(lastChar); return sb.ToString(); }