private int getMaxIntervalOverlapCountUsingCountingSort(
			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
		TimeInteger[] times = new TimeInteger[2 * intervals.size()]; // array of
																		// sorted
																		// times
		int timeInMinute;

		// Calculating frequencies
		for (int i = 0; i < intervals.size(); i++) {
			timeInMinute = intervals.get(i).getBeginMinuteUnit();
			countArray[timeInMinute]++;
			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, we insert end time to the sorted array first
		// because we want start time is "smaller" than end time if they have
		// the same integer representation
		for (int i = intervals.size() - 1; i >= 0; i--) {
			timeInMinute = intervals.get(i).getEndMinuteUnit();
			countArray[timeInMinute]--;
			times[countArray[timeInMinute]] = new TimeInteger(timeInMinute,
					false);
		}

		for (int i = intervals.size() - 1; i >= 0; i--) {
			timeInMinute = intervals.get(i).getBeginMinuteUnit();
			countArray[timeInMinute]--;
			times[countArray[timeInMinute]] = new TimeInteger(timeInMinute,
					true);
		}

		int count = 0;
		int maxOverlap = 0;

		for (int i = 0; i < times.length; i++) {
			if (times[i].isStartingTime()) {
				count++;
			} else {
				count--;
			}

			if (count > maxOverlap) {
				maxOverlap = count;
			}
		}

		return maxOverlap;
	}