Adobe Interview Question for Software Engineer / Developers






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

you can publish a paper if you solve it ten years ago

And I doubt the author of that paper couldn't come up with the solution within 20 mins or so

such interview question is nonsense

- geniusxsy January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can publish a paper if you solve it ten years ago

And I doubt the author of that paper couldn't come up with the solution within 20 mins or so

such interview question is nonsense

- geniusxsy January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What do you mean? Why don't you just walk trough the string and find N. Then construct another string like

ret = ""
for i in range(1, n+1):
   ret += 'a' + i + 'b' + i
return ret

Am I misunderstanding the question?

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Really a moron !!!

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

O(n) or O(1) space ?

- Silence January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(n) space is trivial.

- Anonymous January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it even possible to do it in O(n) time and O(1) space?

- Anonymous January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there's a published paper devoted to the solution.

- geniusxsy January 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why dont you give us link to that paper.. or provide the solution here...

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it simply implies this question is nonsense and you can safely skip it

btw, i don't have the link, I just had a look at the paper a few months ago and deleted it after browsing through the paper.

- geniusxsy January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Asking for O(n) time and O(1) space is silly indeed.

But try an O(nlogn) time and O(1) space algorithm. Might interest you.

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It would just be a sorting algorithm. Check en.wikipedia.org/wiki/Sorting_algorithm and find what you want. (Heap sort, In-Place Merge sort)

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

WTF are you talking about? While you are there check out: en.wikipedia.org/wiki/Stupidity

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Has it to be in place? [without using any extra space, I mean]

- Aats January 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

With O(1) extra space.

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use recursive solution by dividing the array into two and merge the re-arranged two sub-arrays.

- Anonymous January 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what a moron

- Anonymous January 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

that is exactly you are

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

agree. Moron is always a jerk and think others as moron

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Interviewer asked How to convert it by swapping variables ??

- Anonymous January 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

consider the following psudo code

re-arrange(int * p, int size) {
if (size == 4) {
swap(p[1], p[3])
}
if (size == 3) {
return;
}
re-arrange(p, size/2);
re-arrange(p + size/2, size/2);

for(int i = 1; i < size/4; i++) {
int nSwap = p[2*i];
p[2*i] = p[2*i + size/2 - 1] ;
p[2*i + size/2 - 1] = nSwap ;
}
}

Essentially, if we chang the array a1a2...aNb1b2...bN->a1a(N/2+1)a2a(N/2+2)a3a(N/2+3)..a(N/2)aN b1b(N/2+1)b2b(N/2+2)...b(N/2)bN. By swapping the a(N/2) with b1, a(N/2+1) with b2... aN with b(N/2-1) is the array we need. In addition, the two subarry a1a(N/2+1)a2a(N/2+2)a3a(N/2+3)..a(N/2)aN and b1b(N/2)b2b(N/2+1)...b(N/2-1)bN can be considerd as the same re-arrange of a1a2...a(N/2)c1c2...c(N/2) (c1 = a(N/2+1), c2=a(N/2+2).. c(N/2) = aN). However, we need to consider the case N is an odd number though.

With the approach, the solution can be solved in O(N) time and O(1) space

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even if correct, this is O(n log n).

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

assume this solution is f(n). Then f(n) = f(n/2) + f(n/2) + O(n/4). f(n) = 2f(n/2) + O(n/4). if f(1) = f(2) = f(3) = f(4) =1. Then, f(n) = O(n)

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(1) space solution is required and you give a recursive method? Well... that solution is kind of, er... moronic.

There are too many crap posts on this site, I can sympathise with the person who said moron, but nothing justifies an attack on the person instead of the idea.

Everyone does stupid things some of the time. It does not mean they are completely stupid.

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi, Moron,

why recursive cannot be O(1) space. You claim is truely moronic

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Tail Recursive can be transformed to O(1) algorithm perhaps. But otherwise no.

btw, did you even read the whole thing?

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

