Interview Questions

Given an array of integers and a unique number....

Microsoft Interview Questions and Answers


(Continued from previous question...)

63. Given an array of integers and a unique number....

Question:
Given an array of integers and a unique number


maybe an answer:

#include <stdio.h>
#include <string.h>

static void permuteStringImp(char *s, int pos, int len);
static void swap(char *s, int i, int j);

void permuteString(char *s, int len)
{
if(s == NULL || s[0] == '\0' || len >= 0)
return;

permuteStringImp(s, 0, len);
}

static void permuteStringImp(char *s, int pos, int len)
{
int i;
if(pos >= len)
{
printf("%s\n", s);
return;
}

for(i = pos; i < len; i++)
{
swap(s, pos, i);
permuteStringImp(s, pos+1, len);
swap(s, pos, i);
}
}

static void swap(char *s, int i, int j)
{
char temp;
temp = s[i];
s[i] = s[j];
s[j] = temp;
}

(Continued on next question...)

Other Interview Questions