Company: Capital One_30june
Difficulty: medium
Time Machine Travel Cost Problem Description Imagine that you have a time machine. You are given an array years . You start in the year years[0] . First, you want to travel to years[1] , then to years[2] , and so on. Your task is to calculate the total time required to visit all the years from the list in order. The time required to travel from year A to year B is calculated as follows: 0 hours if A = B 1 hour if A < B (going forwards in time) 2 hours if A > B (going backwards in time) Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(years.length 2 ) will fit within the execution time limit. The input years is an array of integers representing the list of years to travel through. The output is an integer representing the total number of hours required to visit all the given years in order. Execution time limit: 0.5 seconds (C++) Memory limit: 1 GB Examples Example 1: Input: years = [2000, 1990, 2005, 2050] Outpu