public int getMaxWorkingTime(List<Interval> intervals) {
		if (intervals == null || intervals.size() == 0){
			return 0;
		}
		
		int[] countArray = new int[1441]; // There are at most 24*60+1 = 1441
											// different times
		times = new Interval[intervals.size()];

		int timeInMinute;

		// Calculating frequencies
		for (int i = 0; i < intervals.size(); i++) {
			timeInMinute = intervals.get(i).getEndMinuteUnit();
			countArray[timeInMinute]++;
		}

		// Accumulating
		int total = 0;
		for (int i = 0; i < countArray.length; i++) {
			countArray[i] = countArray[i] + total;
			total = countArray[i];
		}

		// Sort intervals based on end time
		for (int i = intervals.size() - 1; i >= 0; i--) {
			timeInMinute = intervals.get(i).getEndMinuteUnit();
			countArray[timeInMinute]--;
			times[countArray[timeInMinute]] = intervals.get(i);
		}

		// Initialization
		compatibleIntervals = new int[intervals.size()];
		for (int i = 0; i < compatibleIntervals.length; i++) {
			compatibleIntervals[i] = -1;
		}

		// For each interval i, find largest interval j that is compatible with
		// i such that j<i
		for (int i = 0; i < times.length; i++) {
			for (int j = i - 1; j >= 0; j--) {
				if (times[j].getEndMinuteUnit() < times[i].getBeginMinuteUnit()) {
					compatibleIntervals[i] = j;
					break;
				}
			}
		}

		maxWorkingTimes = new int[intervals.size()];

		return computeMaxWorkingTime(intervals.size() - 1);
	}