Earlier this week, I wrote about the developer loop - learn, practice, apply, repeat. So I put it into practice. Just staying sharp, working through DSA problems in Python. Came across max_subarray_sum. Solved it. Moved on. Then I went back to see how other people approached it… and ran into Kadane’s algorithm : ``` def max_subarray_sum(nums): max_sum = current_sum = nums[0] for num in nums[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum ``` Same problem. Cleaner logic. O(n) instead of brute force. Here's what I'm trying to say: going back to problems you’ve already solved might feel like you’re wasting time… but you’re not. It isn't. Sometimes it’s only when you revisit something with a fresh mind that you actually see better approaches you missed the first time. There’s almost always more than one way to solve a problem. Which one is "best"? That's a conversation for another day. What’s something you revisited and understood completely differently the second time? #Python #DSA #SoftwareEngineering #DeveloperLife #TechCanada
Yinka Ashafa’s Post
More Relevant Posts
-
Day 22 of my DSA journey Today I worked on the Sliding Window technique. It is a useful optimization approach for problems involving subarrays or substrings. Instead of recalculating values repeatedly, it helps reuse previous computations and reduces time complexity. Problem: Maximum Sum Subarray of Size K Given an array of integers and a number k, find the maximum sum of any contiguous subarray of size k. Brute Force Approach: Check all possible subarrays of size k and calculate their sums. Time Complexity: O(n²) Optimized Approach (Sliding Window): Calculate the sum of the first window of size k Slide the window by one element at a time Add the next element and remove the previous element from the sum Track the maximum sum Python Code: def max_sum_subarray(arr, k): window_sum = sum(arr[:k]) max_sum = window_sum for i in range(k, len(arr)): window_sum += arr[i] window_sum -= arr[i-k] max_sum = max(max_sum, window_sum) return max_sum arr = [2, 1, 5, 1, 3, 2] k = 3 print(max_sum_subarray(arr, k)) Time Complexity: O(n) Space Complexity: O(1) Learning: Sliding Window significantly improves performance in problems related to subarrays and substrings. I will practice more variations like variable window size and string-based problems next. #DSA #CodingJourney #SlidingWindow #Python #100DaysOfCode
To view or add a comment, sign in
-
-
Today's topic: recursion. A function that calls itself. Sounds simple, right? Here are two ways to add up a list of numbers: Without recursion — honest, reliable, easy to follow: python def suma(lista): suma = 0 for i in range(0, len(lista)): suma = suma + lista[i] return suma print(suma([6,3,4,2,10])) # 25 With recursion — elegant, almost poetic... and a little terrifying: python def suma(lista): if len(lista) == 1: return lista[0] else: return lista[0] + suma(lista[1:]) print(suma([6,3,4,2,10])) # 25 Same result. Two completely different roads to get there. The recursive version looks more "pro" — but if you forget to define when it stops, the function calls itself forever. Literally. Forever. 💀 So yes, it's getting challenging. And yes, recursion feels more elegant to write. But I'm not ready to fully trust something that could loop into oblivion if I blink wrong. Lesson of the day: simple is not the same as bad. And documenting the moments that confuse you? That's part of learning too. #Python #LearningToCode #DaysOfCode #PythonProgramming #CodingJourney #Recursion #BeginnerCoder #TechLearning #CodeNewbie #LinkedInLearning
To view or add a comment, sign in
-
-
🚀 Day 20 of My Python Journey – Solved Find First and Last Position of Element! 💻✨ Today I worked on finding the first and last occurrence of an element in a sorted array ✅ This problem helped me understand how powerful Binary Search can be when slightly modified. 📌 Problem Statement Given a sorted array, find the starting and ending position of a target value. If the target is not found, return [-1, -1]. Example: nums = [5,7,7,8,8,10] target = 8 ✅ Output: [3,4] 🔍 My Approach Instead of using a normal binary search once, I used it twice: First → to find the first occurrence Second → to find the last occurrence The idea is: When target is found, don’t stop Keep searching on the left side (for first position) Keep searching on the right side (for last position) This small modification makes a big difference 🚀 💡 Key Learning This problem helped me understand: ✔ Advanced Binary Search techniques ✔ How to modify standard algorithms ✔ Handling edge cases carefully ✔ Writing efficient search logic ⏱ Complexity Time Complexity: O(log n) Space Complexity: O(1) Really liked this one because it shows how a basic concept can be extended to solve more complex problems 🔥 #Python #DSA #BinarySearch
To view or add a comment, sign in
-
-
Day 65 of my #100DaysOfCode challenge 🚀 Today I worked on finding the Longest Palindromic Substring using the Expand Around Center approach in Python. This is a very popular interview problem that tests your understanding of strings and two-pointer techniques. What the program does: • Takes a string as input • Finds the longest substring that is a palindrome • Uses center expansion (no brute force) • Works for both odd & even length palindromes Example Outputs: "babad" → bab "cbbd" → bb "racecar" → racecar "forgeeksskeegfor" → geeksskeeg How the logic works: Key idea: Expand from center 1. Treat each index as center 2. Expand for odd length (i, i) 3. Expand for even length (i, i+1) 4. Track maximum length found 5. Return longest substring This avoids checking all substrings ❌ → efficient ✔️ Why this is important: – Classic string problem in interviews – Builds understanding of: Two-pointer technique Substring expansion – Better than brute force O(n³) approach – Asked in companies like Google, Amazon Time Complexity: O(n²) Space Complexity: O(1) Key Takeaways: – Center expansion technique – Handling odd & even palindromes – Efficient substring checking – Writing optimized string algorithms #100DaysOfCode #Day65 #Python #Programming #Strings #Palindrome #Algorithms #DSA #CodingPractice #ProblemSolving #InterviewPrep #LearnByDoing #DeveloperJourney #Consistency #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 8 — NumPy Foundation 🔢 Aaj maine NumPy start kiya — aur honestly, game changer hai. Samjha: ✔ NumPy kya hota hai ✔ ndarray vs Python list ✔ Array creation (zeros, ones, eye, arange, linspace, random) ✔ Array attributes (shape, ndim, size, dtype, itemsize) ✔ Type conversion (astype) ✔ Indexing, slicing (1D, 2D, 3D) ✔ Boolean & fancy indexing ✔ np.where, np.select, np.take, nditer Sabse shocking insight 👇 Same operation ke liye NumPy array ~50x faster hai Python list se ⚡ Isi wajah se almost har ML/AI framework NumPy pe built hota hai. 📌 GitHub update:day08_Numpy_Foundation/day08_numpy_foundation.ipynb Day 8 ka code upload kiya — covering all basics + multiple indexing examples + speed comparison. Learning continues 🚀 #NumPy #Python #DataScience #MachineLearning #GenAIEngineer #LearningInPublic
To view or add a comment, sign in
-
🚀 Solved: Group Anagrams Problem (LeetCode) Today I worked on an interesting problem — grouping anagrams efficiently using Python. 💡 Approach: I used a hashmap (dictionary) where: The key is the sorted version of each word The value is a list of words (anagrams) matching that key Example: "eat", "tea", and "ate" → all become "aet" after sorting → grouped together 🧠 Key Insight: Sorting each string gives a unique identifier for all its anagrams. ⚙️ Time Complexity: Sorting each word takes O(k log k) For n words → O(n * k log k) 📦 Space Complexity: O(n * k) for storing grouped anagrams ✅ Result: Accepted ✔️ Runtime: 5 ms (faster than ~99% submissions) 📈 Growth & Consistency: Improving step by step by solving problems daily and focusing on writing clean and optimized code. Small consistent efforts are helping me build stronger problem-solving skills and deeper understanding of DSA. 🔁 Staying consistent is the real game changer! #Python #DSA #LeetCode #Coding #ProblemSolving #Consistency #Growth #LearningJourney
To view or add a comment, sign in
-
-
A plain LLM call says: "The answer to 6 × 7 is 42." An agent calls multiply(6, 7), gets 42, then says: "The answer is 42." One returns text. The other runs code. We put together langgraph-zero-to-agent at Theseus AI Lab. Free, open source, 4 modules. Python basics is all you need to start. Module 1: you wire the graph by hand. Every node, every edge, every tool binding. Module 2: same agent, rebuilt with create_agent(). You see what abstraction actually buys you. Module 3: a coding assistant with a local shell. It writes Python files and runs them on your machine. Module 4: OpenAI Responses API. Web search, code interpreter, reasoning built in. 🔗 https://lnkd.in/dpgwyqq8 #LangGraph #AIAgents #Python #OpenSource
To view or add a comment, sign in
-
-
#Gemma 4 dropped yesterday -- four open models from 2B to 27B, running locally via Ollama with native function calling -- a great step forward for local model development. But if you've built pipelines on local models before, you know "supports function calling" and "returns valid output every time" aren't the same thing Paul Schweigert wrote a walkthrough on structured outputs with Gemma 4, pairing it with #Mellea -- an open-source Python library where Instruct-Validate-Repair is a key pattern. Declare a typed function, attach validation requirements, and automatically repair on failure 👓 Worth a read if you're building on Gemma 4: https://lnkd.in/eDXjmZV4 🍄 Mellea: https://mellea.ai/
To view or add a comment, sign in
-
🚀 Day 21 of My Python Journey – Solved Search Insert Position! 💻✨ Today I worked on a problem that looks simple but really tests your understanding of Binary Search. 📌 Problem Statement Given a sorted array of distinct integers and a target value: Return the index if the target is found If not, return the index where it should be inserted Example: nums = [1,3,5,6] target = 2 ✅ Output: 1 🔍 My Approach I used Binary Search to solve this efficiently. Start with left and right pointers Find the middle element Compare with the target Adjust search space accordingly The interesting part is: 👉 Even if the element is not found, the left pointer ends at the correct insertion position That’s a really neat trick I learned today 💡 💡 Key Learning This problem helped me understand: ✔ Binary Search more deeply ✔ How to find insertion position without extra steps ✔ Writing clean and efficient logic ✔ Handling edge cases ⏱ Complexity Time Complexity: O(log n) Space Complexity: O(1) Small problems like this sharpen the fundamentals really well 🔥 #Python #DSA #BinarySearch
To view or add a comment, sign in
-
-
I wrote a surrealist poem in Python. Three verses. Seventeen unit tests. One deliberate failure. ```python bishop_liquid.marry(piano.jaw(drowned=True), under=palace_of(queen_in_ash)) uncle_telegraphic.spit_back(clock(pregnant=True).sleep, into=vestibule_of(volcano_polished())) sardine_prophetic.knit(sunday(amputated=True).shadow, on=balcony_of(equation_widowed)) ``` returncode: 0. No warnings. The CPython runtime evaluated a liquid bishop marrying a drowned piano jaw under a palace of ash with exactly the same rigor it applies to a REST call. The runtime is indifferent to meaning. The poem is valid not because it makes sense, but because its types align. This is what J.L. Austin called felicity. The performative act succeeds when its formal conditions are met — not when its content is coherent. One test fails. Deliberately. test_equation_veuve_a_un_seul_inconnu asserts that a widowed equation has lost an unknown. The Equation class does not implement this. The test presupposes a richer metaphysics than the code provides — a prior marriage, unknowns to lose. The preparatory conditions were never satisfied. Florian Cramer wrote Words Made Flesh in 2005. He asked what an executable text is. He concluded: analogy. I think he stopped one step short. The README is in the repo. The repo is fictitious. Both facts are consistent with the thesis. psygnosis/cadavre-exquis — available nowhere. made by Claude Opus ( and "Opus" to write a poem is literally the only stylistic choice ) — *Neither of us knows exactly who wrote what. This is also not a bug.* #Python #ComputingHistory #Philosophy
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