## subbu

BAN USERFor clarity on why a simple where with or wont work.

20 Action

21 Action

22 Comedy

21 Comedy

Supposed to return 21 as it is both Action and Comedy.

If the nested query in the loop sounds confusing, albeit something longer here

select g.id

from genre g, genre x

where g.id = x.id and

((g.Genre = 'Action' and x.Genre='Comedy') or (g.Genre='Comedy' and x.Genre='Action'))

You actually don't need Djisktra for this. The Length of the Jump doesn't need to be optimized, just the number of them.

We can create a graph, with edge I->J abd J<-I if j can be reached from I based on the number of Steps between I and J and what is allowed. And then we just find the shortest path from S - E in terms of number of nodes using BFS (Mark visited node, else will fail).

I am still wondering on the reason for the "can also jump backwards", if the number of jump lengths possible backwards is the same as forwards, I don't see how a shortest path will have a jump backwards. Even if the Jump backwards were different than forwards, I don't see how a shortest path will include a cycle. Added to confuse ?

Its recursive, basically do a bool Split(remainingArray, leftArray, RightArray, leftAverage, rightAverage).

At each round pull the next element and then call Split two times, once for adding it to left with updatedAverage etc. and once for Adding it to right. Whichever returns true return that value.

You can trace this against a simple 1, 2, 1.5 before you right the algorithm.

Its recursive, basically do a bool Split(remainingArray, leftArray, RightArray, leftAverage, rightAverage).

At each round pull the next element and then call Split two times, once for adding it to left with updatedAverage etc. and once for Adding it to right. Whichever returns true return that value.

You can trace this against a simple 1, 2, 1.5 before you right the algorithm.

Its recursive, basically do a bool Split(remainingArray, leftArray, RightArray, leftAverage, rightAverage).

At each round pull the next element and then call Split two times, once for adding it to left with updatedAverage etc. and once for Adding it to right. Whichever returns true return that value.

You can trace this against a simple 1, 2, 1.5 before you right the algorithm.

Should be easy to extend the Serialization and Deserialization mentioned for Binary to Nary (N needs to be known).

leetcode.com/2010/09/serializationdeserialization-of-binary.html

Instead of the two explicit Recursive calls in the Deserialization you do n Recursive calls.

Note: As n increases the number of Null Markers (#) takes more and more space. You can compress it with say #3 or so, and have the File.GetNextToken() interpret it and return # three times.

Should be easy to extend the Serialization and Deserialization mentioned for Binary to Nary (N needs to be known).

leetcode.com/2010/09/serializationdeserialization-of-binary.html

Instead of the two explicit Recursive calls in the Deserialization you do n Recursive calls.

Note: As n increases the number of Null Markers (#) takes more and more space. You can compress it with say #3 or so, and have the File.GetNextToken() interpret it and return # three times.

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Actually any one where should be good enough (Otherwise unnecessary duplicates and distinct).

- subbu August 17, 2014