🗓 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
LeetCode Challenge: Smooth Descent Periods in Stock Prices
More Relevant Posts
-
🗓 Day 64 / 100 – #100DaysOfLeetCode 📌 Problem 1339: Maximum Product of Splitted Binary Tree Today’s problem combined tree traversal with optimization logic. The task was to split a binary tree into two subtrees by removing exactly one edge, such that the product of the sums of the two resulting subtrees is maximized. 🧠 My Approach: First, computed the total sum of all nodes in the tree. Used a post-order DFS traversal to calculate the sum of each subtree. For every subtree: Considered it as one part after the split. The other part would have sum: total_sum − subtree_sum Calculated the product of these two values. Tracked the maximum product across all possible splits. Returned the result modulo 109+710^9 + 7109+7, as required. Post-order traversal works perfectly here because subtree sums must be known before evaluating the split. 💡 Key Learning: This problem reinforced: ✔ how post-order DFS is ideal for subtree-based calculations ✔ combining traversal with optimization criteria ✔ thinking globally (total sum) while evaluating local decisions (each split) A great example of how tree problems often require two passes: one for data collection and one for optimization. Another strong tree-based DP-style problem completed 🌳🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #BinaryTree #DFS #TreeDP #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🗓 Day 60 / 100 – #100DaysOfLeetCode 📌 Problem 1411: Number of Ways to Paint N × 3 Grid Today’s problem was a really good exercise in dynamic programming and pattern observation. The goal was to count the number of valid ways to paint an n × 3 grid using three colors, such that no two adjacent cells (horizontal or vertical) share the same color. 🧠 My Approach: Instead of tracking every possible coloring explicitly, I categorized each row into two patterns: 1️⃣ same – Rows where the 1st and 3rd cells have the same color (e.g., A B A) 2️⃣ diff – Rows where all three cells have different colors (e.g., A B C) For the first row: same = 6 diff = 6 Then for each subsequent row: A same pattern can be formed from: previous same rows in 3 ways previous diff rows in 2 ways A diff pattern can be formed from: previous same rows in 2 ways previous diff rows in 2 ways Using these transitions, I iterated row by row and applied modulo 10^9 + 7 to handle large values efficiently. 💡 Key Learning: This problem reinforced: ✔ breaking complex constraints into manageable states ✔ recognizing repeating patterns to optimize DP solutions ✔ reducing a large state space into just a few variables ✔ how mathematical transitions can drastically simplify implementation A perfect example of how thinking in patterns turns a hard-looking problem into a clean and elegant solution 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #DynamicProgramming #DP #Combinatorics #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🗓 Day 66 / 100 – #100DaysOfLeetCode 📌 Problem 865: Smallest Subtree with All the Deepest Nodes Today’s problem focused on binary tree depth analysis. The goal was to find the smallest subtree that contains all the deepest nodes in the tree. 🧠 My Approach: Used Depth-First Search (DFS) to compute information bottom-up. For each node, tracked: the maximum depth reachable from that node, and the candidate subtree root that contains all deepest nodes. Compared depths of left and right subtrees: If both sides have the same depth → the current node is the answer. Otherwise, propagated the deeper side upward. Returned the node that satisfies the condition for all deepest nodes. This approach cleanly combines depth calculation with subtree selection in a single traversal. 💡 Key Learning: This problem reinforced: ✔ how returning multiple values from DFS simplifies logic ✔ thinking bottom-up for tree optimization problems ✔ identifying the exact node where depths converge Tree problems often become elegant once the right recursive structure is identified 🌳🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #BinaryTree #DFS #TreeTraversal #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🗓 Day 59 / 100 – #100DaysOfLeetCode 📌 Problem 961: N-Repeated Element in Size 2N Array Today’s problem focused on identifying a repeating pattern in an array with well-defined constraints. The task was to find the element that appears n times in an array of size 2n, where all other elements are unique. 🧠 My Approach: I used a set-based approach to track elements as I traversed the array: Iterated through each element in the array. Stored visited elements in a set. If an element was already present in the set, that meant it was the repeated element → returned it immediately. This works efficiently because the problem guarantees exactly one element is repeated n times. 💡 Why this works well: Sets provide O(1) average time complexity for lookup. The repeated element is guaranteed to appear early due to frequency, so we can exit early. Simple logic with clean and readable code. 💡 Key Learning: This problem reinforced: ✔ how problem constraints can simplify the solution ✔ effective use of hash-based data structures ✔ recognizing patterns instead of overcomplicating logic ✔ writing efficient solutions even for “easy” problems A great example of how understanding constraints leads to elegant solutions 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Arrays #HashSet #Simulation #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🗓 Day 63 / 100 – #100DaysOfLeetCode 📌 Problem 1161: Maximum Level Sum of a Binary Tree Today’s problem focused on tree traversal and level-wise aggregation. The task was to find the level in a binary tree that has the maximum sum of node values, with levels numbered starting from 1. 🧠 My Approach: Used Breadth-First Search (BFS) to traverse the tree level by level. For each level: Calculated the sum of all node values at that level. Compared it with the maximum sum seen so far. Kept track of: the current level number the level with the maximum sum Returned the smallest level number in case of a tie, as required. This level-order traversal makes the solution both intuitive and efficient. 💡 Key Learning: This problem reinforced: ✔ how BFS naturally fits level-based tree problems ✔ careful tracking of level indices during traversal ✔ handling ties correctly based on problem constraints Tree problems often become much simpler once the right traversal strategy is chosen. Another solid step forward in mastering binary tree patterns 🌳🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #BinaryTree #BFS #TreeTraversal #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
Day 27 of #30DaysOfCode with Educative Challenge: Moving Average from Data Stream (Easy) Core Idea: Maintain a running sum over a fixed-size window The Pattern: Queue-backed sliding window Keep the last N values in a queue and maintain their running sum. Each new value is added to the queue and the sum, and when the window is full, the oldest value is removed and subtracted from the sum. Why It Works Here: The moving average can be updated in constant time by adjusting the sum incrementally instead of recomputing it over the entire window each time. This makes the structure efficient even for long-running streams. Production Lesson: This is the same pattern used in lightweight monitoring and rate calculations—CPU load averages, rolling error rates, or moving metrics can all be tracked with a small buffer and an incremental update instead of full recomputation. Edge Worth Remembering: When the stream has fewer values than the window size, the average is taken over the actual count in the buffer, not the configured window size. #Educative #Python #SoftwareEngineering #ContinuousLearning #ProblemSolving
To view or add a comment, sign in
-
✅ Day 12 of 100 Days LeetCode Challenge Problem: 🔹 #78 – Subsets 🔗 https://lnkd.in/gazZukB6 Learning Journey: 🔹 Today’s problem was about generating all possible subsets (the power set) of a given array. 🔹 I approached it using backtracking, making a binary decision at each index: include or exclude the current element. 🔹 The recursion explores both paths systematically, ensuring no subset is missed. 🔹 Copying the current solution at the base case preserves the state before backtracking continues. Concepts Used: 🔹 Backtracking 🔹 Recursion 🔹 Depth-First Search (DFS) 🔹 Power Set Generation Key Insight: 🔹 Subset problems naturally map to a include/exclude decision tree. 🔹 Backtracking provides a clean and intuitive way to explore all combinations. 🔹 Understanding recursion flow is crucial for mastering combinatorial problems. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
Mastering Python Logic: From Recommendations to Real-World Analytics! Day 7 at YouExcel Training and the momentum is only building up! 🚀 After developing recommendation systems for cars and venues, today’s warm-up was about building a Student Grading System. This project allowed me to dive deeper into Python’s mathematical capabilities and multi-layered conditional logic. What I implemented today: Arithmetic Operations: Automating the calculation of total marks and percentages from multiple subjects. Precision Logic: Using if-elif-else chains to categorize academic performance into specific grades (A+ to E). Dynamic Feedback: Crafting personalized messages for students based on their results. It’s amazing how a few days of consistent practice under sir Muhammad Rafay Shaikh can turn complex logical problems into structured, executable code. Every warm-up session feels like a step closer to becoming a proficient developer! #Python #CodingJourney #StudentGradingSystem #YouExcel #MuhammadRafayShaikh #LogicBuilding #DataAnalytics #ContinuousLearning #Day7
To view or add a comment, sign in
-
-
🗓 Day 47 / 100 – #100DaysOfLeetCode 📌 Problem 3783: Mirror Distance of an Integer Today’s problem was a straightforward yet satisfying one that focused on digit manipulation and basic number operations. The task was to compute the mirror distance of an integer, defined as the absolute difference between the number and its digit-reversed form. 🧠 My Approach: Observed that if the number has only a single digit, reversing it doesn’t change anything, so the mirror distance is 0. For multi-digit numbers: Converted the number to a string. Reversed the string and converted it back to an integer (automatically handling leading zeros). Calculated the absolute difference between the original number and its reverse. This results in a clean and efficient solution with minimal logic. 💡 Key Learning: This problem reinforced that: ✔ String conversion is often the simplest way to reverse digits ✔ Edge cases (like single-digit numbers or leading zeros) matter ✔ Not every problem needs complex logic — clarity is key A quick win, but an important reminder to always handle edge cases carefully 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #StringManipulation #MathInCoding #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
Day 4 of DSA Practice : Today I learned about Bubble Sort and understood how we can optimize it step by step. 🔹 Approaches Learned: Basic Bubble Sort: O(n²) Optimized Bubble Sort (Early Exit using a flag): Best Case O(n), Worst Case O(n²) ✅ Key Idea (Bubble Sort): We repeatedly compare adjacent elements and swap them if they’re in the wrong order. After each pass, the largest element “bubbles up” to the end of the array. 🚀 Optimization (Early Exit): If in any pass no swaps happen, the array is already sorted — so we stop early. ⚡ Complexity: Time: Worst O(n²), Best O(n) (already sorted with optimization) Space: O(1) This sorting method is great for learning sorting basics and understanding swapping-based sorting. #DSA #Programming #CompetitiveProgramming #Java #Cplusplus #Python #Learning
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