📖 Scenario: You are working on a calendar app that manages meeting times. Sometimes meetings overlap, and you want to combine those overlapping meetings into one longer meeting to avoid confusion.
🎯 Goal: Build a program that merges overlapping intervals from a list of meeting times and prints the merged intervals.
📋 What You'll Learn
Create an array of intervals with exact values
Add a variable to store the number of intervals
Implement the logic to merge overlapping intervals
Print the merged intervals in the format: [start, end]
💡 Why This Matters
🌍 Real World
Merging overlapping intervals is useful in calendar apps, booking systems, and timeline visualizations to avoid conflicts and show clear schedules.
💼 Career
Understanding interval merging helps in software development roles involving scheduling, data processing, and algorithm design.
Progress0 / 4 steps
1
Create the initial intervals array
Create an array called intervals of type int[][2] with these exact intervals: {1, 3}, {2, 6}, {8, 10}, {15, 18}.
DSA C
Hint
Use curly braces to define each interval inside the array.
2
Add the number of intervals variable
Create an int variable called n and set it to 4, the number of intervals in intervals.
DSA C
Hint
Count how many intervals are in the array and assign that number to n.
3
Implement merging logic
Write code to merge overlapping intervals from intervals using n. Store merged intervals in merged array and keep count in mergedCount. Use a simple sorting and merging approach.
DSA C
Hint
Sort intervals by start time, then merge by comparing current interval start with last merged interval end.
4
Print merged intervals
Print each merged interval from merged array using mergedCount. Format each interval as [start, end] on its own line.
DSA C
Hint
Use a for loop to print each merged interval with printf.
Practice
(1/5)
1. What is the main goal of the Merge Overlapping Intervals problem?
easy
A. Find the maximum number of intervals without overlap
B. Sort intervals by their end times only
C. Combine all intervals that overlap into one continuous interval
D. Count how many intervals are in the list
Solution
Step 1: Understand the problem goal
The problem asks to merge intervals that overlap, so they become one continuous interval without gaps.
Step 2: Identify the correct description
Combine all intervals that overlap into one continuous interval correctly describes merging overlapping intervals into one combined interval.
Final Answer:
Combine all intervals that overlap into one continuous interval -> Option C