Company: Typeface_10sep
Difficulty: medium
Lock Code Problem Description You are given an array of integers codeSequence of length n and an integer maxValue . A locking system allows you to modify any number in the array to any integer less than or equal to maxValue at a cost of 1 per change. Two numbers are co-prime if their greatest common divisor (GCD) is 1. To unlock the repository, you need to select a number from the array that is co-prime with all other numbers in the array. The lock's code is calculated as the maximum possible value of: selected number - total modification cost Your task is to determine the lock code by selecting an optimal number from the array after modifications that is co-prime with all other numbers in the array. For example: n = 3 codeSequence = [3, 2, 4] maxValue = 6 Optimally: Change the element at the third position to 5 at the cost of 1 unit: codeSequence' = [3, 2, 5] . Choose the element 5 since it is co-prime with both 2 and 3. Calculate lock code = selected number - cost = 5 - 1 = 4. Return