### __SAK__'s blog

By __SAK__, history, 2 months ago,

Couldn't come up with a approach to this problem, please suggest some approaches

Specifically, Billy's N kids are tagged with ID numbers 1...N.

Billy wants to take a picture of the kids standing in a line in a very specific ordering, represented by the contents of an array A[1...N], where A[j] gives the ID number of the jth kid in the ordering.

He arranges the kids in this order, but just before he can press the button on his camera to snap the picture, up to one kid moves to a new position in the lineup. More precisely, either no kids move, or one kid vacates her current position in the lineup and then re-inserts herself at a new position in the lineup.

Frustrated but not deterred, Billy again arranges his kids according to the ordering in A, but again, right before he can snap a picture, up to one kid (different from the first) moves to a new position in the lineup.

The process above repeats for a total of five photographs before Billy gives up.

Given the contents of each photograph, see if you can reconstruct the original intended ordering A. Each photograph shows an ordering of the kids in which up to one kid has moved to a new location, starting from the initial ordering in A.

Moreover, if a kid opts to move herself to a new location in one of the photographs, then that kid does not actively move in any of the other photographs (although that kid can end up at a different position due to other kids moving, of course).


• 0

 » 2 months ago, # |   0 Which company hiring test problem? Mention the name of company and position offered and time of test so we know you aren't cheating.
•  » » 2 months ago, # ^ |   0 It was in Algo University test and it ended a couple hours ago
 » 2 months ago, # |   0 Auto comment: topic has been updated by __SAK__ (previous revision, new revision, compare).
 » 2 months ago, # |   0 What's the N's range?
•  » » 2 months ago, # ^ |   0 N <= 10^5