```ts
export function mergeIntervals(intervals: number[][]): number[][] {
  if (intervals.length === 0) return [];

  // Validate intervals and create a copy of them
  const validatedIntervals = intervals.map(([start, end]) => {
    if (start > end) throw new Error("Interval start cannot be greater than end");
    return [start, end];
  });

  // Sort intervals by start time
  validatedIntervals.sort((a, b) => a[0] - b[0]);

  const merged: number[][] = [];
  let currentInterval = [...validatedIntervals[0]];

  for (let i = 1; i < validatedIntervals.length; i++) {
    const [start, end] = validatedIntervals[i];
    if (start <= currentInterval[1]) {
      // Intervals overlap or touch, merge them
      currentInterval[1] = Math.max(currentInterval[1], end);
    } else {
      // No overlap, add the current interval to merged and move to next
      merged.push([...currentInterval]);
      currentInterval = [start, end];
    }
  }

  // Add the last interval
  merged.push([...currentInterval]);

  return merged;
}
```