Intel Corporation Interview Question: If we have a string of 7 char... | Glassdoor

Interview Question

Software Systems Quality Assurance Internship Interview Santa Clara, CA

If we have a string of 7 characters and we can put from 'a

 ' to 'z' in any of these places, write a program which its output is from 'aaaaaaa' to 'zzzzzzz'.

Interview Answer

1 Answer


Using recursion. Maybe the first thought in our mind is for loop but after second thought I believe is most suitable for this question. Following is my program using C++.
void Str(int str_size, int index, char *str)
    if(str_size == index)
        str[index] = '\0';
    for(char c = 'a'; c <= 'z'; ++c)
        str[index] = c;
        Str(str_size, index + 1, str);

Tishin on Sep 25, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.