FastPrepMaximum Later Difference
Problems/Maximum Later Difference

Maximum Later Difference

Apple logoApple● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple new grad online assessment. The later-larger rule, the sample, and the -1 result are about 98% the same as the report. The report is for a 12-month graduate placement. We chose limits for signed values.

Given nums, return the largest difference nums[j] - nums[i] over indices i < j with nums[j] > nums[i].

If no such pair exists, return the no-pair value -1. Equal values do not form a valid pair.

Function

maximumLaterDifference(nums: int[]) → int

Examples

Example 1

nums = [3,6,10,1,4,6,5]return = 7

Ten comes after three, and no other pair has a larger difference, so the answer is seven.

Example 2

nums = [5,5,4]return = -1

Each later value is equal to or smaller than every earlier one, so no valid pair exists and the answer is the no-pair value.

Constraints

  • 1 <= nums.length <= 10^5.
  • -10^9 <= nums[i] <= 10^9.

More Apple interview questions

  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge Two Strings by Maximum Boundary OverlapOA · Seen Sep 2026
  • Collect Letters Along a Unique Grid PathOA · Seen Aug 2025
  • Maximum Weight in Two BagsOA · Seen Aug 2025
  • Ignore SectionsOA · Seen Mar 2024
  • Gas Station Circular TourOA · Seen Nov 2021
  • House Robber IIOA · Seen Nov 2021
  • Clone an Undirected Graph StateOA · Seen Mar 2021
  • Longest Increasing Subsequence LengthOA · Seen Feb 2021
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Server InvestmentRippling · OARippling interview questions
  • Book Reading EveningsGoogle · OAGoogle interview questions
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Minimum Project Bid CostNVIDIA · OANVIDIA interview questions
  • Minimum AmountBelvedere Trading · OA
  • Maximum Income from Asset TradingJefferies · OA
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Economical TripAccenture · OAAccenture interview questions
  • Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions

Interview reports that mention this question

  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE Interviews: 37 Experiences (Part 1 of 3)

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int maximumLaterDifference(int[] nums) {
        // Write your solution here.
    }

}
Checking account…