Microsoft Interview Question for Software Engineer / Developers






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

First method:

You use an array of size 256-initialized to 0(considering ascii), in pass one increment corresponding element for each occurance in input string.

In second pass see whether the element occurs exactly once, in that case return the element. complexity - 2n - 0(n)

2nd way:

Make a copy of the input string, sort this copied version.
make a pass through input string, for each character determine in logn times whether it occurs once or more times.

Complexity 0(nlogn)

Is there any better soln???

- jason November 11, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Non-duplicate implies it appears an odd # of times(1). Assume a duplicate is at most 2. XOR from left to right to get a result K. Then XOR K to find the missing duplicate. This is O(n) running time and O(1) space. (a^b)^a = a ^(b^a) because XOR is a 1-1 function.

- Jack January 25, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What do you have in your breakfast? weed?

- Jack ass November 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

both of jason's way work although they both require o(n) space.

Jack's way doesn't solve this problem because you can't assume that there is only one non-duplicate nor that any duplicates only have two instances.

o(n^2) time and o(1) space algorithm also exists.
o(n) time and o(n) space algorithm exists (Jason's).

Are there any better algorithms?

- Anonymous February 18, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Jason's method 1 gives O(1) space.. It always takes a[256] and doesnt change depending on the size of the string..

- Anonymous October 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a Hash table...
Has string twice to check which is non duplicate

- MaVeRiK July 26, 2009 | 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