Microsoft Interview Question
Software Engineer in Teststhe league table can never look like this. one team has to win and the other has to lose. the sum of total points won by all teams has to equal 56.
we can also have like
11 3
11 3
11 3
11 3
11 3
1 13
0 14
0 14
so it will be max 13 n not qualified
edit for prev response it will be 11 not 13..
and for min matched for qualifying can be something like this
14 0
14 0
14 0
4 10
3 11
3 11
2 12
2 12
hence it will 4
every thing is BS..except for the first anon...he got it write..
sriks ur missing a small point..14 wins means every other team has to lose and hence the 2nd cant have 14 wins again..its a simple math thou...
The answer given by the first guy is correct. Don't understand why are there so many people questioning it and more interestingly, some1 even gives his code...
Because after the analysis by a human brain, the answer can be given immediately, so it's a problem that can be solved with O(0) time and O(0) storage..
So why do they write a code to solve a question that can be solved with O(0) time and O(0) storage?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* Replace(char* src, char* from, char* to)
{
int count;
char* temp;
int i,j,k,l,p;
for(i=0,p=0;i<strlen(src);i++,p++)
{
count =0;
temp[p]=src[i];
if(src[i]==from[0])
{
count++;
for(j=1;j<strlen(from);j++)
if(src[i+j]==from[j])
count++;
if(count==strlen(from))
for(k=i,l=0;k<i+strlen(to);k++,l++)
temp[k]=to[l];
p=p+strlen(to)-1;
i=i+strlen(from)-1;
}
}
return temp;
}
int main(void)
{
char str[40];
char find[10];
char replace[10];
char *nstr;
printf("Enter the original string: ");
scanf("%s",&str);
printf("Enter the find string: ");
scanf("%s",&find);
printf("Enter the string to replace: ");
scanf("%s",&replace);
nstr = Replace(str,find,replace);
printf("The modified string is: %s \n",nstr);
return 0;
}
//for questio one this code below should be fine ......although it could be made better by involving the malloc functions by determining the size exactly.......
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* Replace(char* src, char* from, char* to)
{
int count;
char* temp;
int i,j,k,l,p;
for(i=0,p=0;i<strlen(src);i++,p++)
{
count =0;
temp[p]=src[i];
if(src[i]==from[0])
{
count++;
for(j=1;j<strlen(from);j++)
if(src[i+j]==from[j])
count++;
if(count==strlen(from))
for(k=i,l=0;k<i+strlen(to);k++,l++)
temp[k]=to[l];
p=p+strlen(to)-1;
i=i+strlen(from)-1;
}
}
return temp;
}
int main(void)
{
char str[40];
char find[10];
char replace[10];
char *nstr;
printf("Enter the original string: ");
scanf("%s",&str);
printf("Enter the find string: ");
scanf("%s",&find);
printf("Enter the string to replace: ");
scanf("%s",&replace);
nstr = Replace(str,find,replace);
printf("The modified string is: %s \n",nstr);
return 0;
}
char *replace(char *str, char *find, char *replace)
{
char *p=NULL;
char *out=NULL;
if(NULL==str || NULL ==find || NULL==replace){
printf("\n invalid param");
return NULL;
}
if(NULL == (p=strstr(str, find))){
printf("\n find not present in str");
return NULL;
}
else{
int len=0;
len= p-str + strlen(p+strlen(find)) + strlen(replace);
out=(char *)malloc(len +1);
if(out==NULL){
return NULL;
}
*p='\0';
strcpy(out, str);
strcat(out, replace);
strcat(out, p+strlen(find));
}
return out;
}
Hi ajitpec,
The written test of Microsoft was on 13th Feb 2011 in Bangalore.
Thanks for the written test questions.
Can you please send me the questions for the INTERVIEW please which was held on 19-20 Feb 2011?
You can send me the questions in my email or you can just call me.
OR, just give me your cell number, I will call you directly.
I will be really grateful to you.
Sandeep Shivhare
8880994330
sandeep_shivhare19@yahoo.co.in
char* replaceString(char* str, char* find, char* replace)
{
int strLen = strlen(str);
int findlen = strlen(find);
int replacelen = strlen(replace);
char* newStr = (char *)malloc(sizeof(char)*strlen(str)*( (replacelen/findlen)+1)+1);
*newStr = '\0';
int index = 0;
int done = 0;
while(*(str+index))
{
//printf("%c,%d\n",*(str+index),index);
if(*(str+index) == *find || !*(str+index+1))
{
int newlen = strlen(newStr);
if(*(str+index) != *find)
{
memcpy(newStr+newlen,str+done, index-done+1);
*(newStr+newlen+index-done+1) = '\0';
}
else
{
memcpy(newStr+newlen,str+done, index-done);
*(newStr+newlen+index-done) = '\0';
done = index;
if(index+findlen <= strLen)
{
bool match = true;
for(int i = 0 ; i < findlen ; i++)
{
if(*(str+index+i) != *(find+i))
{
match = false;
break;
}
}
if(match)
{
index += findlen;
done = index;
newlen = strlen(newStr);
memcpy(newStr+newlen,replace,replacelen);
*(newStr+newlen+replacelen) = '\0';
}
}
}
//printf("%s\n",newStr);
//getchar();
}
index++;
}
return newStr;
}
Solution for problem 1
char * replace(char *str,char *find,char *replace)
{
char *temp = (char *)malloc((sizeof(char)*(strlen(str)+strlen(replace)-strlen(find))));
char *i;
i=strstr(str,find);
if(i>=0)
{
strncpy(temp,str,(i-str));
strcat(temp,replace);
strcat(temp,i+strlen(find));
return temp;
}
return str;
}
4)Ans:
- Anonymous February 14, 2011Let A,B,C,D,E,F,G,H are 8 teams.
Mimum number of matches to win for qualify = 4
Teams win Loss
A 14 0
B 12 2
C 10 4
D 4 10
E 4 10
F 4 10
G 4 10
H 4 10
Maximum number of matches won by team when not qualify = 10
Teams Win Lost
A 10 4
B 10 4
C 10 4
D 10 4
E 10 4
F 4 10
G 2 12
H 0 14