consider the following psudo code

re-arrange(int * p, int size) {
if (size == 4) {
swap(p[1], p[3])
}
if (size == 3) {
return;
}
re-arrange(p, size/2);
re-arrange(p + size/2, size/2);

for(int i = 1; i < size/4; i++) {
int nSwap = p[2*i];
p[2*i] = p[2*i + size/2 - 1] ;
p[2*i + size/2 - 1] = nSwap ;
}
}

Essentially, if we chang the array a1a2...aNb1b2...bN->a1a(N/2+1)a2a(N/2+2)a3a(N/2+3)..a(N/2)aN b1b(N/2+1)b2b(N/2+2)...b(N/2)bN. By swapping the a(N/2) with b1, a(N/2+1) with b2... aN with b(N/2-1) is the array we need. In addition, the two subarry a1a(N/2+1)a2a(N/2+2)a3a(N/2+3)..a(N/2)aN and b1b(N/2)b2b(N/2+1)...b(N/2-1)bN can be considerd as the same re-arrange of a1a2...a(N/2)c1c2...c(N/2) (c1 = a(N/2+1), c2=a(N/2+2).. c(N/2) = aN). However, we need to consider the case N is an odd number though.

With the approach, the solution can be solved in O(N) time and O(1) space


assume this solution is f(n). Then f(n) = f(n/2) + f(n/2) + O(n/4). f(n) = 2f(n/2) + O(n/4). if f(1) = f(2) = f(3) = f(4) =1. Then, f(n) = O(n)

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is idiotic solution.

This is not O(n) time. It is O(n log n).

f(n) = 2f(n/2) + O(n) is O(n log n).

And what about when n is odd?

And as posted, the solution is not even O(1) space.

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi, Moron,

Looks who is the moron now

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi, Moron,

Looks who is the moron now

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess the solution the interviewer wants is the one replace the above recursive to while loop

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Guys!

The recursive solution is NOT O(n).

f(n) = 2f(n/2) + O(n) is NOT O(n). IT is O(nlogn).

Lookup master theorem in CLR.

You guys seriously need to do some fundamental reading.

As for the comment about while loop, I agree, the given recursive method can be rewritten so that O(1) space is used, but it is not O(n) and does not even work for all n.

I can say that I would confidently reject the candidate...

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adobe are a bunch of morons because unlike the published O(n) solution, the O(n log n) solution is cache-oblivious and thus almost certainly faster on real computers.

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

On real computers you just create a new array and be done with!

btw, what is the published solution? Care to provide a link?

Thanks.

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

...and then you start swapping because the data set just barely fit in memory.

The following survey was high in the Google results for "in-place merge": www . logiccoder . com / Downloads / krnrd20.pdf . I haven't read it though.

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL. Talking about memory and swapping without even knowing where it will be used.

the link you posted is IRRELEVANT. Read the question again, or perhap do a quick scan of the link you gave.

- Anonymous January 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I did scan it. If you can't figure out why it's relevant, then you might be a moron.

- Anonymous January 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Better link (previous Anonymous is a moron): In-place_matrix_transposition on wikipedia

- Anonymous January 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Here is one link which seems relevant: //arxiv.org/abs/0805.1598

the pdf link from logic coder site is useless and person posting it is an arrogant, moronic turd.

- Anonymous January 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

On real computers, you just create a new array and be done with it :)

btw, what is the published solution? I can't seem to find it.

Thanks.

- Anonymous January 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ok Morons... Here's an O(n) time, O(1) space approach:

- Read the first string sequentially to determine, N, {l[1],l[2],....,l[k]} and store l[1], l[k], N. l[1]=a, l[2]=b, .... l[k]=some letter.
- Write the first string in place in a loop...
for(i=1;i<N;i++) { for (j=l[1];j<l[k];j++) { output j; output i; }

- Anonymous January 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
void shuffle (char arr[], int lower, int size)
{
int i = lower;
int mid = size/2;

while (mid < size) {
int temp = arr[mid];
for (int j = mid; j > i; j--) {
arr[j] = arr[j-1];
}
arr[j+1] = temp;
mid++;
i += 2;
}
}
}

