Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

The question looks very tough but becomes easy with the following observation.
First we rotate the source string (left or right) to get the maximum match with target. Then change the mismatch characters. If there are n characters in the string then the complexity will be:
1) n times we rotate the array and do n comparison for each rotation = O(n^2)
2) one scan of both source and target to change the mismatch = O(n)
But i guess the n^2 complexity is still very poor. Looking forward to a smarter algorithm for it.
Once we have the minimum number of steps it can be done then we can verify if it can be done in the given number of steps in input.

- kr.neerav February 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi,

The problem is to find whether the said operation can be done in the given steps, if it is to find the lowest number of steps needed it would be simple,

It would get harder in this case, say you rotated once and changed one character and you already got the destination (2 steps) and the given number of steps is 4, what you can now do is, change one character twice to make it 4 steps and the answer would be yes..

he specifically told to check only if its possible with the given number of steps or not.. he is not worried if it can be solved with lower number of steps :)

- hari.r.krishnaa February 10, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Agreed. First we need to find out in how many steps it can be done. If the number of steps in the input is less than that then it cannot be solved.
If greater then find the number of extra steps. If its even then we can solve the problem in the given number of steps (one step to change something and other to undo that). If odd then it cannot be solved.

- kr.neerav February 10, 2014 | 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