## National Informatics Centre Interview Question for Scientific Officers

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
1
of 1 vote

Sort and Compare O(nlogn)

Comment hidden because of low score. Click to expand.
0
of 0 vote

Step 1:store the first string in p,
Step 2: store the second string in s,
Step 3: create a array(occurrence[26]) and initialise it with zero,
Step 4:find occurrence of leters in first string ,second string and increase the corresponding index in occurrence[26] array corresponding the 1st string and same time decrease the occurrence[26] corresponding the 2nd string ,{if p[i]==b the p[i]-‘a’ will be 1}
Step 5 :If all the contents of occurrence[26] array is zero then both the string have same set of letter otherwise different letter .
Any problem cotact ansariinjnu@gmail.com
#include<stdio.h>
Int main()
{
Char p[10],s[10];
Int i=0,occurrence[26]={0};
Printf(“\nEnter the 1st string”);
Gets(p);
Printf(“\nEnter the 2nd string”);
Gets(s);
While(*p && *s)
{
Occurrence[p[i]-‘a’]++;
Occurrence[s[i++]-‘a’]--;
}
If(*p || *s)
{
Printf(“Both string is not same:”);
Return;
}
I=0;
While( i<26 && ! occurrence[i])
I++;
If(i==26)
Printf(“Bothe string is same”);
Else
Printf(“Bothe string is not same:”);
Retirn 0;
}

Comment hidden because of low score. Click to expand.
0

your code won't work entirely because you are incrementing i inside the while loop twice so after p[i] is handled, the next character handled will not be s[i] but instead s[i+1]..

otherwise the logic works fine...

Comment hidden because of low score. Click to expand.
0
of 0 vote

This function will return 1 if Equal otherwise it will return 0.

``````int strMatch(char str1[],char str2[]){

int arr[256];
for(int i=0;i<256;i++){
arr[i]=0;
}
for(int i=0;str1[i]!='\0';i++){
arr[str1[i]]++;
}
for(int i=0;str2[i]!='\0';i++){
if(arr[str2[i]]<=0) return 0;
arr[str2[i]]--;
}
for(int i=0;i<256;i++){
if(arr[i]>0) return 0;
}
return 1;
}``````

Comment hidden because of low score. Click to expand.
0

This is the answer for the provided question. All your doing is checking for strlen. As per the question 'mips' and 'mississippi' has the same set of characters

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.