𝐃𝐚𝐲 87/100 – 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 🚀 Problem: 228. 𝐒𝐮𝐦𝐦𝐚𝐫𝐲 𝐑𝐚𝐧𝐠𝐞𝐬 Today I solved a problem where we need to summarize consecutive numbers in a sorted unique array into ranges. 🔑 𝐈𝐝𝐞𝐚: Traverse the array and keep extending the range while consecutive numbers continue. Once the sequence breaks, close the range and store it. 💡 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Start with the first element as start Move forward while nums[i] + 1 == nums[i+1] If range exists → "start->end" Else → single number "start" 𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Efficient single pass solution (O(n)) by grouping consecutive elements on the fly. #LeetCode #Java #ProblemSolving #DSA #100DaysOfCode #CodingJourney
Summarize Consecutive Numbers in Sorted Array
More Relevant Posts
-
🚀 Day 61/100 Today’s problem: Check Balanced String 📌 Problem Summary: A string is called balanced if the sum of digits at even indices is equal to the sum at odd indices. 💡 What I learned: - How to handle index-based logic - Difference between even & odd indexing - Clean iteration and condition checking 🧠 Approach: - Traverse the string - Maintain two sums → even index & odd index - Compare both sums ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(1) Consistency is the key — small steps every day lead to big results 💪 #Day61 #CodingJourney #Java #DSA #ProblemSolving #Consistency #KeepLearning #100DaysOfCode
To view or add a comment, sign in
-
-
Day 25/100: Finding the "Gap" 🎯 Today's challenge: Search Insert Position. We all know Binary Search finds an element in O(log n), but what if the element isn't there? I learned that by the end of the search, the `left` pointer doesn't just give up—it points exactly to where that missing number *should* be inserted to keep the array sorted. It’s a powerful way to handle dynamic data without breaking the order. Quarter of the way through the challenge! 🚀 #100DaysOfCode #Java #DSA #BinarySearch #ProblemSolving #Unit3 #Day25 #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 64/100 Today’s problem: Find all strings that are substrings of another word 🧠 What I learned: - How to compare strings using nested loops - Using ".contains()" to check substrings efficiently - Importance of breaking early to optimize performance - Strengthening problem-solving with brute-force approach 💡 Key Insight: Sometimes simple solutions (O(n²)) are enough when constraints are small. No need to overcomplicate! 🔁 Consistency > Perfection #Day64 #DSA #Java #CodingJourney #Consistency #KeepLearning #100DaysOfCode
To view or add a comment, sign in
-
-
Day 59 - Merge Two Sorted Lists Worked on merging two sorted linked lists into one sorted list. Approach: • Used a dummy node to simplify pointer handling • Compared nodes from both lists and attached the smaller one • Appended remaining elements after traversal A classic linked list problem that strengthens pointer manipulation skills. Time Complexity: O(n + m) Space Complexity: O(1) #Day59 #LeetCode #Java #LinkedList #CodingPractice #DSA #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 48 of My #LeetCode Journey Today’s problem: 2615. Sum of Distances 💡 Key Idea: Instead of calculating distances between equal elements using brute force (O(n²)), I used: HashMap to group indices of same values Prefix Sum to efficiently compute distances This reduced the complexity to O(n) 🔥 🧠 What I Learned: How prefix sums can optimize distance calculations Efficient handling of repeated elements Writing clean and optimized code using Java ⚡ Approach: Store indices of each number Use prefix sums to calculate left & right distances Combine both to get final answer 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) Consistency is key. Small progress every day leads to big results 💪 #Day48 #Java #FullStackDeveloper #CodingJourney #100DaysOfCode #DSA #LeetCode
To view or add a comment, sign in
-
Day 32 of #50DaysLeetCode Challenge 💻🔥 Today I solved the “Rotate Image” problem using Java. 🔹 Problem: Given an n × n matrix, rotate the image 90° clockwise in-place (no extra matrix allowed). 🔹 Where people mess up: Trying to simulate rotation directly with extra space. That defeats the whole point of the problem. 🔹 Optimal Approach: 1. Transpose the matrix (swap rows & columns) 2. Reverse each row That’s it. Two clean steps. No overthinking. 🔹 Key Insight: Rotation isn’t magic — it’s just a combination of simple transformations. 🔹 Time Complexity: O(n²) 🔹 Space Complexity: O(1) 📌 What I learned: Most matrix problems look complicated until you break them into small predictable operations. If your approach feels messy, you’re probably doing it wrong. Simple > Clever. #Day32#LeetCode #Java #Matrix #DSA #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 58 of #100DaysOfCode Solved – Check Balanced String 🔍 What I did: Traversed the string and calculated the sum of digits at even and odd indices separately, then compared both sums to determine if the string is balanced. 💡 Key Learning: Practiced string traversal and indexing Improved understanding of even vs odd index logic Learned how to convert char to integer (c - '0') 🎯 Takeaway: Even simple index-based problems can strengthen your fundamentals and attention to detail. #Day58 #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Solved an interesting problem today: “Minimum Stickers to Spell Word” At first, I tried a greedy approach… failed ❌ Then I realized this is actually a DP + memoization problem. 💡 Key Insight: Instead of trying all combinations blindly, we reduce the target string step by step. 🧠 Approach: - Convert each sticker into frequency map - Recursively try reducing target - Use memoization to avoid recomputation ⏱️ Time Complexity: Optimized significantly with caching 🔥 This problem improved my thinking about state reduction. #DSA #CodingInterview #Java #LeetCode
To view or add a comment, sign in
-
-
Day 81 - Balanced Binary Tree Checked whether a binary tree is height-balanced using a bottom-up approach. Approach: • Recursively compute height of left and right subtrees • If height difference > 1 → not balanced • Use -1 as a signal to stop early Time Complexity: O(n) Space Complexity: O(h) #Day81 #LeetCode #BinaryTree #DSA #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 67 of #LeetCode Challenge ✅ Problem Solved: Check If Two String Arrays are Equivalent 💡 What I learned today: • Learned how to compare two string arrays without joining them • Understood how to traverse multiple strings using pointers • Improved handling of indices across arrays and strings • Realized the importance of edge cases to avoid runtime errors 🧠 Approach: • Used four pointers to track positions in both arrays and strings • Compared characters one by one • Moved to the next string when current string ends • Ensured both arrays are fully traversed at the end 📊 Key Takeaway: Efficient solutions avoid extra space — comparing character by character is better than building new strings 🔥 Consistency + small improvements every day = big progress #Day67 #LeetCode #CodingJourney #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development