Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency
LeetCode 66: Plus One Array Solution
More Relevant Posts
-
Day 29 of Daily DSA 🚀 Solved LeetCode 287: Find the Duplicate Number ✅ Problem: Given an array containing n + 1 integers where each number is in the range [1, n], find the duplicate number. Approach: Used the index marking technique. Key Idea: Treat the value as an index Convert the value to absolute (Math.abs) Mark the visited index by making the number negative If we encounter an index that is already negative, that value is the duplicate This allows us to detect duplicates efficiently without extra space. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 4 ms (Beats 91.67%) ⚡ • Memory: 82.75 MB A clever trick that uses the array itself as a visited map. #DSA #LeetCode #Java #ProblemSolving #Algorithms #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 24/90 – Solved LeetCode 1288: Remove Covered Intervals Continuing my DSA consistency journey, today I worked on an Interval Pattern problem: Remove Covered Intervals. 💡 Problem Insight An interval [a, b] is considered covered if another interval [c, d] exists such that: c ≤ a and b ≤ d The challenge is to remove all such covered intervals and return the number of remaining intervals. ⚙️ Approach • Step 1 – Sorting Strategy Sort intervals by start time ascending and end time descending. This ensures that larger intervals appear first when the start point is the same. • Step 2 – Track Maximum End Maintain a variable maxEnd representing the farthest end seen so far. • Step 3 – Identify Valid Intervals If the current interval’s end is greater than maxEnd, it means the interval is not covered, so we update maxEnd and count it. 📊 Performance Runtime: 6 ms Faster than 90% of submissions 📚 Key Takeaway A well-designed sorting strategy can significantly simplify interval problems and reduce unnecessary comparisons. Staying consistent and learning new problem-solving patterns every day. #DSA #LeetCode #Java #Algorithms #ProblemSolving #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
-
🌱 Day 11 of my #100DaysOfCode Journey Today I solved LeetCode Problem – Contains Duplicate. The problem asks us to determine if an integer array contains any duplicate values. If any value appears more than once, we return true; otherwise, false. The approach I used today was to sort the array first and then check adjacent elements for equality. This helps detect duplicates efficiently in a single pass. 🔹 What I practiced today: ✅ Array manipulation and sorting ✅ Comparing adjacent elements to find duplicates ✅ Thinking about time vs. space trade-offs 📊 Complexity Analysis: • Time Complexity: O(n log n) — due to sorting • Space Complexity: O(1) — in-place array check A simple yet practical problem that strengthens array handling and logical thinking in algorithm problems. #LeetCode #Java #DSA #100DaysOfCode #CodingJourney #ContainsDuplicate
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 41 💻 LeetCode – Add to Array-Form of Integer Today I solved a problem focused on array manipulation and digit-by-digit addition. 🔎 Problem: An integer is given in array form, where each element represents a digit. The task is to return the array representation of num + k. 💡 Approach: Instead of converting the array into a number, I simulated manual addition from the last digit, just like we do on paper. ✔ Traverse the array from right to left ✔ Add digits with k and manage the carry ✔ Store the result digits and reverse at the end This approach efficiently handles large inputs and avoids integer overflow. Small problems like this strengthen logic building and problem-solving skills. #LeetCode #DSA #100DaysOfCode #ProblemSolving #Java #CodingJourney #SoftwareDeveloper #TechGrowth
To view or add a comment, sign in
-
-
Day 85/100 – LeetCode Challenge ✅ Problem: #226 Invert Binary Tree Difficulty: Easy Language: Java Approach: Recursive DFS (Divide and Conquer) Time Complexity: O(n) Space Complexity: O(h) where h = tree height Key Insight: Swap left and right child at every node, then recursively invert both subtrees. Classic recursion problem — made famous by Google interview story. Solution Brief: Base case: if root is null, return null. Swap left and right children using temporary variable. Recursively call invertTree on left and right subtrees. Return the root (now inverted). #LeetCode #Day85 #100DaysOfCode #Tree #Java #Algorithm #CodingChallenge #ProblemSolving #InvertBinaryTree #EasyProblem #DFS #Recursion #DSA
To view or add a comment, sign in
-
-
🚀 Day 20 of My DSA Journey Solved LeetCode Problem #1394 — Find Lucky Integer in an Array 💡 📌 Problem Summary: Given an array of integers, find the largest number whose frequency in the array is equal to its value. If no such number exists, return -1. 🧠 Approach: Used HashMap to store frequency of each element Traversed the map to check if frequency == value Tracked the maximum lucky number 💻 Key Learning: Importance of frequency counting Efficient use of HashMap Writing clean and optimized code using getOrDefault() ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) ✅ Consistency is the key — small steps every day lead to big results! #Day20 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Today I solved LeetCode 951 – Flip Equivalent Binary Trees. 🧩 Problem Summary: Given the roots of two binary trees root1 and root2, check whether they are flip equivalent. Two trees are flip equivalent if they are the same after any number of flip operations, where a flip operation swaps the left and right children of a node. 💡 Key Concepts Used: Binary Trees Recursion Depth First Search (DFS) Tree comparison 🧠 Approach: If both nodes are null, return true. If one is null or values differ, return false. Recursively check two possibilities: Without flip → left with left AND right with right With flip → left with right AND right with left If either case is true, the trees are flip equivalent. 📚 What I Learned: How to handle multiple recursive possibilities. Comparing trees with flexible structure (not fixed order). Strengthening understanding of DFS in tree problems. Writing clean recursive conditions for complex checks. Leveling up my tree problem-solving skills Consistency and practice make all the difference #LeetCode #DSA #BinaryTree #FlipEquivalent #DFS #Recursion #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 89 - #100DaysOfCode Today I solved a problem on finding the smallest common element between two sorted arrays. 🧩 Problem Given two integer arrays, return the first common element between them. If no common element exists, return -1. 💡 Approach I used a HashSet to efficiently check for common elements. Steps: 1️⃣ Insert all elements of the first array into a HashSet. 2️⃣ Traverse the second array. 3️⃣ Check if the current element exists in the set. 4️⃣ If found, return that element immediately. 5️⃣ If no common element is found, return -1. ⏱ Time & Space Complexity Time Complexity: O(n + m) Space Complexity: O(n) 📌 Key Learning: Using a HashSet helps reduce lookup time to O(1), making the solution efficient #DSA #Java #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 117 🚀 | LeetCode Progress Solved 3 problems today and strengthened array manipulation skills 💪 📌 Problem 1: Sort Array By Parity (#905) – 🟢 Easy 👉 Two-pointer / index swapping technique 👉 Place even numbers at the front while iterating 👉 In-place solution with O(1) extra space 👉 Time Complexity: O(n) Efficient way to partition arrays without extra memory ⚡ 📌 Problem 2: Find All Numbers Disappeared in an Array (#448) – 🟢 Easy 👉 Index marking technique using negative values 👉 Mark visited indices by flipping the sign 👉 Positive indices at the end represent missing numbers 👉 Time: O(n) | Space: O(1) (excluding result list) A clever trick to use the array itself as a hash map 🧠 📌 Problem 3: Minimum Changes to Make an Alternating Binary String (#1758) – 🟢 Easy 👉 Compare with two possible patterns: "010101..." and "101010..." 👉 Count mismatches for both patterns 👉 Return the minimum operations needed 👉 Time Complexity: O(n) Simple logic but great practice for pattern-based string problems 🔍 Small improvements every day lead to big progress over time 📈 #Day117 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #GeekStreak #100DaysOfCod
To view or add a comment, sign in
-
Day 100/100 – LeetCode Challenge ✅ Problem: #41 First Missing Positive Difficulty: Hard Language: Java Approach: In-Place Index Marking Time Complexity: O(n) Space Complexity: O(1) Key Insight: Place each positive integer in its correct position (index i should contain i+1). Mark presence using negative values without extra space. Solution Brief: First pass: replace numbers outside range [1, n] with n+1 (ignore them) Second pass: treat each number as index, mark that index negative Third pass: first positive index = missing number If all marked, answer is n+1 #LeetCode #Day100 #100DaysOfCode #Array #Java #Algorithm #CodingChallenge #ProblemSolving #FirstMissingPositive #HardProblem #InPlace #Optimization #DSA
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