FastPrepClassify Natural-Month Distance Between Dates
Problems/Classify Natural-Month Distance Between Dates

Classify Natural-Month Distance Between Dates

Apple logoApple● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report asks for comparison against one natural calendar month. It does not define reversed inputs or unequal month lengths, so this exercise orders the dates and uses a clamped monthly anniversary.

Given two valid Gregorian calendar dates firstDate and secondDate in YYYY-MM-DD format, return whether the later date is less than, exactly, or more than one calendar month after the earlier date.

The input order does not matter: let earlier be the smaller date and later the larger date. The one-month anniversary of earlier is the same day in the next calendar month. If the next month has no such day, use that month's last day instead. Use the standard Gregorian month lengths, including February's leap-year length.

Compare later with the anniversary and return exactly one of:

  • LESS_THAN_ONE_MONTH
  • EXACTLY_ONE_MONTH
  • MORE_THAN_ONE_MONTH

This is a calendar comparison, not a count of elapsed days. Time zones do not apply.

Function

classifyNaturalMonthDistance(firstDate: String, secondDate: String) → String

Examples

Example 1

firstDate = "2026-01-15"secondDate = "2026-02-14"return = "LESS_THAN_ONE_MONTH"

One month after January 15 is February 15. February 14 comes before that, so the answer is LESS_THAN_ONE_MONTH.

Example 2

firstDate = "2026-01-31"secondDate = "2026-02-28"return = "EXACTLY_ONE_MONTH"

February has no day 31 in 2026, so the anniversary of January's last day is February 28. The later date is exactly that day, so the answer is EXACTLY_ONE_MONTH.

Example 3

firstDate = "2026-03-30"secondDate = "2026-02-28"return = "MORE_THAN_ONE_MONTH"

The earlier date is February 28, so its anniversary is March 28. March 30 comes after that, so the answer is MORE_THAN_ONE_MONTH.

Constraints

  • Both inputs are valid Gregorian dates in zero-padded YYYY-MM-DD format.
  • 1900-01-01 <= firstDate, secondDate <= 2100-12-31.
  • The two dates may be supplied in either order and may be equal.

More Apple Onsite Interview questions

  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • FIFO Mutex Operation TraceONSITE INTERVIEW · Seen Oct 2026
  • Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
  • Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
  • BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Clock Hand Angle with Subsecond PrecisionScale AI · ONSITE INTERVIEWScale AI interview questions
  • Transaction Fee Calculator — Channel Volume TiersStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Segmented Durable Key-Value StoreOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Babysitter Quote with Hourly RatesUpstart · ONSITE INTERVIEWUpstart interview questions
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions
  • Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
  • Reservoir Sampling with Recorded DrawsMeta · ONSITE INTERVIEWMeta interview questions
  • Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW

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
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String classifyNaturalMonthDistance(String firstDate, String secondDate) {
        // Write your code here.
    }
}
Checking account…