Adobe Interview Question for Computer Scientists


Country: India
Interview Type: In-Person




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

Number the words as has been done in the previous comment
Initial configuration is {5,2,3,1,4,6}
Final configuration is {1,2,3,4,5,6}

Constructing a graph with edges between final position & initial position we have
1->5
2->2
3->3
4->1
5->4
6->6

1->5->4->1 , 2->2 , 3->3 , 6->6

The answer will be the total number of nodes - the number of disconnected components
Here the answer is 6-4=2

This can be explained as follows,
In a component(which is always a cycle) of 'n' nodes, n-1 swaps would be needed

- sajaljain4 August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if there are repetitions, 123456 don't have any repetitions but in english text alphabets would repeat.

- Naveen Reddy Mandadi October 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can the swaps occur anywhere, or for adjacent words only?

- Anonymous July 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just as you said, it is " similar to minimum swaps to convert string A to string B." so would we be given the string B in this case, which is "we must go to newyork now"?

1. If yes, then the decisive solution is same as conversion of string A to string B which takes some help from the Longest Common Sub-sequence dynamic prog problem.

2. If no, then I don't see if there is any decisive solution..

- ramblersm July 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How is this remotely related to DP?

- Anonymous July 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use inversion count approach
step 1: assign a number t each word of string A
and step 2: apply inversion count
geeksforgeeks archive : archives/3968

- bhavesh July 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you pls explain in detail...
Thanks in Advance..

- TeachLead July 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeah, true...

- Birbal October 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

good solution bhavesh
@TechLead
We can assign a number to each word in the correct sentence
e.g.:
we must go to newyork now
we - 1
must - 2
go - 3
to - 4
newyork - 5
now - 6

do this using a map
now for the senetence spoken by yoda
"Newyork must go we to now"
create an int array storing numbers for the corresponding words
array would be {5,2,3,1,4,6}

count the number of inversions as done here: www[dot]geeksforgeeks[dot]org/archives/3968

- Tushar July 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Though this is nice approach, finding inversion wont give you minimum swaps required.but we can get minimum swaps form this new array.

- Deepak July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yeah... sorry

- Tushar July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question of minimum number of swaps can be asked only if the resultant sentence(correct one) is given.

- season August 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You see this in your mirror reflection

- Anonymous January 15, 2014 | 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