Time Travel

Problem Overview

  • Task: given a list of years visited in order starting at years[0], find the total travel time.
  • Input: years array (length 1–100, values 1–10^4); Output: integer hours.
  • Per-hop rules: same year = 0 hours, future year = 1 hour, past year = 2 hours.
  • Real-world context: time-travel journey planning across historical years.
  • From Ziprecruiter interviews; a coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: