Computer Associates Interview Question
Software Engineer / DevelopersCountry: United States
The statement "WITHOUT using the ascii values" probably means you can't use the ascii value directly, especially with the constraint of an array of size 32. Since the poster hasn't clarified the issue, it is probably safe to assume you can use the ascii values to determine an indirect index. Especially since you only have to worry about lower case. Which means you only need 'z'-'a'+1 slots or 26 slots. So an array of size 32 is going to be more than sufficient to track lowercase letters. So something like the following pseudo-code should do the trick.
for (char* c = buffer; c < 'buffer end'; ++c ) {
array[*c-'a']++;
++c;
}
This also assumes you're using single byte characters, which again since the poster hasn't specified is probably a safe assumption to make, but... depends on whomever was the originator of the question.
put 'a' in array['a' - 'a']; 'b' in array['b'-'a'],etc....
- Anonymous July 03, 2011