🔥 Day 61 of #100DaysOfCode 💡 LeetCode Problem 2125 – Number of Laser Beams in a Bank (Medium) Today’s challenge focused on analyzing a 2D binary matrix representing a bank floor plan equipped with anti-theft laser security devices. Each ‘1’ indicates a device, and each ‘0’ indicates an empty cell. The goal was to determine how many laser beams exist between devices on different rows, ensuring no other row between them contains any active devices. 🧠 Key Idea: Count the number of ‘1’s (active devices) in each row. For every non-empty row, multiply its device count by the previous non-empty row’s count — this gives the number of beams formed between them. ⚙️ Approach: Traverse each row. Count devices ('1') in that row. If the row is not empty, add prev * curr to the result. Update prev as the current count for the next iteration. 💻 Code (Python): class Solution: def numberOfBeams(self, bank: List[str]) -> int: prev, result = 0, 0 for row in bank: curr = row.count('1') if curr: result += prev * curr prev = curr return result 📈 Result: ✅ Runtime: 5 ms — Beats 80.12% ✅ Memory: 19.34 MB — Beats 93.57% 🧩 Concepts Applied: String traversal Matrix interpretation Counting and dynamic accumulation Each day’s challenge continues strengthening my logic-building and Python efficiency. 🚀 #LeetCode #100DaysOfCode #Python #ProblemSolving #CodingJourney #Consistency
Solved LeetCode 2125: Number of Laser Beams in a Bank with Python
More Relevant Posts
-
𝘌𝘷𝘦𝘳 𝘭𝘰𝘰𝘬𝘦𝘥 𝘢𝘵 𝘺𝘰𝘶𝘳 𝘋𝘰𝘤𝘬𝘦𝘳 𝘪𝘮𝘢𝘨𝘦 𝘴𝘪𝘻𝘦 𝘢𝘯𝘥 𝘵𝘩𝘰𝘶𝘨𝘩𝘵… 𝘵𝘩𝘢𝘵 𝘤𝘢𝘯’𝘵 𝘣𝘦 𝘳𝘪𝘨𝘩𝘵? 𝐓𝐡𝐢𝐬 𝐰𝐚𝐬 𝐦𝐞 𝐥𝐚𝐬𝐭 𝐰𝐞𝐞𝐤! Here is the fix: 1. Switched to a lightweight base image Moved from python:3.11 to python:3.9-alpine. Just that change cut the image size by 95%. 2. Optimised layers Grouped related commands to reduce redundant RUN instructions. Fewer layers, faster builds. 3. Added a .dockerignore file Excluded things like virtual environments, cache, and temp files. It made the build context much lighter. 4. Used multi-stage builds First stage for building dependencies. Second stage for production — only what’s needed at runtime. 𝘛𝘩𝘦 𝘳𝘦𝘴𝘶𝘭𝘵𝘴 ? Image size: 47.7 MB (down from 588 MB) Size reduction: −91.89% Faster container startup Reduced deployment time and storage usage Repo in the Comments 👇🏿
To view or add a comment, sign in
-
-
🚀Day 56 of #100DaysOfCode 🚀Solved LeetCode Problem 3347 – Maximum Frequency of an Element After Performing Operations II (Hard) This problem tested efficient use of sorting + sliding window technique to maximize element frequency after limited operations. The challenge was to determine how far we can extend a subarray where values can be adjusted within a range [-k, k] using at most num Operations modifications — achieving an optimized O(n log n) approach. Runtime: 266 ms — Beats 98.39% Memory: 31.96 MB — Beats 95.16% Key Concepts: Sorting for value proximity alignment Two-pointer technique for maintaining valid operation windows Cumulative operation cost calculation to ensure feasibility Feeling great to see consistent performance improvements and algorithmic clarity growing day by day! 🚀 #LeetCode #100DaysOfCode #Python #ProblemSolving #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚀 DSA Progress – Day 102 ✅ Problem #1657: Determine if Two Strings Are Close 🧠 Difficulty: Medium | Topics: String, Hash Table, Sorting, Frequency Counting 🔍 Approach: Implemented a frequency-based comparison approach to determine whether two strings can be transformed into each other using specific operations. Step 1 (Length Check): If the strings have different lengths → they can never be close. Step 2 (Frequency Counting): Created two frequency arrays of size 26 (for each lowercase English letter) and counted occurrences of each character in both strings. Step 3 (Character Set Validation): Checked that both strings use the same set of unique characters. If a character exists in one but not the other → return False. Step 4 (Frequency Pattern Check): Sorted both frequency arrays and compared them. If both have the same frequency distribution, they can be transformed into each other → return True. This ensures we only check for the pattern and presence of characters, not their positions. 🕒 Time Complexity: O(n + 26 log 26) ≈ O(n) 💾 Space Complexity: O(1) (fixed-size frequency arrays) 📁 File: https://lnkd.in/gyMwmsei 📚 Repo: https://lnkd.in/g8Cn-EwH 💡 Learned: This problem was a great exercise in identifying core equivalence patterns between strings. It taught me to look beyond direct character order and instead focus on frequency structures and sets — two powerful tools in string transformation logic. Breaking the problem into steps like length check → character set → frequency pattern made the solution clean, efficient, and interview-friendly. ✅ Day 102 complete — decoded the secret symmetry between two “close” strings! 🔤🔁✨ #LeetCode #DSA #Python #Strings #HashTable #Sorting #FrequencyAnalysis #DailyCoding #InterviewPrep #GitHubJourney
To view or add a comment, sign in
-
🧩 Day 54 of my LeetCode Challenge Problem: 3217. Delete Nodes From Linked List Present in Array Difficulty: Medium 🧠 💡 Intuition: We’re given a linked list and an array of integers. Our task is to delete all nodes from the linked list whose values are present in the given array. The trick here is to ensure we do it efficiently since both the array and list can be large. 🧠 Approach: Convert the array nums into a set for O(1) lookups. Use a dummy node to simplify edge cases like deleting the head. Traverse the list using two pointers (prev and cur). If a node’s value exists in the set, skip it. Otherwise, move forward. Finally, return the modified list starting from dummy.next. ⏱ Complexity: Time: O(n + m) Space: O(m) ✅ Example: Input: nums = [1,2,3], head = [1,2,3,4,5] Output: [4,5] Nodes with values 1, 2, and 3 are deleted, leaving the clean list [4,5]. 💬 Takeaway: Efficient lookups with a set and clean traversal logic make linked list problems much easier! #LeetCode #Day54 #LinkedList #Python #CodingChallenge
To view or add a comment, sign in
-
-
Today, I played around with integrating a minimal Knowledge Graph into a RAG pipeline using NetworkX. The idea is simple: represent knowledge as connected nodes (concepts, facts, or entities) and visualize their relationships. Then, when you query the system, it can retrieve not just direct data but contextually related information from neighboring nodes. Here’s a small Python snippet I used to: >Build a graph from a DataFrame using nx.from_pandas_edgelist() >Query a node to extract its subgraph >Visualize relationships dynamically with Matplotlib This is prototyping but still it’s cool how even a small graph can make retrieval feel more semantic.
To view or add a comment, sign in
-
-
🚀 Day 40 / 100 — #100DaysOfLeetCode 💡 (1625) Lexicographically Smallest String After Applying Operations (Medium) This was a really fun graph + BFS problem disguised as a string manipulation challenge. The trick is realizing that applying the two operations (add & rotate) repeatedly explores a finite set of states, forming an implicit graph, where each node is a string transformation. 🧩 Problem Overview You are given: A numeric string s Two integers a and b You can repeatedly: Add a (mod 10) to all digits at odd indices. Rotate the string right by b positions. Find the lexicographically smallest string possible after any number of operations. ⚙️ Approach — BFS on States Used Breadth-First Search (BFS) to explore all reachable strings: Start from the initial string s. Use a set vis to track visited states. For each string, generate: One by performing addition on odd indices. One by rotating by b. Continue until all unique transformations are explored. Track the smallest lexicographical string seen. 📈 Complexities Time Complexity: O(10 * n) Each state can appear up to 10 times due to modulo operations, and each state has n length. Space Complexity: O(10 * n) For storing visited transformations. ✅ Key Insights The problem is finite because both operations are modular and cyclic. BFS guarantees we explore all possible reachable strings in an optimal manner. Lexicographical comparison after BFS is straightforward — track the smallest string so far. ✨ Takeaway This problem beautifully demonstrates how: “Even string problems can secretly be graph traversal problems.” It’s a neat mix of modular arithmetic, rotation logic, and state-space search. #LeetCode #100DaysOfCode #BFS #GraphTraversal #StringManipulation #ProblemSolving #Python #Algorithms
To view or add a comment, sign in
-
-
**Headline/First Line (The Hook):** > Ever wondered what happens inside your Hard Drive when you hit 'Save'? 💾 **Body:** > I just finished building **PlanetDiskHardDrive** (a conceptual Python simulation!) and it's been an incredible journey diving into the core of how data storage works. > > This project models low-level computer science concepts in a unified environment, including: > > ⚙️ **Fragmentation & Defragmentation:** Visualizing why your files get scattered and how utilities put them back together for faster access. > 🛡️ **SMART Health Checks:** Simulating real-world hard drive diagnostics like temperature and reallocated sectors. > 🔄 **Version Control (Rollback):** Conceptualizing how Git-like commits and rollbacks interact with raw disk sectors. > 💥 **The System Collapse:** A simulated disaster scenario to understand the importance of the File Allocation Table (FAT). > > This was built to be a teaching tool, bringing complex ideas to life with simple Python code. > > **Check out the full code and detailed README here:** > https://lnkd.in/g4e3Aubg > > **I'd love to hear your thoughts!** What's the most challenging low-level OS concept you've tackled in a personal project? 👇 > > #ComputerScience #Python #OpenSource #OperatingSystems #DataStorage #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 3347. Maximum Frequency of an Element After Performing Operations II A fascinating difficult level problem that improved my understanding of range based window logic and frequency optimization. 💡 Problem Insight: Given an integer array nums, you can perform at most numOperations, where each element can be increased or decreased by up to k. The goal is to find the maximum possible frequency of any element after performing the allowed operations. 🧠 My Approach: - Sort the array to easily manage ranges. - Use a two-pointer (sliding window) technique to expand or shrink the valid range. - Calculate both target-based and non-target-based frequencies. - Return the optimized maximum frequency. 📊 Complexity Analysis: - Time Complexity: O(n log n) - Space Complexity: O(1) #LeetCode #Python #ProblemSolving #DSA #CodingChallenge #LearningEveryday #TechGrowth #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 9 of #100DaysOfLeetCode Problem: 21. Merge Two Sorted Lists Category: Linked List / Two Pointers Today’s challenge focused on merging two sorted linked lists into a single sorted list. This problem was a great refresher on pointer management, conditional linking, and efficient traversal through nodes. 🧠 Key Learnings: Used two pointers to compare nodes from both lists and attach the smaller node to the merged list. Managed the traversal smoothly without losing reference to the new head node. Reinforced the concept of dummy nodes for cleaner list initialization. Strengthened confidence in working with linked data structures and node connections. 🎯 Takeaway: Linked lists teach the importance of precise pointer handling — one wrong reference can change the entire structure! #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #LinkedList #Pointers #Python #AIEngineer #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