hi connections I just tackled LeetCode 53: Maximum Subarray using Kadane’s Algorithm. There’s something so satisfying about mapping out the logic by hand before hitting the keyboard. The core decision at every index? ✅ Start fresh: Is the current number bigger than the total sum so far? ✅ Keep going: Does adding the current number improve the streak? My logic: maxSum: Decides whether to restart or continue the subarray. maxSumSoFar: Tracks the "all-time high" score. Quick Tip: Watch out for variable names! I spent a minute debugging a NameError because my notes said a, but the function expected nums. Even the best logic needs a bit of syntax TLC. Efficiency: Time: O(n) Space: O(1) #SoftwareEngineering #LeetCode #Coding #Python #Algorithms #ProblemSolving
Maximizing Subarray with Kadane's Algorithm
More Relevant Posts
-
I just tackled the classic problem of implementing K independent queues within a single array of size N! The challenge is to ensure O(1) time complexity for both enqueue and dequeue operations while maintaining optimal space efficiency. Instead of statically partitioning the array—which leads to wasted space—I used a linked-list approach within the array. By maintaining a 'next' array to track both the links between elements and a stack of free slots, the implementation allows any queue to grow as long as there is space available in the global array. This dynamic allocation ensures that no queue is blocked if the total capacity hasn't been reached. A great exercise in pointer manipulation and efficient memory management! Implementation: https://htmlify.me/r/pope #DataStructures #Coding #Python #Algorithms #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 12/30 | LeetCode 215 – Kth Largest Element in an Array Problem: Given an integer array nums and an integer k, return the kth largest element in the array. ⚠️ Note: It is the kth largest in sorted order, not the kth distinct element. 🧠 Approach (Sorting) Sort the array in ascending order Reverse it (or directly access from the end) Return the (k-1) index Simple and effective. ⏱️ Complexity Time Complexity: O(n log n) (due to sorting) Space Complexity: O(n) 🧾 Python Code class Solution(object): def findKthLargest(self, nums, k): a = sorted(nums) b = a[::-1] return b[k-1] ✅ Example Input: nums = [3,2,1,5,6,4] k = 2 Output: 5 🎯 Key Learning Sorting gives a quick solution But in interviews, you might be asked for: Heap solution → O(n log k) QuickSelect → O(n) average Understanding multiple approaches makes you stronger in DSA. 🔖 Hashtags #LeetCode #30DaysOfLeetCode #Day12 #Python #Arrays #Sorting #DSA #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
feb-21-26 LeetCode 762 – Prime Number of Set Bits in Binary Representation Solved today’s problem focused on bit manipulation and prime checking! 🔹 Problem: Given two integers left and right, count how many numbers in that range have a prime number of set bits (1s) in their binary representation. 💡 Approach: Iterate through each number in the range. Count set bits using bitwise operations (& and right shift). Check whether the count of set bits is a prime number. Keep track of valid cases. 🧠 Concepts Used: Bit Manipulation Prime Number Checking Mathematical Optimization Simple problem on the surface, but a great way to strengthen understanding of binary representation and efficient computation. Consistency + Daily Practice = Growth 📈🔥 #LeetCode #BitManipulation #PrimeNumbers #Python #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Day 76 of #100DaysOfLeetCode Today’s challenge focused on matrix optimization using prefix sums — a great example of turning brute force into an efficient solution. 🟨 Maximum Side Length of a Square with Sum ≤ Threshold (LeetCode 1292) We need to find the largest square submatrix such that: ✔ The sum of all its elements ≤ threshold ✔ Return the maximum possible side length 🧠 My Approach Built a 2D prefix sum array Used it to calculate any submatrix sum in O(1) Checked square sizes efficiently to find the maximum valid one This problem shows how preprocessing can drastically reduce complexity. 💡 What I Learned Prefix sums are extremely powerful for grid problems Brute force becomes practical after optimization Many matrix problems reduce to smart range queries 📊 Complexity Analysis Time Complexity: O(m × n × min(m, n)) Space Complexity: O(m × n) ✅ Day 76 Summary Simple idea. Strong technique. Clean implementation. Progressing steadily toward 100. 🚀 On to Day 77. #100DaysOfLeetCode #Day75 #LeetCode #PrefixSum #Matrix #DynamicProgramming #DSA #ProblemSolving #Python #CodingJourney #AdityaCodes
To view or add a comment, sign in
-
-
Day 75 of #100DaysOfLeetCode Today’s challenge focused on matrix optimization using prefix sums — a great example of turning brute force into an efficient solution. 🟨 Maximum Side Length of a Square with Sum ≤ Threshold (LeetCode 1292) We need to find the largest square submatrix such that: ✔ The sum of all its elements ≤ threshold ✔ Return the maximum possible side length 🧠 My Approach Built a 2D prefix sum array Used it to calculate any submatrix sum in O(1) Checked square sizes efficiently to find the maximum valid one This problem shows how preprocessing can drastically reduce complexity. 💡 What I Learned Prefix sums are extremely powerful for grid problems Brute force becomes practical after optimization Many matrix problems reduce to smart range queries 📊 Complexity Analysis Time Complexity: O(m × n × min(m, n)) Space Complexity: O(m × n) ✅ Day 75 Summary Simple idea. Strong technique. Clean implementation. Progressing steadily toward 100. 🚀 On to Day 76. #100DaysOfLeetCode #Day75 #LeetCode #PrefixSum #Matrix #DynamicProgramming #DSA #ProblemSolving #Python #CodingJourney #AdityaCodes
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 𝟵/𝟯𝟬 — 𝗗𝗦𝗔 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Day 9 of this journey, and one thing is becoming clear — many problems look different on the surface, but the underlying patterns keep repeating. The more I practice, the easier it gets to spot those patterns early. Today’s focus continued on two-pointer techniques and array manipulation — working on controlling pointer movement, handling edge cases, and keeping solutions efficient. 🔎 𝗗𝗮𝘆 𝟵 𝗙𝗼𝗰𝘂𝘀 • Strengthening two-pointer logic • Handling sorted arrays and boundary conditions • Solved: ✅ Remove Duplicates from Sorted Array ✅ Container With Most Water ✅ 3Sum Some of these definitely required a bit more thinking time, but that’s part of the process. Every challenging problem is just another step toward stronger problem-solving. On to Day 10 💪 #DSA #Python #LeetCode #LearningInPublic #Consistency #SoftwareEngineering #ProblemSolving
To view or add a comment, sign in
-
Tonight on the Programming for Lovers stream on YouTube (7:30 PM ET), we’re building one of the most beautiful things in computer science: Conway’s Game of Life. If you’ve never seen it: the rules are simple, but the behavior is not. We will get emergence, structure, motion, and patterns that feel alive; including the Gosper glider gun, a tiny machine that manufactures gliders forever. We’ll implement it in Python and make the visualization seen below for the gosper gun and other beautiful patterns. Won't you join us? 🐍🫶
To view or add a comment, sign in
-
I recently tackled an interesting sliding window problem: given a binary array, what is the maximum number of consecutive 1's you can get if you are allowed to flip at most k zeros? The Logic: Instead of trying every possible flip (which would be O(n^2) or worse), I used the Sliding Window (Two Pointers) technique. ✅ Expand: Move the right pointer to grow the window. ✅ Constraint Check: If we hit more than 'k' zeros, it's time to shrink the window from the left. ✅ Maximize: Keep track of the largest window size we've seen that satisfies the condition. Efficiency: By only passing through the array once, the solution hits an optimal O(n) time complexity and O(1) space complexity. It’s a classic example of how a dynamic window can turn a complex search into a streamlined linear process. Implementation: https://htmlify.me/r/6uhp #DataStructures #Algorithms #Python #CodingChallenge #SlidingWindow #ProblemSolving
To view or add a comment, sign in
-
-
🚀 #Day26 of #LeetCode Challenge 🧩 Problem Solved: 12. Integer to Roman Today’s problem was about converting a number into its Roman numeral representation. Sounds simple… but the tricky part is handling special cases like 4 (IV), 9 (IX), 40 (XL), 90 (XC), 400 (CD), and 900 (CM). 🔥 Key Learning: Instead of building logic digit by digit, I used a greedy approach: ✅ Create a mapping of values to Roman symbols ✅ Start from the largest value (1000 → 1) ✅ Keep subtracting while adding corresponding symbols ✅ Move downward This ensures we always build the Roman numeral in the correct order. ✔ All test cases passed Every day I’m realizing — most medium problems are about choosing the right pattern, not complicated logic. Consistency > Motivation 💯 Google #LeetCode #DSA #Python #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
BUILT AN AI OBSERVABILITY USING LANGFUSE Spent some time figuring out how to monitor local LLM agents properly. Turns out Langfuse + OpenTelemetry makes it pretty straightforward. The demo shows: - RAG with a recipe knowledge base (PgVector vector DB + Ollama embeddings) - Stock price lookups with YFinance - File system access through MCP tools - All traces flowing into Langfuse Everything runs locally with Ollama: - LLM: Llama 3.2 - Embeddings: nomic-embed-text Best part? You can actually see what your agent is doing - which docs it grabbed, how long each step took, where it failed. Makes debugging way easier. Using Agno framework because it plays nicely with async Python and has clean tool integration. Check out the demo recording to see it in action. Code's on GitHub if you want to try it. https://lnkd.in/gHmhf8Tb ##aiobservability #langfuse #Agno #python #ollama #pgvector
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