LeetCode Challenge: Smooth Descent Periods in Stock Prices

🗓 Day 41 / 100 – #100DaysOfLeetCode 📌 Problem 2110: Number of Smooth Descent Periods of a Stock Today’s problem focused on identifying and counting smooth descent periods in a stock’s price history. A smooth descent period is a contiguous segment where each day’s price decreases by exactly 1 compared to the previous day. Even a single day counts as a valid period. 🧠 My Approach: Observed that the array can be broken into maximal descending segments where prices[i] = prices[i-1] - 1. Traversed the array while maintaining the current length of a smooth descent sequence. Whenever the smooth descent condition breaks, reset the length to 1. For each position, added the current length to the answer. This works because a descent segment of length k contributes: 1+2+3+⋯+k smooth descent periods in total. 💡 Key Learning: This problem reinforced a powerful counting technique: ✔ Break the array into valid segments ✔ Count subarrays using incremental accumulation ✔ Avoid nested loops by leveraging mathematical patterns It’s a great example of turning what looks like a subarray-counting problem into a simple single-pass solution. Another solid daily problem completed 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #SlidingWindow #TwoPointers #Arrays #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning

  • graphical user interface

To view or add a comment, sign in

Explore content categories