FastPrepIce Cream Sticks
Problems/Ice Cream Sticks

Ice Cream Sticks

Intuit logoIntuit● MediumINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Given an array A[] denoting heights of N ice cream sticks and a positive integer K, modify the height of each stick either by increasing or decreasing them by K only once and then find out the least difference in the heights between the shortest and longest sticks.

For example, consider that the heights are 0, 6, 11 and K=7. We can change 0 to 7, 6 to 9, and 11 to 4. The maximum difference is between 4 and 9, which is 5. We cannot minimise this difference.

Input

The first line of input contains a positive integer K. The second line of input contains a positive integer N, representing the number of sticks. The third line of the input contains N integers, representing the heights of N sticks.

Output

The minimum of the maximum difference of heights possible.

Function

getMinimumDifference(K: int, A: int[]) → int

Examples

Example 1

K = 2A = [2, 6, 9, 11]return = 5

Explanation: 2->4, 6->8, 9->7, 11->9. So, the maximum difference is 5 (9-4).

Example 2

K = 20A = [3, 4, 5]return = 2

3->23, 4->24, 5->25. So, the max different is 2(25-23).

Constraints

  • 0 < K <= 30 0 < N <= 30 0 <= A[i] <= 500

More Intuit interview questions

  • Number of IslandsONSITE INTERVIEW · Seen Nov 2026
  • VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
  • Parse Router LogsOA · Seen Oct 2026
  • Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
  • Maximum Square-Free DivisorOA · Seen Oct 2026
  • Two Tribes from Taller-Person CountsOA · Seen Oct 2026
  • Shortest Path from an Encoded GraphOA · Seen Sep 2026
  • Oldest and Youngest EmployeesOA · Seen Sep 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Maximize Center A Package BenefitAmazon · OA
  • EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions

Interview reports that mention this question

  • Intuit OA: What It Tests (2026)

Intuit interview experiences

  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public int getMinimumDifference(int K, int[] A) {
        // write your code here
    }

}
Checking account…