Morgan Stanley Interview Report
- 0of 0 votes
AnswersWrite a function to check whether the two strings are rotation of each other or not.
Example: str1="Password" str2="ordPassw"
My Solution was.........
- varunesh.88 December 07, 2012 in India#include<stdio.h> void fn(char * str1, char * str2) { int i=0, j=0,flag=0; while(str2[i]) { if(str2[i]== *str1) { flag=1; break; } i++; } if(!flag) { printf("2nd String is not a rotation of other\n"); return; } j=i; while(str2[i]) { if( !(str2[i]==*str1)) { printf("2nd String is not a rotation of other\n"); return; } i++; str1++; } i=0; while(i<j) { if( !(str2[i]==*str1)) { printf("2nd String is not a rotation of other\n"); return; } i++; str1++; } if(*str1=='\0') printf("String are rotation of each other\n"); else printf("2nd String is not a rotation of other\n"); } int main() { char * str1="Password"; char * str2="ordPassw"; fn(str2, str1); return 0; }
| Report Duplicate | Flag | PURGE
Morgan Stanley Intern C - 2of 2 votes
AnswersGiven a string we have to find first non-repeating character in the string....
- varunesh.88 December 07, 2012 in India
Example: str="aabbbccccddeffffgg";
Answer is : e| Report Duplicate | Flag | PURGE
Morgan Stanley Intern C