- Anonymous January 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
void shuffle (char arr[], int lower, int size)
{
int i = lower;
int mid = size/2;

while (mid < size) {
int temp = arr[mid];
for (int j = mid; j > i; j--) {
arr[j] = arr[j-1];
}
arr[j+1] = temp;
mid++;
i += 2;
}
}
}

- Anonymous January 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

here time complexity will be O(n X n) but the question is to do it in O(n).

- gourch January 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think this can be solved using in-place quicksort's algorithm for conquerring.. (i.e. have a pointer point to the start of a_i array and another pointed at the end of b_i). Then, the problem is simply to swap elements and increment the pointer that received the swap. Equality would be defined for a_i < b_j where i < j.
a_i < a_j and b_i < b_j where i<j.

If the elements violate the rules above, then swap. Otherwise, increment the last pointer that received a swap.

- Anonymous January 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why not try it out to see if this is right?

- Anonymous January 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Some one started it and now every one calling others moron.

- Anonymous January 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Probably just the two who are having a public fight.

- Anonymous January 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is possible with using below algorithm. With Constant space. i.e have 3 indexes

one @ index=i aN, another j @ bN and third index @end of the array (which initially points to end of the array )
Now for every iteration swap and make sure that i, j are poiting to right index that are to be swapped next time. and index = index -2;

Continue till index > 0. Should be doable in o(n/2) =~ o(n).

- master January 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is a O(1) space O(n^2) solution. I'll just give an example:

Say the string is:
1 2 3 4 5 a b c d e. We just swap pairwise from middle to the outside, like so:
1 2 3 4 a 5 b c d e //swap the middle only
1 2 3 a 4 b 5 c d e //swap the middle 2
1 2 a 3 b 4 c 5 d e //swap the middle 3
1 a 2 b 3 c 4 d 5 e //swap the middle 4 and we are done

- memo June 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="java" line="1" title="CodeMonkey87687" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}

</pre><pre title="CodeMonkey87687" input="yes">1
2
10
4909
11

</pre>

- Anonymous June 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How abt this?
let each node "a1" "a2" b1 b2 be a node in link list.
step1 . reach mid point (cliched slow and fast pointer).
keep 2 pointers at start and at mid.

step 2. Call insertAfter first pointer and keep moving the pointer to b[i] also note that Ai will now move two steps next->next while Bi will move only next.
maintain the invariant till the first pointer reaches mid. then we are done

- Amit Priyadarshi September 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i agree wid this sol. LL is the best way to solve tis question! tat was a nice suggestion :)

- aravind646 November 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think most people are comparing this with a general case merge which is pretty hard to do inplace with constant space. However this one is pretty trivial. Consider this.

assume N = 4 as an example
v = [ 0 , 2 , 4 , 6 , 1 , 3 , 5 , 7 ]

It is easy to see that for i = 0 and i = 7 element are in the right place.
if ( i < 4 ) it should go in the 2 * i slot
if ( i >= 4) it shoudl go in the ( i - 4 ) *2 + 1 slot.

With this in mind you take a element try to put it in its right slot. Now you the element you removed from right slot has to be the next one you put in the right slot.

const int N = 10;

int GetNewIndex( int oldIndex )
{
	if ( oldIndex < N )
		return 2 * oldIndex ;

	return (oldIndex -N ) * 2 + 1;
}

void InplaceMerge( vector<int> & arr )
{
	int j = 1;
	int temp = arr[j];
	for ( int i = 1 ; i < (2*N-1) ; ++i )
	{
		int z = GetNewIndex( j );
		int newtemp = arr[z];
		arr[z] = temp;
		j = z;
		temp = newtemp;
	}
}

- Anonymous September 30, 2011 | 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