Euclidean Algorithm: 2300 years old, still the most elegant solution I've seen. This morning's Codewars problem: Find the Greatest Common Divisor of two numbers. My first instinct? Write a loop. Seven lines of code. It worked, but felt clunky. Then I thought: "This feels recursive." Spent 10 minutes staring at the screen. "What's the base case?" "How do I reduce the problem?" Then it clicked. The insight: GCD(a, b) is just GCD(b, remainder). Keep calling until the remainder is zero. That's your answer. Four lines instead of seven. Elegant instead of clunky. Recursive instead of iterative. What makes it beautiful: → Each step is simpler than the last → The solution emerges naturally → Base case is obvious (when b = 0) Traced through an example: GCD(48, 18) becomes GCD(18, 12) which becomes GCD(12, 6) which becomes GCD(6, 0) Answer: 6 Euclid figured this out in 300 BC. I figured it out this morning. Better late than never. This is why I solve algorithms daily. Not for interviews. For the mindset. Learning to see problems recursively changes how you code. #Algorithms #Recursion #Codewars #JavaScript #LearningInPublic
Yordan Gergov’s Post
More Relevant Posts
-
⚡ Day 151 of 160 – GeeksforGeeks #gfg160 DSA Challenge 📘 Problem: Bellman-Ford Algorithm 💻 Language: JavaScript 📂 Topic: Graph | Shortest Path | Dynamic Programming 🧠 Problem Summary: Given a weighted directed graph with V vertices and E edges, find the shortest distance from a source vertex S to all other vertices — even if negative edge weights exist. If there’s a negative weight cycle, report it. ✅ Approach Used: Bellman-Ford Algorithm (Dynamic Programming + Relaxation) Initialize dist[] with infinity for all vertices, except dist[S] = 0. Relax all edges V - 1 times: For each edge (u, v, w), if dist[u] + w < dist[v], update dist[v] = dist[u] + w. Run one more iteration to check for negative weight cycles. If any edge can still be relaxed → negative cycle detected. 📊 Example: Edges = [[0,1,5],[1,2,-2],[0,2,3]] Shortest distances from 0: [0, 5, 3] ⏱ Time Complexity: O(V × E) 📦 Space Complexity: O(V) 🔍 Key Insights: Works for negative edges, unlike Dijkstra. Fails only if a negative cycle exists. Relies on the idea that shortest paths contain at most (V - 1) edges. 💡 Takeaway: Bellman-Ford beautifully blends graph theory with DP-style relaxation, teaching the importance of iterative updates and cycle detection in weighted graphs. #Day151 #DSAChallenge #BellmanFord #GraphAlgorithm #ShortestPath #DynamicProgramming #JavaScriptDSA #GeeksForGeeks160 #160DaysOfCode #NegativeWeightCycle #AlgorithmLearning #CodingChallenge #TechInterviewPrep #ProblemSolvingDaily #GraphTheory
To view or add a comment, sign in
-
-
I recently published streamlit-iiif-viewer, a new Streamlit component that makes it easy to embed the IIIF viewer of your choice directly into your apps. For context, IIIF (International Image Interoperability Framework) is a set of open standards for delivering and describing high-quality images and metadata over the web. It is gradually adopted by GLAM (galleries, libraries, archives and museums); but not only! The goal of IIIF is to ensure interoperable access to digitized (cultural) materials: with IIIF, any viewer can display, annotate images or build collection of images from any institution that supports the protocol. This component provides an easy and simple Python interface to integrate IIIF manifests — via URL or custom Python dict (that validate IIIF Presentation API v3 schema) — without worrying about frontend setup. Perfect for fast prototyping to build proofs of concept that combine IIIF and AI tools for exemple. Currently, only Tify and Mirador IIIF viewers are supported. Install the package via PyPi : pip install streamlit-iiif-viewer Check it out the open-source code on GitHub: https://lnkd.in/e2akZaUy Test the demo here: https://lnkd.in/eu7t2XV7 #iiif #Streamlit #OpenSource #Python #DigitalHumanities
To view or add a comment, sign in
-
-
🚀 Mastering Array Recursion: Flattening Nested Structures Ever run into a deeply nested array and wished there was a clean, elegant way to make it flat? While built-in methods like Array.prototype.flat() are great, understanding the recursive approach is a fantastic way to sharpen your JavaScript fundamentals and master complex data structures! The Challenge 🤯 We want to transform an array like this: [1, [2, 3], [4, [5, 6]], 7] Into a flat array: [1, 2, 3, 4, 5, 6, 7] The Recursive Solution 🧠 Why Bother with Recursion? 🤔 Fundamental Skill: Recursion is a core computer science concept. Mastering it helps you better understand algorithms, tree traversals, and dynamic programming. Readability: For naturally recursive problems (like nested arrays or tree structures), the recursive solution often mirrors the problem's structure, making the code surprisingly elegant and readable. Interview Readiness: This is a classic coding interview problem designed to test your command of JavaScript and core algorithm design. Keep challenging yourself with these fundamentals! Happy coding! #JavaScript #Recursion #WebDevelopment #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 50: Binary Search Tree Iterator (BST) 🌲 I'VE HIT THE HALFWAY MARK! Day 50 of #100DaysOfCode is dedicated to mastering the "Binary Search Tree Iterator." This challenge requires designing a class that enables in-order traversal of a BST using constant time complexity for the key operations. The key insight is using an Iterative Inorder Traversal with a Stack: __init__ (Initialization): The constructor doesn't traverse the whole tree. It uses a helper function (_push_left) to initially push the root and all its left descendants onto the stack. This positions the stack to start at the smallest element. next(): This method retrieves the next smallest element. It simply pops the top element from the stack, and then immediately checks if that popped node has a right child. If it does, it calls _push_left on the right child to load the next set of smallest elements onto the stack. Efficiency: The design ensures that while an element is pushed and popped exactly once overall (O(n) total time), the amortized time complexity for both next() and hasNext() is O(1). This was a perfect problem to mark the halfway point—combining Data Structures and Algorithmic Design! #Python #DSA #Algorithms #BST #Iterator #Stack #100DaysOfCode
To view or add a comment, sign in
-
-
🔼 Day 165 of #200DaysOfCode Today, I revisited a fundamental concept that plays a major role in data structures and algorithm design — sorting an array in ascending order using Bubble Sort (without built-in sort methods). 💡 Modern JavaScript gives us shortcuts like Array.sort(), but when we build the logic manually, we develop a much deeper understanding of: • Pairwise comparison • Value swapping in arrays • Nested looping structure • Time complexity (Bubble Sort → O(n²)) Sorting isn’t just a beginner concept — it’s the backbone of efficient searching, optimization, and real-world computational logic. 🔁 Going back to basics reminds me that advanced problem-solving ability is built on strong fundamentals, not shortcuts. 🌱 Every step forward in coding is supported by the basics we choose to master — and revisit. #JavaScript #200DaysOfCode #CodingChallenge #Sorting #Algorithms #WebDevelopment #DeveloperMindset #LearnInPublic #DSA #ProblemSolving
To view or add a comment, sign in
-
-
🎨 Solving “Sort Colors” — The Dutch National Flag Problem Today I tackled a classic array problem on LeetCode: Sort Colors (#75). 🧩 The Challenge: We are given an array of integers 0, 1, and 2, representing colors: red, white, and blue. The goal is to sort the array in-place so that all 0s come first, followed by 1s, and then 2s — without using built-in sort functions. 💡 Key Insight / Pattern This problem is famously known as the Dutch National Flag problem. The idea is to use three pointers to divide the array into three sections: low → next position for 0 mid → current element under consideration high → next position for 2 We traverse the array once, swapping elements into the correct section. This results in O(n) time and O(1) space — very efficient! 🔹 Approach If nums[mid] == 0: swap with nums[low] → move low and mid forward If nums[mid] == 1: do nothing → move mid forward If nums[mid] == 2: swap with nums[high] → move high backward This single-pass, in-place approach neatly separates the colors while keeping the code simple. 🧠 Pattern Recognized Three-pointer array partitioning — useful for problems involving limited value sets or segregating arrays efficiently. Related Problems: Move Zeroes (#283) Partition Array (#215) Merge Sorted Array (#88) 💬 Takeaway: Understanding patterns like the Dutch National Flag not only helps in solving specific problems efficiently but also trains your mind to see structure in seemingly random arrays — a skill that’s invaluable for coding interviews and problem-solving in general. #LeetCode #DSA #Python #Algorithms #CodingInterview #ProblemSolving #Arrays #TwoPointers #TechJourney
To view or add a comment, sign in
-
-
🔽 Day 166 of #200DaysOfCode Today, I continued sharpening my fundamentals by implementing Bubble Sort in descending order — without using JavaScript’s built-in .sort() method. 💡 While sorting might look simple on the surface, it is one of the most essential concepts in programming — powering search algorithms, intelligent ordering systems, real-time data processing, and more. By writing this logic manually, I reinforced: ✅ How comparisons work inside loops ✅ Value swapping and index manipulation ✅ Time complexity analysis (O(n²) for Bubble Sort) ✅ Why optimized sorting algorithms matter in bigger datasets 🌱 Every advanced concept in Data Structures & Algorithms is built on these fundamentals — and revisiting them helps improve clarity, confidence, and coding discipline. 🔁 Progress in programming isn’t linear — it’s iterative. Master the basics, and everything else becomes easier. #JavaScript #166DaysOfCode #BubbleSort #Algorithms #WebDevelopment #DSA #CodingChallenge #ProblemSolving #LearnInPublic #DeveloperMindset
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 96 Problem: String to Integer (atoi) 🔢➡️💻 This is a classic implementation problem that tests careful handling of edge cases, parsing logic, and boundary conditions. 🧠 Problem Summary: Implement the function myAtoi(string s) that converts a string into a 32-bit signed integer following specific parsing rules. Steps to follow: 1️⃣ Ignore leading whitespaces. 2️⃣ Check the sign (+ or -). 3️⃣ Read digits until a non-digit character is found. 4️⃣ Handle overflow/underflow by clamping the number within the 32-bit signed integer range: Range = [−2³¹, 2³¹ − 1] 5️⃣ Return the final integer. ⚙️ My Approach: Trim leading spaces using lstrip(). Identify the sign based on the first non-space character. Iterate through the string and build the number digit by digit. Multiply by the sign and ensure the result stays within integer limits using max() and min(). 📈 Complexity Analysis: Time: O(n) — traverse each character once. Space: O(1) — only a few variables used. ✨ Key Takeaway: This problem is a great example of careful boundary handling and parsing logic — it’s not just about coding, but about thinking through every possible input case. 🔖 #DSA #100DaysOfCode #LeetCode #ProblemSolving #Python #CodingChallenge #myAtoi #StringParsing #AlgorithmDesign #InterviewPrep #TechCommunity #LearningEveryday
To view or add a comment, sign in
-
-
Docs A real-time collaborative editor that turns notes into shared, structured knowledge with seamless co-authoring and version-aware workflows ⭐ Stars: ~14.2k 🍴 Forks: 430 🧾 License: MIT 🧩 Languages: Python 🌐 https://lnkd.in/gAmKXvmp 💻 https://lnkd.in/dbeFSTNn ✨ Features: * Simple editor & clean formatting * Inline or Markdown * Slash blocks & shortcuts * Offline edits with sync * AI actions (rewrite/summarize) * Live collab & access control 🔔 Discover Open Source. Every Day
To view or add a comment, sign in
-
Think any value equals itself? Adorable. `NaN === NaN` is `false`. Your simple `if (result === NaN)` check for bad math will silently fail every single time. You have to use `Number.isNaN()`. Is this strict mathematical purity, or a sadistic language trap designed to make debugging a nightmare? #GaboTips #JS
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