🔥 Day 82 of #100DaysOfLeetCode ✅ Problem: Number of Longest Increasing Subsequence ✅ Difficulty: Medium 💡 Key Insight: Instead of tracking only the LIS length, we also maintain the number of ways each LIS can be formed. For every element, we check all previous smaller elements and update both length and count dynamically. 🛠 Approach: Use two arrays: dp[i] → Length of LIS ending at index i cnt[i] → Number of LIS ending at index i If a longer subsequence is found → update length and copy count. If another subsequence of the same length is found → add the counts. Finally, sum counts for indices having the maximum LIS length. ⏱ Complexity: Time: O(n²) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Optimize LIS with Counting Approach
More Relevant Posts
-
🚀 Day 100 of #100DaysOfLeetCode Problem: 127. Word Ladder Difficulty: Hard Key Insight: This is a shortest-path problem where each valid word transformation is an unweighted edge — BFS guarantees the minimum sequence length. Approach: Used BFS starting from beginWord. At each step, generated all possible words by changing one character (a–z). Used a HashSet for O(1) lookup and removed visited words to avoid revisits. Complexity: Time: O(N × L × 26) Space: O(N) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 4 of #100DaysOfCode Solved Single Element in a Sorted Array on LeetCode using Binary Search ⚡ 🧠 Key insight: In a sorted array where every element appears twice except one, index parity (even/odd) helps decide which half to search. ⚙️ Approach: 🔹Apply binary search 🔹Compare mid with its adjacent element 🔹Use index parity to move left or right 🔹Narrow down until the single element is found ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🔹 Day 85 – #100DaysOfLeetCode Problem: 3010. Divide an Array Into Subarrays With Minimum Cost I Difficulty: Easy Key Insight: The cost of a subarray depends only on its first element. Since the first subarray always starts at index 0, the problem reduces to selecting the two smallest possible starting elements from the remaining array. Approach: Fix the first subarray cost as nums[0] Find the smallest and second smallest values in nums[1…n-1] Add them to get the minimum total cost Time Complexity: O(n) Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 93 of #100DaysOfLeetCode Problem: 1382. Balance a Binary Search Tree Difficulty: Medium Key Insight: An inorder traversal of a BST produces a sorted sequence. A height-balanced BST can be built by recursively choosing the middle element of this sorted list as the root. Approach: Perform inorder traversal to store node values in a list Recursively construct a balanced BST using the middle element as root Left subtree from left half, right subtree from right half Time Complexity: O(n) Space Complexity: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
Day 17/100 | #100DaysOfDSA Today’s problem: Valid Anagram Two strings. Same letters. Same frequency. That’s it. Approach: • Use a frequency array (size 26) • Increment for first string • Decrement for second string • If all values → 0, it’s an anagram Time complexity: O(n) Big takeaway: When order doesn’t matter — count. Simple idea. Efficient solution. Clean execution. ⚡✨ #100DaysOfCode #LeetCode #DSA #Algorithms #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #ComputerScience #Consistency #Programmers #TechGrowth
To view or add a comment, sign in
-
-
Day 56 of #100DaysOfCode 🚀 Today’s DSA problem: Maximum Nesting Depth of the Parentheses 📌 Problem idea: Given a valid parentheses string, find the maximum depth of nested ( and ). 🧠 Key insight: Increase depth when ( appears Decrease depth when ) appears Track the maximum depth reached at any moment ✅ Why this matters: This problem sharpens: Stack / counter intuition Understanding of nested structures Real-world parsing concepts (expressions, compilers) 📌 Approach: Use a counter instead of a stack Update max depth while traversing the string Time Complexity: O(n) Space Complexity: O(1) Small problems, strong fundamentals 💪 Onward to the next one! #100DaysOfCode #Day56 #DSA #CodingJourney #ProblemSolving #LeetCode #Java #Consistency #dsawithkunal
To view or add a comment, sign in
-
-
Day 3 of Daily DSA 🚀 Solved LeetCode 1: Two Sum Approach: Used a HashMap to store numbers with their indices. For each element, checked if the complement (target - current) already exists. Complexity: • Time: O(n) • Space: O(n) Performance: Runtime: 2 ms (Beats 99.15%) Memory: 47.34 MB Focusing on writing clean and efficient solutions before over-optimizing. Consistency > Intensity 💯 #DSA #LeetCode #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 11 of #100DaysOfCode Solved Find Minimum in Rotated Sorted Array on LeetCode using Binary Search 🔄 🧠 Key insight: In a rotated sorted array, at least one half is always sorted. By comparing the middle element with the right boundary, we can determine which half contains the minimum and safely discard the other. ⚙️ Approach: 🔹Use binary search on the array 🔹Compare nums[mid] with nums[right] 🔹If nums[mid] > nums[right] → minimum lies in the right half 🔹Else → minimum lies in the left half (including mid) ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfLeetCode Problem: 4Sum Difficulty: Medium Key Concept Learned: Sorting + Two Pointers + Duplicate Handling Today’s challenge was about finding all unique quadruplets in an array whose sum equals a given target. The optimized approach involved sorting the array, fixing two indices, and then using the two-pointer technique to efficiently search for valid combinations. Key takeaways: Sorting enables efficient pointer movement and duplicate detection Skipping duplicates at every level (i, j, left, right) is crucial to ensure uniqueness Two-pointer technique reduces the brute force complexity significantly Careful pointer handling avoids repeated results and improves performance A great problem for strengthening array manipulation, pointer logic, and edge-case handling. On to Day 71! 💪🔥 #LeetCode #DSA #Java #TwoPointers #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
One more interesting question I solved 💪😄👌 📌 Problem:- How Many Numbers Are Smaller Than the Current Number 👉 Given an array, for each element we need to find how many numbers are smaller than it. ⚙️ Approach:- • For every number, compare it with all other elements. • Creating count for individual elements which are smaller than the current element. ( ⭐ Key Highlight of This Problem) • Store the count in a result array and return it 📚 Learnings:- ✅ How to traverse arrays efficiently. ✅ How nested loops work in real problems ✅ How to create count for individual element. #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Arrays #LearningDaily
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