Coprime Pick with Change Cost
Updated
Problem statement
Given an integer array arr and an integer maxValue, return the maximum score you can get.
You may change as many elements of arr as you like. Each change sets one element to any integer from 1 to maxValue and costs 1, including a change to the element you end up selecting.
After the changes, select one element that is coprime with every other element of the array. Two numbers are coprime when their greatest common divisor is 1. Your score is the value of the selected element minus the total cost of your changes.
Note: when arr has only one element, there is nothing else to compare it with, so it can always be selected.
Function
maxScore(arr: int[], maxValue: int) → intExamples
Example 1
arr = [6,10,15]maxValue = 15return = 13Keep 15 and change 6 and 10 to 1, since both share a factor with 15. The score is 15 - 2 = 13.
Example 2
arr = [4,6,8]maxValue = 8return = 6Change 4 to 7 and select it. 7 shares no factor with 6 or 8, so the score is 7 - 1 = 6. Keeping 8 and changing the other two elements also scores 8 - 2 = 6.
Example 3
arr = [10]maxValue = 10return = 10There is no other element, so 10 can be selected with no changes.
Constraints
1 <= arr.length <= 10001 <= maxValue <= 1091 <= arr[i] <= maxValue
More Citadel Online Assessment questions
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
- Busy IntersectionOA · Seen Sep 2026
- Shortest Path in an Unweighted GraphOA · Seen Sep 2026
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Image Processing CostOA · Seen Jul 2026
- Process SchedulingOA · Seen Mar 2026
- Social Media SuggestionsOA · Seen May 2025
- Best Sum Downward Tree PathOA · Seen May 2025
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMicrosoft · OAMicrosoft interview questions
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Resource AllocationMaven Securities · OAMaven Securities interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Total Batch ExpenseAmazon · OA
- Minimum Increments for Stepwise TowersZipRecruiter · OAZipRecruiter interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences