IBM Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
#include <stdio.h>
void swap(char *s, int i, int j)
{
char temp = s[i];
s[i] = s[j];
s[j] = temp;
}
void foo(char *s, int j, int len)
{
int i;
if (j == len-1) {
printf("%s\n", s);
return;
}
for (i=j;i<len;i++) {
swap(s, i, j);
foo(s, j+1, len);
swap(s, i, j);
}
}
int main()
{
char s[] = "abc";
foo(s, 0, strlen(s));
}
I think that interviewer wants to generate all hamilton paths, starting from each character ( each Node). Actually this is DFS form each Node as it was suggested above
P.P william do you have already feedback from so many interviews or still wainting?
Hi, sorry for the late reply. Yes the feedback was given during the interview (meaning, she mentioned that she was looking for the minimum spanning tree solution).
As for the on-site interview (this was a phone interview) I am expecting an invitation soon (I hope). The recruiter said I did well.
This is a minimum spanning tree starting at each node.
- fayezelfar January 19, 2016