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)

- Loler October 01, 2012 | Flag Reply
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;
}

- ansariinjnu October 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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...

- JustCoding October 01, 2012 | Flag
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;
 }

- pradegup October 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- gixxer6er October 02, 2012 | Flag


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More