Company: Barclays
Difficulty: medium
Find Soldier ID at Kth Position body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; } .problem-container { max-width: 900px; margin: auto; padding: 20px; border: 1px solid #ddd; border-radius: 8px; background: #f9f9f9; } h1, h3 { color: #333; } pre { background: #f4f4f4; padding: 10px; border: 1px solid #ddd; border-radius: 5px; overflow-x: auto; } ul { margin: 0; padding-left: 20px; } .example { margin-top: 20px; } .example .input, .example .output { margin-bottom: 10px; } Find the Soldier\'s ID at Kth Position There are N soldiers standing in a line, with IDs from 1 to N in ascending order. The soldiers are participating in an exercise consisting of Q actions. During the i-th action, the Major calls two numbers, row i and col i . The soldiers at the row i -th and col i -th positions swap places, and this process continues until all specified positions swap as per the given input. Write an algorithm to find the ID of the soldier at the K -th position in the line aft