🎉🎉 Day-37 of #60DaysOfDSA 🎉🎉 Problem: Count Increasing Subarrays 👉 Problem Statement: Given an array, count the number of strictly increasing subarrays of size ≥ 2. 👉 Approach Used (Greedy + Math Insight): ✔️ Traverse the array and track length of increasing subarray ✔️ If current element > previous → extend sequence ✔️ Otherwise → calculate subarrays from previous sequence ✔️ Formula used: For a sequence of length k → number of subarrays = k*(k-1)/2 👉 Steps: 1️⃣ Initialize count = 1 2️⃣ Traverse array 3️⃣ If increasing → count++ 4️⃣ Else → add (count*(count-1)/2) to result and reset 5️⃣ Add remaining sequence result 👉 Time Complexity: O(n) #problemsolving #java #dsa #geekstreak60
Count Increasing Subarrays in Array with Java
More Relevant Posts
-
🚀 Day 15 / 85 Days of DSA Challenge Today’s problem was about applying range-based updates with a twist — stepping through the array using a custom interval (k) and applying modular multiplication. 💡 Key Learnings: Handling queries with non-contiguous updates (i += k pattern) Importance of modulo arithmetic to prevent overflow Final aggregation using bitwise XOR 🔍 Approach: For each query [l, r, k, v]: Start from index l Jump k steps each time Multiply elements by v (mod 1e9+7) Finally, compute XOR of the modified array. ⚡ This problem highlights how brute-force works but may need optimization for large constraints. Consistency > Perfection 💯 85 Days Challenge — Let’s go! 🔥 #DSA #CodingChallenge #Java #ProblemSolving #100DaysOfCode #LearningJourney
To view or add a comment, sign in
-
-
Day 48/75 — Max Consecutive Ones III Today’s problem was about finding the maximum consecutive 1s after flipping at most k zeros. Approach: • Use sliding window • Expand right pointer • Count zeros in window • Shrink window when zeros > k Key logic: if (nums[right] == 0) zeroCount++; while (zeroCount > k) { if (nums[left] == 0) zeroCount--; left++; } maxLength = Math.max(maxLength, right - left + 1); Time Complexity: O(n) Space Complexity: O(1) Key Insight: Keep the window valid by ensuring at most k zeros, and maximize its size. 48/75 🚀 #Day48 #DSA #SlidingWindow #TwoPointers #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 75/100 🚀 | #100DaysOfDSA Solved LeetCode 378 – Kth Smallest Element in a Sorted Matrix today. The problem was to find the k-th smallest element in an n x n matrix where each row and column is sorted. Approach: Used Binary Search on the value space (not indices). • Defined the search range from the smallest element (matrix[0][0]) to the largest (matrix[n-1][n-1]) • For each mid, counted how many elements in the matrix are ≤ mid • If count < k → move right (left = mid + 1) • Else → move left (right = mid) For counting, used an efficient bottom-left traversal: • Started from bottom-left corner • If current element ≤ mid → all elements above are valid → add count and move right • Else → move up This avoids checking all elements and keeps it efficient. Time Complexity: O(n log(max - min)) Space Complexity: O(1) Key takeaway: Binary Search isn’t just for arrays — it can be applied on the answer space, especially when the matrix has sorted properties. #100DaysOfDSA #LeetCode #DSA #Java #BinarySearch #Matrix #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 46/75 — Frequency of the Most Frequent Element Today’s problem was about maximizing the frequency of an element using at most k increments. Approach: • Sort the array • Use sliding window • Maintain sum of current window • Expand right pointer • Shrink window when operations exceed k Key logic: while ((long) nums[right] * (right - left + 1) - total > k) { total -= nums[left]; left++; } maxFreq = Math.max(maxFreq, right - left + 1); Time Complexity: O(n log n) (sorting) Space Complexity: O(1) Key Insight: Make all elements in window equal to the largest element — check if cost ≤ k. 46/75 🚀 #Day46 #DSA #SlidingWindow #TwoPointers #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 102/160 – GFG Challenge Today’s problem: Cycle Detection in an Undirected Graph 🔁 🔍 Key Learning: Learned how to detect cycles using BFS traversal Used a queue with (node, parent) to track traversal path Understood why checking neighbor != parent is crucial to avoid false cycle detection 🧠 Concept Breakdown: Convert edge list → adjacency list Traverse all components (important when graph is disconnected) If a visited node is reached again and it's not the parent, a cycle exists 💡 Takeaway: Graph problems become much easier when you: Identify the input format (edge list vs adjacency list) Choose the right traversal (BFS/DFS) Track parent properly in undirected graphs ⏱️ Time Complexity: O(V + E) Consistency is key 🔥 102 days down, 58 more to go! #GFG #100DaysOfCode #DSA #Java #GraphTheory #CodingJourney
To view or add a comment, sign in
-
-
Yesterday's matrix problem was solved using traversal. Today's matrix problem was solved using Binary Search. Same topic. Different thinking. 🚀 Day 95/365 — DSA Challenge Solved: Search a 2D Matrix Key observation: The matrix is not just row-wise sorted. The first element of each row is greater than the last element of previous row. This means the matrix behaves like a sorted 1D array. So we can apply Binary Search. We convert index → row, col: row = mid / cols col = mid % cols And perform normal binary search. ⏱ Time: O(log(m * n)) 📦 Space: O(1) Day 95/365 complete. 💻 270 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #BinarySearch #Matrix #LearningInPublic
To view or add a comment, sign in
-
-
When a problem asks for maintaining a condition on both minimum and maximum, monotonic data structures become very powerful. 🚀 Day 110/365 — DSA Challenge Solved: Longest Continuous Subarray With Absolute Diff ≤ Limit Problem idea: We need to find the longest subarray such that the difference between max and min elements is ≤ limit. Efficient approach: Use Sliding Window + Two Monotonic Deques. Steps: 1. Use one deque to maintain maximum elements (decreasing order) 2. Use another deque to maintain minimum elements (increasing order) 3. Expand window by moving the right pointer 4. If (max − min) exceeds limit, shrink window from the left 5. Track the maximum valid window size This ensures we can get max and min in O(1) time. ⏱ Time: O(n) 📦 Space: O(n) Day 110/365 complete. 💻 255 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #SlidingWindow #Deque #LeetCode #LearningInPublic
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟖𝟎/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐗𝐎𝐑 𝐀𝐟𝐭𝐞𝐫 𝐑𝐚𝐧𝐠𝐞 𝐌𝐮𝐥𝐭𝐢𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐐𝐮𝐞𝐫𝐢𝐞𝐬 𝐈 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: For each query, update elements from index l to r with step k. Multiply each selected element by v under modulo. After processing all queries, compute XOR of the final array. 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: Brute-force range simulation + XOR aggregation. ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐪 × 𝐧) (worst case) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝟏) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Even when constraints allow brute force, structuring the simulation cleanly ensures correctness and readability. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #Simulation #XOR #Arrays #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
To view or add a comment, sign in
-
-
Day 2/30 — DSA Challenge 🚀 Problem: Lowest Common Ancestor of Deepest Leaves Topic: Tree + DFS Difficulty: Medium Approach: Used DFS to calculate depth of left and right subtrees At each node, compared depths: If equal → current node is LCA Else → return deeper subtree result Mistake / Challenge: Initially overcomplicated thinking about storing all deepest nodes Realized we don’t need to track nodes explicitly, depth comparison is enough Fix: Returned a Pair (node, depth) from recursion Handled everything in one DFS traversal Key Learning: Tree problems often look complex but can be simplified with recursion Focus on what needs to be returned from each call Time Taken: 60 minutes Consistency check ✅ See you on Day 3. GitHub Repo: https://lnkd.in/g87geK_g #DSA #LeetCode #Java #Trees #Recursion #LearningInPublic
To view or add a comment, sign in
-
-
Day 63/75 — Rotate Array Today’s problem was about rotating an array to the right by k steps. Approach: • Use reversal algorithm for optimal in-place rotation • Reverse entire array • Reverse first k elements • Reverse remaining elements Key logic: k = k % n; reverse(nums, 0, n - 1); reverse(nums, 0, k - 1); reverse(nums, k, n - 1); Time Complexity: O(n) Space Complexity: O(1) A classic array problem that reinforces in-place manipulation techniques. 63/75 🚀 #Day63 #DSA #Arrays #InPlace #Java #Algorithms #LeetCode
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