Microsoft Interview Question for Software Engineer in Tests






Comment hidden because of low score. Click to expand.
0
of 0 vote

you can use a hashtable(like an array); the key is the letter.
for every letter, table[letter]++;

- S October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

and for testing we can reverse the hash table....
that is every time we encounter a letter we decrease the letter count in the hash table...after all the letters are traversed we iterate through the hash table and check if all the letters counts are 0 or not.

- SC October 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Solution1 (worse):
For each char find the occurence by iterating the array.
complexity is O(n^2)

Solution2:
if you are free from modifying the array. Then sort the array and find the occurence.
It takes o(n logn) + o(n) = O(n logn)

Solution3:
If memory is not a constraint, then go with hash table.
It takes O(n) time and O(n)space.

- Veeren March 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anybody please give linear solution?

- Sidhu November 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hash table solution is inefficient because it requires a lot of space eg. what if your character set is unicode?

I used a binary search tree and did it in O(nlogn)

- Anonymous November 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hashtable solution needs constant amount of space, it is not inefficent. The number of symbols are constant even if you consider unicode character set.

- Anonymous November 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi,
It may be done as following in O(n):

* int count[256]={0};
* now iterate thru each char of the input string and do:
for(i=0;i<strlen(str);i++) {
ch=str[i];
count[ch]++; }
* now iterrate thru count[] to get frequency of each letter
:)

- shanky July 26, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More