FastPrepTotal Years of Work Experience
Problems/Total Years of Work Experience

Total Years of Work Experience

LinkedIn logoLinkedIn● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: In LinkedIn's first phone screen for a staff AI engineer, the coding task worked from a person's employment history, where each role has a starting and a finishing month, and wanted a whole-number count of years worked. Two points needed settling with the interviewer: roles that run at the same time, and roles that are still ongoing. The candidate saw it as a merge-intervals exercise.

The report did not give the input format or the answers to those questions. Practice choices here: months are written YYYY-MM between 1970 and 2099, both the start and end months count, overlapping months count once, Present means through a given current month, the answer is the number of distinct months divided by 12 and rounded down, and there are up to 200 jobs.

The judged task matches the report at about 80%.

A profile lists a user's jobs. experiences[i] = [start, end] means the user worked from month start through month end, both included. An end of "Present" means the job is ongoing and lasts through currentMonth.

Jobs may overlap, and a month in which the user held several jobs counts only once. Count the distinct months worked and return the total years of experience as a whole number: the number of months divided by 12, rounded down.

Function

totalYearsOfExperience(experiences: String[][], currentMonth: String) → int

Examples

Example 1

experiences = [["2015-01","2017-12"],["2017-06","2019-12"],["2021-01","Present"]]currentMonth = "2026-06"return = 10
  • The first two jobs overlap, so together they cover January 2015 to December 2019: 60 months.
  • The third job runs from January 2021 to the current month, June 2026: 66 months.
  • The total is 126 months, which is 10 full years (126 / 12 rounded down).

Example 2

experiences = [["2020-03","2020-03"]]currentMonth = "2024-01"return = 0
  • One month of work is 0 full years.

Example 3

experiences = [["2010-01","2010-12"],["2011-01","2011-12"]]currentMonth = "2012-05"return = 2
  • Back-to-back jobs cover 24 months with no gap: 2 years.

Constraints

  • 1 <= experiences.length <= 200
  • experiences[i].length == 2
  • Every month is written "YYYY-MM" with a year from 1970 to 2099; an end may also be "Present".
  • For every job, start <= end <= currentMonth (with "Present" read as currentMonth).

More LinkedIn problems

  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
  • Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public int totalYearsOfExperience(String[][] experiences, String currentMonth) {
        // Write your code here.
    }
}
Checking account…