Microsoft Interview Question
1,273 Interview Reviews |
Back to all Microsoft Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Program Manager at Microsoft:
Shift a String 10 elements forward, and have the elements that fall off at the end of the String move to the front of the String. Don't use a second String.
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (4)
Loop i = 0 To Length -1 Then
s = s.substring(0,i) + s.substring(length-1,1) + s.substring(i, length-1-i)
End Loop
Helpful Answer?
Yes |
No
Inappropriate?
char[] chars = string.toCharArray()
StringBuffer toReturn = new StringBuffer();
for(int i = 0, j = 10; i < chars.length; ++i, j = (j+1) % chars.length) {
toReturn.add(chars[j])
}
return toReturn;
to char array and append to a string buffer
Helpful Answer?
Yes |
No
Inappropriate?
0 of 1 people found this helpful
{
int i=0;
int len = strlen(str);
while(shiftCount)
{
for(i=0;i<len;i++)
{
swap(i,len-1,str);
}
shiftCount--;
}
printf("Shifted String: %s \n",str );
}
void swap(int n1,int n2,char str[])
{
char temp = str[n1];
str[n1] =str[n2];
str[n2]=temp;
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Interview Candidate: