Google | Sort Objects Based on Conditions
Anonymous User
2102

I was asked the following question in google phone screen round, but I had no idea on how to proceed. Any inputs will be much appreciated.

Given list of objects-
{a, b, "right"} --> a is to the right of b
{c,b, "right"} --> c is to the right of b
{b,a, "left"} --> b is to the left of a

sort them based on left and right conditions.

output any valid output.
one valid output is - b, a, c

I thought of using a linked list, but it'll be too complex to check for each and every condition of left/right.

Comments (9)