100DaysOfCode: Increasing Subarrays and Minimum Distance of Good Tuple Solutions

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

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories