Day 95 of my #100DaysOfCode journey 🚀 Today I solved the Number of Enclaves problem using BFS on a grid. Problem intuition: We are given a grid of land (1) and water (0), and we need to count how many land cells are part of an enclave — meaning they cannot reach the boundary of the grid. Key idea: If a land cell is connected to the boundary, it is not an enclave. Approach: • Push all boundary land cells (1) into a queue • Use BFS to mark all land connected to the boundary as visited / water • After traversal, count the remaining land cells • Those remaining cells are the enclaves Concepts reinforced: • BFS on 2D grid • Boundary traversal pattern • Connected components • Grid-to-graph conversion Time Complexity: • O(n × m) → every cell is processed at most once This problem is another strong reminder that many “grid problems” are really just graph traversal problems in disguise. The more I practice these patterns, the more naturally the solutions start forming. 🌱 #100DaysOfCode #DSA #Graphs #BFS #GridProblems #Algorithms #Python #CodingJourney #ProblemSolving #SoftwareEngineering
Day 95: Solving Number of Enclaves with BFS on Grid
More Relevant Posts
-
I thought State in LangGraph was just a dict you pass around. It is not. It is a reducer. When I built a pipeline that spawns 5 parallel thumbnail generators, each one returns {"thumbnail_prompts": [some_prompt]}. I expected a collision. Five workers, one key, last-write-wins. What actually happens: Annotated[list[str], operator.add] tells LangGraph to reduce those results by appending them. Each parallel worker's output gets merged into a single list automatically. No locks. No race conditions you have to manage. The type annotation is not documentation. It is a runtime instruction to the framework. This is the part the tutorial skips. You can follow a LangGraph getting-started guide entirely and never encounter Annotated with a reducer. But once you hit actual parallelism, it is the difference between a system that works and one that silently drops data. The abstraction is clean. What made it click was understanding that the type system and the execution engine are the same thing here. #Python #LangGraph #SystemDesign
To view or add a comment, sign in
-
-
🚀 Stop iterating through your DataFrames like it's 2010. I recently refactored a pipeline processing 50M rows. We were using a standard loop to calculate a rolling average, which was choking our CPU and stalling the entire cluster. Before optimisation: for i in range(len(df)): df.loc[i, 'avg'] = df['val'].iloc[i-5:i].mean() After optimisation: df['avg'] = df['val'].rolling(window=5).mean() Performance gain: 45x faster execution time. By moving from a row-based loop to a vectorised rolling window function, we cut the execution time from 12 minutes down to 16 seconds. The underlying implementation of Polars and Pandas handles these operations in highly optimised C/Rust, which no Python loop can match. Stop writing row-wise operations and start leveraging vectorisation. It’s the single biggest win for data processing throughput. What is the most expensive loop you have ever managed to replace with a vectorised operation? #DataEngineering #Python #PerformanceTuning #DataScience #CodingTips
To view or add a comment, sign in
-
Learn about numpy sorting with real time example, In this video, we cover: 00:07 Basic Sorting in ascending order 00:50 Descending sorting 01:43 argsort explaning 04:04 partition 05:36 2d dimensional array. #numpy #python #datascience #machinelearning #coding https://lnkd.in/gqnjPFhs
NumPy Sorting Explained with Real Example | sort(), argsort(), partition(), 2D Arrays
https://www.youtube.com/
To view or add a comment, sign in
-
Day 2 of the 30 Days Challenge with .Starting from the very Basics, we were introduces to Data types; Strings, Integers, boolean etc. Today we focus on integers on Jupiter notebook. starting from the very Basic arithmetic and how it is used in python2^2. = 2**22x2 = 2*22÷2 = 2/22+2 & 2-2 = 2+2 & 2-2...#AI#MachineLearning#Datatypes#M4ACE#30DayChallenge
To view or add a comment, sign in
-
-
🚀 Another LeetCode Problem Solved: Palindrome Number! 🔗 Check out my solution: https://lnkd.in/dwDMqXXn 💡 Problem Overview Given an integer x, determine whether it is a palindrome — meaning it reads the same forward and backward. (LeetCode) Examples: ✔ 121 → Palindrome ❌ -121 → Not a palindrome ❌ 10 → Not a palindrome 🧠 My Approach (Digit Reversal) Instead of converting the number to a string, I used a mathematical approach: Extract digits using % 10 Reverse the number step by step Compare reversed number with original ⚙️ Key Learnings ✔ Strong understanding of number manipulation ✔ Importance of handling edge cases (negative numbers, trailing zeros) (leet-solution.com) ✔ Practicing clean and efficient logic ⏱️ Complexity • Time Complexity: O(log n) • Space Complexity: O(1) 🔥 Why this problem matters Even though it’s an “easy” problem, it builds: Logical thinking Problem-solving fundamentals Confidence for bigger challenges 🚀 Next Goal Move towards optimized approaches and medium-level problems to strengthen DSA skills. #LeetCode #DSA #Python #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
Unlocking the hidden superpower of Binary Search Trees! 🔓🌲 Kth Smallest Element in a BST - LeetCode 230 - Medium (Blind 75) If you want to find the "kth smallest" number in a normal array or a standard tree, you usually have to gather all the numbers and sort them first. But a Binary Search Tree (BST) has a built-in superpower: it already stores data in a naturally sorted way! (The Inorder Secret): The secret to unlocking a BST is a specific way of walking through it called "Inorder Traversal" (Left child -> Current Node -> Right child). If you read a BST this way, you visit the nodes in perfectly ascending order. So, instead of collecting all the nodes, I just started counting them as I walked: 1. Go as far left as possible (to the absolute smallest number). 2. Start walking back up, visiting nodes and increasing a `count`. 3. The exact moment `count == k`, we have found our target! Save it to `result` and stop. Key Learnings: 1) Inorder = Sorted: Always remember that an Inorder Traversal of a valid BST will always process the nodes in strictly increasing order. This is a massive cheat code for BST problems. 2) Early Exit: We don't need to traverse the entire tree. By tracking the count, we can stop the moment we hit our target, saving valuable processing time. 3) State Management: Using class variables (`self.count` and `self.result`) is a clean way to maintain state across multiple recursive calls without having to pass them down as arguments every single time. Time and Space Complexity: Time Complexity: O(H + k) — Where H is the height of the tree. We take O(H) time to reach the leftmost leaf, and then O(k) time to find the kth element. Space Complexity: O(H) — The call stack memory will at most hold H nodes (the height of the tree). Shifting from standard Binary Trees to Binary Search Trees makes you appreciate how data structure design naturally solves problems for you. What is your favorite BST property? 👇 #LeetCode #BinarySearchTree #Blind75 #DataStructures #Python #Recursion #Algorithms #TechInterviews #SoftwareEngineering #MCAFreshers #CodingJourney
To view or add a comment, sign in
-
-
🚀 Another LeetCode Problem Solved: Palindrome Number! 🔗 Check out my solution: https://lnkd.in/dwDMqXXn 💡 Problem Overview Given an integer x, determine whether it is a palindrome — meaning it reads the same forward and backward. (LeetCode) Examples: ✔ 121 → Palindrome ❌ -121 → Not a palindrome ❌ 10 → Not a palindrome 🧠 My Approach (Digit Reversal) Instead of converting the number to a string, I used a mathematical approach: Extract digits using % 10 Reverse the number step by step Compare reversed number with original ⚙️ Key Learnings ✔ Strong understanding of number manipulation ✔ Importance of handling edge cases (negative numbers, trailing zeros) (leet-solution.com) ✔ Practicing clean and efficient logic ⏱️ Complexity • Time Complexity: O(log n) • Space Complexity: O(1) 🔥 Why this problem matters Even though it’s an “easy” problem, it builds: Logical thinking Problem-solving fundamentals Confidence for bigger challenges #LeetCode #DSA #Python #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
A Renko forecasting pipeline was tested on EURUSD using MetaTrader 5 tick/time-bar data converted into 11,578 Renko bars with ATR-derived brick size 0.00028. Training used 60 days of M5 history and 14 engineered features covering direction sequences and volume stats. CatBoost delivered 59.27% test accuracy. Feature importance was led by volume: last_volume (18.36), avg_volume (14.23), volume_ratio (12.81), followed by consecutive-move metrics, challenging price-pattern-heavy rule sets. Implementation stack: Python, numpy, pandas, MetaTrader5 API, catboost. Modules cover data ingest, Renko conversion, feature generation, cross-validated training, and probability-based signaling with a 75% confidence threshold. #MQL5 #MT5 #AlgoTrading #AITrading https://lnkd.in/dAGfEC7K
To view or add a comment, sign in
-
-
Geospatial Technologies essential keywords, daily Tips 🌎 : Keyword : Xarray Category :Programming Xarray is a Python library that extends NumPy’s ndarray to support labelled, multi‑dimensional arrays with dimension, coordinate, and attribute metadata, enabling intuitive indexing, broadcasting, and operations on spatial data grids. Its DataArray and Dataset objects mirror the structure of NetCDF files, making it ideal for climate, remote‑sensing, and geospatial workflows that require efficient handling of large raster datasets and seamless integration with libraries such as pandas, dask, and xgcm. By preserving semantic information through coordinate labels, X #TechGeoMapping #EssentialKeywords
To view or add a comment, sign in
-
Day 25 of 100 Completed Today connected cycle detection with arrays and wrapped up the Titanic EDA work. • #287 - Find the Duplicate Number (Medium) - solved • Completed Titanic dataset EDA 🔎 Focus Areas • Applying cycle detection in arrays (Floyd’s Algorithm) • Understanding value-index mapping as a linked structure • Finalizing insights from a real-world dataset 💡 Key Takeaways (DSA) 📌 #287 Find the Duplicate Number This problem looks like an array problem, but it’s actually a hidden linked list: treat index → value as a pointer detect cycle using slow-fast pointers the meeting point helps find the duplicate Key insight: some problems disguise known patterns - recognizing them is the real skill. 🚀 Python + EDA (Titanic Dataset) Completed the EDA process on the Titanic dataset. 💡 Key Takeaways (Python) • Able to clean, explore, and visualize data end-to-end • Better understanding of relationships between features • More confidence in using Pandas + visualization libraries together ⚡ Honest Reflection This was a milestone day. Finishing a full EDA cycle on a real dataset is a solid step forward. On the DSA side, recognizing cycle detection in an array context shows real improvement in pattern recognition. Still need to go deeper into extracting meaningful insights from data, not just performing steps. Consistency is strong. Progress is becoming more practical and applied. Patterns recognized: Cycle Detection | Floyd’s Algorithm | Array as Linked List | Pattern Recognition | EDA | End-to-End Analysis #100DaysOfCode #DSA #Python #EDA #Pandas #LeetCode #BuildInPublic #CodingJourney #Consistency
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