💻 Solved a great problem today: Count Increasing Subarrays 🚀 Given an array, the task was to count all strictly increasing subarrays of size ≥ 2. 🔍 Approach I used: Broke the array into continuous increasing segments For each segment of length k, calculated subarrays using the formula: 👉 k(k-1)/2 Summed all results to get the final answer ⚡ Time Complexity: O(n) 📦 Space Complexity: O(n) 💡 This problem helped me understand how breaking a problem into patterns can simplify complex logic. Here’s my Python solution 👇 class Solution: def countIncreasing(self, arr): list2 = [] list2.append(arr[0]) list3 = [] for i in range(1, len(arr)): if arr[i-1] < arr[i] and arr[i] > 2: list2.append(arr[i]) else: list3.append(list2) list2 = [] list2.append(arr[i]) list3.append(list2) ans = 0 for i in list3: if len(i) > 1: ans += (len(i) * (len(i) - 1)) // 2 return ans 🔥 Always learning, always improving. #python #dsa #coding #problemSolving #programming #developers #learning
Count Increasing Subarrays in Python
More Relevant Posts
-
Week 4 of #100DaysOfCode — done! 🎉 Last week I learned how to build classes. This week I learned how to make them talk to each other. Topics covered: 🧹 Inheritance → Superclass, subclass, base class — and what they actually mean → How Python finds attributes (spoiler: it walks up the chain) → Overriding methods — and extending them with super() → isinstance, issubclass, type — when to use which → Multiple inheritance + MRO (Method Resolution Order) 🏗️ Abstract Classes & Interfaces → ABC + @abstractmethod — enforcing a contract on subclasses → Duck typing — "if it has a speak() method, it speaks" → Subclassing built-ins (list, dict, iterator) → Mixins — plugging in behaviour without full inheritance I’ve structured my learning into notes and practical examples to better understand the concepts : https://lnkd.in/epaBymnJ #100DaysOfCode #Python #OOP #LearningInPublic #Programming
To view or add a comment, sign in
-
🐍 Day 8 of Learning Python — and things are getting real! Today's lab was all about writing code that doesn't break (or at least fails gracefully 😄). Here's what I worked through: ✅ Exception Handling — try / except / else / finally • Caught ZeroDivisionError, FileNotFoundError, ValueError, and TypeError • Used `raise` to throw custom error messages • Built my own exception class: TooSmallError 🎉 ✅ Standard library deep dive: • math — calculated circle areas, factorials, GCD, and compound interest • random — shuffled lists, simulated 1000 coin flips, generated reproducible sequences with seed() • datetime — parsed date strings, added time deltas, sorted ISO dates, and printed 5-day schedules ✅ Introspection with dir() and help() The biggest lesson today? Real-life programs don't always get perfect input. Learning to handle errors gracefully is just as important as writing the happy path. Day by day, the pieces are coming together. 💪 #Python #100DaysOfCode #LearningToCode #PythonProgramming #CodingJourney #Day8
To view or add a comment, sign in
-
Today's office discussion took an unexpected turn, diving deep into the nuances of loops. We began with a seemingly simple question: What’s the real difference between a for loop and a while loop? Initially, it seemed straightforward: - Use a for loop when you know how many times to iterate. - Use a while loop when you only know the condition, not the count. However, the conversation quickly evolved. We discovered that the difference goes beyond syntax; it’s about intent and control. Interestingly, despite their differences, Python allows us to make for and while loops behave similarly. For instance: - A for loop is driven by an iterator. - A while loop is driven by a condition check. You can even rewrite a for loop using a while loop by manually handling the iterator. Ultimately, it’s not about which loop is more powerful; it’s about how you approach the problem. Final insights: - For loop → cleaner and more readable when iteration is defined. - While loop → more flexible when termination is dynamic. - Under the hood, both are simply different methods of controlling flow. It's fascinating how a "beginner topic" can lead to a rich discussion about Python internals and abstraction layers. Sometimes, the simplest concepts reveal the deepest insights. #Python #Programming #SoftwareEngineering #LearningEveryday #CleanCode
To view or add a comment, sign in
-
I spent 3 hours debugging code that worked perfectly fine 😶🌫️😶🌫️😶🌫️ The problem? I was convinced something was broken and kept "fixing" things that didn't need fixing.... Turns out the API was just slow. I needed to wait 30 seconds instead of 10. This happened while building my meeting summarizer — a Python app that transcribes recordings and sends email reports via Claude. Here's what nobody tells you about learning to code in your late 30s: Your business brain works against you. 12 years of "moving fast" as a PM doesn't translate to code. I kept jumping to solutions before diagnosing the actual problem. The fix was embarrassingly simple: add a longer timeout!!!!! The real lesson? Slow down. Actually read the error message. Sit with the confusion a bit longer. What's a lesson that took you way too long to learn? #AIlearning #CareerTransition #Python #BuildingInPublic
To view or add a comment, sign in
-
-
📅 7 April 2026 Solved Median Finder (Two Heaps) problem today on LeetCode. Initially, I was getting wrong answers even though the logic looked correct. The mistake? Comparing directly with a max heap stored as negative values. 🔍 Key Learning: When using a max heap in Python (via negative values), always convert back before comparison. ❌ Wrong: num < self.left[0] ✅ Correct: num <= -self.left[0] 💡 Approach: - Use two heaps: • Max Heap (left) → stores smaller half • Min Heap (right) → stores larger half - Balance both heaps after every insertion - Median depends on heap sizes 📈 Time Complexity: - addNum → O(log n) - findMedian → O(1) Small bug, big learning 🚀 Consistency in DSA is what builds clarity. #leetcode #dsa #python #heaps #codingjourney #problemSolving
To view or add a comment, sign in
-
-
Today’s Python lesson made the whole language feel more connected. 🐍 Day 12 of my #30DaysOfPython journey was all about modules, and this one felt like learning how Python organizes its tools behind the scenes. A module is basically a file that contains code, functions, or variables that you can reuse in another file. Instead of writing everything from scratch, you can create something once and bring it into your main program whenever needed. Today I explored: 1. What modules are and why they matter 2. Creating a separate file and importing it into another file 3. Importing only specific parts instead of the whole file 4. Renaming something while importing it 5. Built-in modules like os, statistics, math, string, and random What stood out to me today was how modules make Python feel less like a single script and more like a system of connected pieces. That shift matters because it is what makes code easier to reuse, organize, and scale. One more day, one more topic, one more step toward writing code that is cleaner, smarter, and more modular. Which felt more useful to you first: creating your own module or using built-in ones like math and os? Github Link - https://lnkd.in/gVPWQWiS #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
🚀 Day 3: From Learning Concepts to Building Something Today’s learning was not just about understanding concepts — I also tried applying them by building a small project. ⏱️ What I Explored Today: 🔹 Lists in Python 🔹 String operations 🔹 Basic problem-solving using lists & strings 🔹 Combining concepts to build logic 💻 Mini Project: Built a simple calculator using Python ✔️ Performed basic operations like addition, subtraction, multiplication, and division ✔️ Used functions and conditions to structure the logic ✔️ Focused on writing clean and understandable code 💡 Why This Matters: Learning concepts is important, but applying them in small projects makes everything clearer and more practical. 💡 Impact of Learning: ✔️ Improved my understanding of lists and strings ✔️ Gained confidence in combining multiple concepts ✔️ Got hands-on experience in building a small functional program ✔️ Moving one step closer to building real-world applications 🔥 Big Realization: Even a small project can teach more than just theory — implementation is where real learning happens. 🎯 Next Step: Work on more mini projects and start exploring slightly advanced Python concepts. Learning → Applying → Improving 🚀 #Python #ArtificialIntelligence #MiniProject #LearningJourney #100DaysOfCode #GUVI #StudentDeveloper
To view or add a comment, sign in
-
-
My thesis was stuck. A matrix had the wrong shape and I had no idea why. I could have printed the entire dataset to find the error. I did not. Instead I used Python's debugger. One breakpoint. One look at the intermediate state. Wrong dimensions. Found in seconds. That moment changed how I work. Not because debugging saved my thesis. But because it taught me something I still use every day: You do not need to see all the data to understand what is wrong. You just need to see the right data at the right moment. Since then, every time a pipeline breaks or a model behaves unexpectedly, I reach for the debugger first. Not print statements. Not guesswork. A breakpoint. An intermediate result. A clear answer. Debugging is not a last resort. It is the fastest way to understand what your code is actually doing. What is your go-to strategy when something breaks unexpectedly? #Python #Debugging #DataScience #MachineLearning #FreelanceDataScientist
To view or add a comment, sign in
-
-
Today’s Python topic felt less like syntax and more like learning how code makes decisions. 🐍 Day 09 of my #30DaysOfPython journey was all about conditionals, and this one felt important because it is where Python starts reacting to situations instead of just following instructions. Conditionals help a program choose what to do based on whether something is true or false. Today I explored: 1. if — runs a block when a condition is true 2. else — runs when the condition is false 3. elif — used when there is more than one condition to check 4. shorthand if-else → code if condition else code 5. nested conditions → condition inside a condition 6. logical operators like and (both conditions needs to be true) & or (any one condition needs to be true) What stood out to me today was how much control conditionals give you. They are basically the part of Python that makes logic feel alive. One more day, one more topic, one more step toward writing code that can actually think through a situation. When you first learned conditionals, what was the trickiest part: if-else, elif, or nested conditions? Github Link - https://lnkd.in/g4_tYUDG #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
Just solved “Second Largest Digit in a String” on LeetCode — and here’s the simple approach I followed 👇 Instead of overcomplicating it, I focused on clean thinking + Python basics: 🔹 Converted the string into a set → removes duplicates instantly 🔹 Filtered only digits using isdigit() 🔹 Stored them as integers in a list 🔹 Sorted the list → easy access to largest & second largest 🔹 Edge case check: if less than 2 digits → return -1 💡 Key takeaway: Sometimes the most optimal solution isn’t about complex algorithms — it’s about using the right built-in tools smartly. 🚀 What I’m improving with each problem: • Writing cleaner logic • Thinking in steps instead of rushing • Handling edge cases early Consistency > Complexity. #LeetCode #DSA #Python #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
Explore related topics
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