Devesh Shukla’s Post

LeetCode: Longest Consecutive Sequence ✅ This problem real challenge is beating the naïve sorting approach. Strategy: Instead of sorting, I used a HashSet for constant-time lookups. The key idea is to only start counting a sequence when the current number does not have a predecessor (num - 1). From there, expand forward to count the full streak. This ensures every number is visited only once. 🕒 Time Complexity: O(n) — each element is processed at most once 📦Space Complexity: O(n) — extra space for the set 👉 The right data structure often matters more than clever loops. #LeetCode #DSA #JavaScript #ProblemSolving #LearnInPublic #CodingJourney #CSwithDev

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories