Turing Software Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
void swap (char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(char *a, int i, int n)
{
int j;
if (i == n)
printf("%s\n", a);
else
{
for (j = i; j <= n; j++)
{
if (a[i] == a[j] && i != j)
continue;
swap((a+i), (a+j));
permute(a, i+1, n);
swap((a+i), (a+j)); //backtrack
}
}
use back tracking
for ex string ABC
first
keep A (first letter constant) and chane others
ABC cange 2n letter
ACB
change the first letter
BAC
BCA
and so on
here is the code
- getjar.com/todotasklist my android app November 08, 2011