FastPrepCoprime Pick with Change Cost
Problems/Coprime Pick with Change Cost

Coprime Pick with Change Cost

Citadel logoCitadel● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel Securities online assessment for a student software engineer role in mid 2026, as one of two problems in a 75-minute test. You may change numbers in an array at a price of 1 each, then pick one number that has no common factor with any of the others, and you want that number minus the total price to be as large as possible.

The report gives no examples. It does not say whether changing the picked number also costs 1. Here it does. We also keep every new value between 1 and maxValue, which never changes the answer. The examples are ours.

Our version is about 95% the same as the reported question.

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) → int

Examples

Example 1

arr = [6,10,15]maxValue = 15return = 13

Keep 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 = 6

Change 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 = 10

There is no other element, so 10 can be selected with no changes.

Constraints

  • 1 <= arr.length <= 1000
  • 1 <= maxValue <= 109
  • 1 <= 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
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int maxScore(int[] arr, int maxValue) {
      // Write your code here.
    }
}
Checking account…