Find ID of Soldier

Asked at HSBC · Coding Questions · Difficulty: Easy

There are N soldiers standing in a line, with IDs from 1 to N, in ascending order. They are participating in an exercise consisting of Q actions. During the i-th action, the Major calls two numbers `row` and `col`. The soldiers at the `row`-th and `col`-th positions swap places, then `row+1` and `col-1`, and so on while `row+m < col-m` — i.e. the segment of positions `[row, col]` is reversed. Each soldier's ID is covered by the range `[row, col]` for at most one action (the ranges do not overlap).

Loading the problem…