Загрузка страницы

Merge Intervals | leetcode 56 | Company tag : Facebook , Amazon, Google

🔴 Code - http://thecodingworld.com/2020/06/01/merge-intervals/

🔴 Struggling solving leetcode question give yourself a 5 min break ➡️➡️ https://youtu.be/X1TgX0eoevM
🔴 TheCodingWorld is an initiative to give back to the community, We have started this channel to aid the student community to grasp different topics in computer science, with appropriate examples, particularized and comprehensive explanation.
The majority of our videos are about programming and interview preparation.
🔴 If you haven’t you should join our community

⬇⬇⬇⬇⬇⬇⬇

✅ 🤳🏻 📲 👨‍🏫 💬for early updates and Announcement 📢 - https://t.me/joinchat/AAAAAE6R3PLTMJWx05NvLg

✅ chat with me (Telegram)👨‍🏫💬 - https://t.me/joinchat/Lvim3BNQhw1wVPFOFSn09A

✅INSTAGRAM - https://instagram.com/thecodingworld?igshid=89hpqrtn8c7h

✅📬📧 Email - info.thecodingworld@gmail.com
problem description 📄📖

Given a collection of intervals, merge all overlapping intervals.

Example 1:

Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
Example 2:

Input: [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals [1,4] and [4,5] are considered overlapping.

Solution 📝

1) Sort all intervals in increasing order of start time.
2) Traverse sorted intervals starting from first interval,
3)Check if current interval overlaps with previous interval ( if starting of current is less or equal to ending of previous)
a) If current interval overlaps with previous interval, then merge it with previous interval (by updating the previous starting as {min(starting of previous, starting of current interval)} and ending as{ max(ending of previous, starting of current)}
b) Remove the current interval
4) return the intervals.

Resources 📖🗃

leetcode - https://leetcode.com/problems/merge-intervals/

if this video helped you in anyway please give it a thumbs up and subscribe for more such videos.

Видео Merge Intervals | leetcode 56 | Company tag : Facebook , Amazon, Google канала thecodingworld
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
14 октября 2019 г. 9:24:25
00:10:20
Яндекс.Метрика