Microsoft Interview Question for Software Engineer in Tests


Team: SDET
Country: India
Interview Type: Phone Interview




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

Linear search, complexity O(N). Is the array sorted, except the spaces? If, yes binary search, and at each step check if you found a space, in which case move one position to the left, or to the right.

- EugenDu May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@zammer: what does element refer here?Does it mean character?

- aka May 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

oh .sorry it means character only .

- zammer May 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@zammer : Do you mean we have to search only single character or multiple character element also for eg. can i search for 'ab' also ?

- Ashish May 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is unique about this problem? just matching one character at a time and stopping when match is found is simple solution but doesn't it sound too simple?

- Sumit May 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I agree with Sumit

- Jackie May 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This array should be sorted, not characters array, but strings array.
The solution can be found sites.google.com/site/spaceofjameschen/home/sort-and-search/find-string-in-a-sorted-array-interspersing-with-spaces

- Anonymous May 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please Explain Question With an example .

- ankitjaingc May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question would make more sense if it is sorted and requires better than O(n), for O(n) it's too simple

- Jackie May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeah , the array is sorted and we have to search one character .

- zammer May 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the array is sorted, then may be binary search is fine

- Sam May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int findIndex(char[] A, char ch){

int low=0;
int high=A.lengh()-1;

while(low<=high)
{
int mid=(high-low)/2 -low;

if(A[mid]==ch){
return mid;}

else if (A[mid]<ch)
{
low=mid+1;
while(A[low]==' '){
low++;
}
}

else 
{
high=mid-1;
while(A[high]==' '){
high--;
}
}

}
return -1;

}

- Sam May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You are NOT checking the condition when A[mid] == ' '.

- Hello world June 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it is array of string and we have to search for a particular string

- Anonymous June 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using Binary Search

int chSearch(string& str,char val, int start, int end, bool shift = true)
{

	if(start == end)
		return -1;
	if(str[start]==val)
		return start;
	if(str[end]==val)
		return end;
	int mid = (start+end)/2;
	if(shift)
	{
		while (str[mid]== ' ')
		{
			mid --;
		}
	}
	else
	{
		while (str[mid]== ' ')
		{
			mid ++;
		}
	}
	if(str[mid]==val)
		return mid;
	if(str[mid]<val)
		chSearch(str,val,mid,end,false);
	else
		chSearch(str,val,start,mid);
}
int binarySearch(string &str,char val)
{
	int length = str.length();
	if(val < str[0] || val > str[length-1])
		return -1;
	return chSearch(str,val,0,length-1);
}

- Anonymous June 19, 2013 | Flag Reply


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