Company: Intuit_3march
Difficulty: medium
Ship Locks A ship has n doors with locks. For the crew to board, all doors must be unlocked, which happens only when all locks have the same value. The array locks represents n locks, where locks[i] is the initial value of the i th lock. In one operation, you can change a lock's value according to these rules: If current value = 1, next value can be k or 2 If current value = k , next value can be k - 1 or 1 Otherwise, next value can be current value - 1 or current value + 1 Find the minimum number of operations needed to make all lock values the same. Example k = 100 n = 3 locks = [1, 2, 99] Optimal strategy (making all locks have value 1): Lock 1 (value 1): No operations needed Lock 2 (value 2): One operation to change 2 → 1 Lock 3 (value 99): Two operations to change 99 → 100 → 1 Total minimum operations required: 0 + 1 + 2 = 3 Function Description Complete the function minOperations in the editor with the following parameter(s): int k : an integer int locks[n] : the i