Day 60/100 of #100DaysOfCode 🔹 GFG POTD – Count Increasing Subarrays My approach: Instead of checking all subarrays, I tracked the length of every increasing streak. Example: If the array is: [1, 2, 3, 1, 2] Then: 1 → 2 → 3 is one increasing streak of length 3 1 → 2 is another streak of length 2 For every streak of length len, the number of increasing subarrays is: len * (len - 1) / 2 Why? Because from a streak of 3: [1,2] [2,3] [1,2,3] This helped solve it in O(n) time. 🔹 LeetCode POTD – Minimum Distance of Good Tuple We had to find 3 equal values in the array such that: distance = |i-j| + |j-k| + |k-i| My thought process: For any 3 indices: a < b < c The formula simplifies to: 2 * (c - a) That means: 👉 only the first and last index matter. So instead of checking all triplets: I stored indices of each number For every number appearing 3+ times: checked every 3 consecutive indices calculated minimum distance This reduced the solution from brute force to O(n). Slowly improving every day. On to Day 61 💻🔥 #LeetCode #GeeksforGeeks #CodingJourney #DSA #ProblemSolving #Cpp #Programming #100DaysOfCode
100DaysOfCode: Increasing Subarrays and Minimum Distance of Good Tuple Solutions
More Relevant Posts
-
64 of #100DaysOfCode 🚀 Solved LeetCode 46 – Permutations using the Recursion and in-place backtracking (swap) approach. 🔹 Instead of using extra space like visited[], I used swapping to generate permutations efficiently. 🔹 Fixed each index and tried all possible elements using recursion. 🔹 Backtracking (swap back) helped explore all possibilities without extra memory. 💡 Key Learning: Backtracking becomes more powerful when optimized with in-place operations — cleaner and faster! ⚙️ Time Complexity: O(n × n!) 📦 Space Complexity: O(n) (recursion stack) #leetcode #dsa #cpp #backtracking #codingjourney #programming #100daysofcode
To view or add a comment, sign in
-
-
Subtree of another tree Approach: If subRoot is null - return true If root is null - return false If values match - check isIdentical(root, subRoot) If identical - return true Else - check left and right: isSubtree(root.left, subRoot) isSubtree(root.right, subRoot) Return true if found anywhere, otherwise false TC: O(N*M) -- n =no. of nodes in root, m = no. nodes in subRoot (worst case) SC: O(h) -- height of tree ( O(N) -- skewed tree || O(logN) -- balanced tree) #coding #programming #DSA #Consistency #Leetcode #CodingJourney
To view or add a comment, sign in
-
-
Solved the Target Sum Expression problem in C++ today. The challenge was to count how many different expressions can be formed by placing '+' or '-' before each number in an array so that the final result equals the target. For example: arr = [1, 1, 1, 1, 1], target = 3 Output = 5 What I learned: 1. Each number gives us two choices: add or subtract 2. This problem can be solved efficiently using Dynamic Programming 3. We track how many ways each sum can be formed as we move through the array Key takeaway: Instead of generating all expressions manually, DP helps us store intermediate results and avoid repeated work. #cpp #programming #dsa #dynamicprogramming #codingchallenge #leetcode #geekforgeeks #softwaredeveloper
To view or add a comment, sign in
-
-
Solved a Gray Code problem in C++ today. The task was to generate bit patterns from 0 to 2^n - 1 such that every consecutive pattern differs by only one bit, while always starting from 0. I used the Gray code formula: gray = i ^ (i >> 1) This makes the solution clean and efficient, and guarantees that adjacent codes differ by exactly one bit. Example for n = 2: 00 -> 01 -> 11 -> 10 What I like about this problem is how a simple bit manipulation formula can solve what looks like a complex sequence-generation challenge. Concepts practiced: Bit Manipulation Binary Representation Pattern Generation C++ Problem Solving #cpp #coding #programming #datastructures #algorithms #problemsolving #bitmanipulation #leetcode #geekforgeeks
To view or add a comment, sign in
-
-
Solved LeetCode 151: Reverse Words in a String Today, I worked on reversing the order of words in a string while handling extra spaces efficiently. I learned how to: Remove leading, trailing, and multiple spaces Extract words correctly Reverse their order using clean logic and STL I implemented an optimized solution with: Time Complexity: O(n) Space Complexity: O(n) This problem helped me improve my understanding of string manipulation, edge case handling, and clean coding practices https://lnkd.in/getBKFiE GitHub Repo: https://lnkd.in/gg4daDpn #day18 #DSA #Cpp #LeetCode #Coding #Programming #Learning #ProblemSolving #Strings
To view or add a comment, sign in
-
-
Day 70 of #100DaysOfCode 💻 Solved LeetCode 523 – Continuous Subarray Sum using an optimized Prefix Sum + HashMap approach. 💡 Key Insight: If two prefix sums have the same remainder when divided by k, the subarray between them is divisible by k. ⚡ Reduced time complexity from O(n²) → O(n) #leetcode #coding #dsa #cpp #programming #placements
To view or add a comment, sign in
-
-
Invert Binary tree Approach: check if node is null or not if null return null swap left node and right ( not value complete node ) go to left (recursively) go to right (recursively) return node TC: O(N) SC:O(N)- recursive stack #DSA #programming #coding #problemSolving
To view or add a comment, sign in
-
-
Solved LeetCode: Power of Two using Bit Manipulation Learned how to efficiently check whether a number is a power of 2 using binary properties. A number is a power of two if it has only one set bit in its binary representation. Used the trick: n > 0 && (n & (n - 1)) == 0 Optimized solution with: Time Complexity: O(1) Space Complexity: O(1) This problem helped me understand bit manipulation, binary concepts, and optimized checking techniques https://lnkd.in/dFdQhMmS GitHub Repo: https://lnkd.in/gg4daDpn #day10 #DSA #Cpp #LeetCode #Coding #Programming #Learning #ProblemSolving #BitManipulation
To view or add a comment, sign in
-
-
🚀 Day 53/100 – LeetCode DSA Challenge 🔹 Problem: Find the Index of the First Occurrence in a String 🧩 Problem Statement: Given two strings haystack and needle, we need to return the index of the first occurrence of needle in haystack. If needle is not present, return -1. 📊 How I Solved It: • Compared substring of length needle with needle itself • Traversed only till n - m to avoid out-of-bound errors • Returned index immediately when match found • If no match → returned -1 return -1; 🧠 What I Learned Today: • How string matching works internally • Importance of correct loop boundaries (n - m) • Difference between brute-force vs optimized approaches • Concept of sliding window in strings • Built-in methods like indexOf() can simplify problems #Day53 #100DaysOfCode #LeetCode #DSA #Java #Programming #CodingJourney #ProblemSolving #TechSkills
To view or add a comment, sign in
-
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