Interview Questions

Find the frequency of each letter in a string. then test it.

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

Find the frequency of each letter in a string. then test it.

Question:
Find the frequency of each letter in a string. then test it.


maybe an answer:


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.


maybe an answer2:


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

(Continued on next question...)

Other Interview Questions