Day 19: Longest Consecutive Sequence (LeetCode 128) — HashSet | O(n)
Автор: Ashwini Kemshetty
Загружено: 2026-01-30
Просмотров: 11
Описание:
🎯 Day 19 of My LeetCode Journey | Longest Consecutive Sequence (LeetCode 128)
In this video, I solve LeetCode Problem #128 — Longest Consecutive Sequence using a HashSet to achieve an optimized O(n) solution.
The goal is to find the length of the longest sequence of consecutive numbers in an unsorted array.
🔗 Problem Link:
https://leetcode.com/problems/longest...
📌 PROBLEM SUMMARY:
Given an array of integers nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in O(n) time.
✅ Example 1:
Input: nums = [100, 4, 200, 1, 3, 2]
Output: 4
Explanation: The longest consecutive sequence is [1, 2, 3, 4].
✅ Example 2:
Input: nums = [0,3,7,2,5,8,4,6,0,1]
Output: 9
💡 KEY CONCEPTS:
✅ HashSet for fast lookup
✅ Consecutive sequence detection
✅ Avoiding repeated scans
✅ Optimal O(n) strategy
📊 COMPLEXITY:
• Time: O(n)
• Space: O(n)
🎓 DIFFICULTY: Medium
🏷️ TOPICS: Hash Table, Array, Set, Greedy
🔔 SUBSCRIBE for daily LeetCode solutions and coding challenges!
👍 LIKE if you found this helpful!
💬 COMMENT your thoughts or variations!
📚 MY LEETCODE JOURNEY PLAYLIST:
• Leetcode
🤝 CONNECT WITH ME:
• GitHub: https://github.com/ashwinikemshetty
• LinkedIn: / ashwinikemshetty
#LeetCode #LongestConsecutiveSequence #LeetCode128 #Day19 #HashSet #Array #DSA #Algorithms #100DaysOfCode
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: