𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐃𝐚𝐢𝐥𝐲 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 – 𝐃𝐞𝐜𝐨𝐝𝐞 𝐭𝐡𝐞 𝐒𝐥𝐚𝐧𝐭𝐞𝐝 𝐂𝐢𝐩𝐡𝐞𝐫𝐭𝐞𝐱𝐭 (𝐌𝐞𝐝𝐢𝐮𝐦) Today’s problem was a 𝐟𝐮𝐧 𝐦𝐚𝐭𝐫𝐢𝐱 𝐭𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥 + 𝐬𝐢𝐦𝐮𝐥𝐚𝐭𝐢𝐨𝐧 𝐜𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐋𝐢𝐧𝐤 : https://lnkd.in/gsSCrJbr 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 : https://lnkd.in/gMhqhD6M The idea behind the encoding process: The original text is written 𝐝𝐢𝐚𝐠𝐨𝐧𝐚𝐥𝐥𝐲 𝐢𝐧 𝐚 𝐦𝐚𝐭𝐫𝐢𝐱 with a fixed number of rows. The matrix is then read row by row to produce the encoded string. To decode it, we reverse the process: 🔹 𝐊𝐞𝐲 𝐎𝐛𝐬𝐞𝐫𝐯𝐚𝐭𝐢𝐨𝐧𝐬 If n = encodedText.length() and we know rows, then cols = n / rows Characters of the original text lie on diagonals starting from each column in the first row. Traverse diagonally (row++, col++) from each starting column. 🔹 𝐒𝐭𝐞𝐩𝐬 Compute the number of columns. For every column c, traverse diagonally down-right. Map the matrix index using r * cols + c. Build the result string. Remove trailing spaces at the end. 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 Time: O(n) Space: O(n) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Whenever you see a matrix encoding problem, think about how the data was written and reverse the traversal pattern. #LeetCode #CodingInterview #DataStructures #Algorithms #Java #ProblemSolving #DailyCodingChallenge
Decode Slanted Ciphertext (Medium) Challenge
More Relevant Posts
-
I added more threads to fix my pipeline. Throughput dropped. That was the moment I realized I had been debugging the wrong thing for days. We were processing ~8 million events in a strict time window. The system was falling behind. My first instinct more threads, more parallelism. Classic move. But the system wasn't compute-bound. Every event was triggering datastore lookups, config reads, network calls. The threads weren't competing for CPU. They were all just waiting and I gave them more company. Python 3.13 introduced a free-threaded build where the GIL can be disabled. True parallel execution across cores. No more serialization. A lot of engineers read that and thought: "Finally, Python is fixed." It's not that simple. Your system's throughput is capped by three things and free-threading only addresses one: → I/O ceiling - how fast your external dependencies respond → Thread overhead ceiling - context switching cost beyond the optimal thread count → Execution ceiling - where the GIL used to apply Removing the GIL lifts the execution ceiling. If your system is sitting behind the I/O ceiling, nothing moves. What actually fixed my pipeline wasn't threads or Python versions. It was pulling config data out of the critical path and caching state locally. One design decision. More impact than any concurrency change. Removing the GIL doesn't remove bad architecture. Full breakdown with the three-ceiling model and where free-threading genuinely helps link in comments. #Python #SystemDesign #BackendEngineering #SoftwareEngineering #DistributedSystems #Concurrency
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟲𝟴/𝟳𝟱 | 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝟳𝟱 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: 136. Single Number 𝗗𝗶𝗳𝗳𝗶𝗰𝘂𝗹𝘁𝘆: Easy 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘂𝗺𝗺𝗮𝗿𝘆: Given a non-empty array where every element appears twice except for one, find the element that appears only once. Constraints: • Linear time complexity required • Constant extra space 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: This problem is efficiently solved using Bit Manipulation (XOR operation). • Key Properties of XOR: – a ^ a = 0 – a ^ 0 = a – XOR is commutative and associative • Logic: – XOR all elements in the array – Duplicate numbers cancel each other out – The remaining value is the unique element • Implementation: – Initialize a variable (e.g., result = 0) – Traverse the array and XOR each element with result – Final result holds the single number This works because pairs eliminate themselves, leaving only the non-repeating number. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 𝗔𝗻𝗮𝗹𝘆𝘀𝗶𝘀: • Time Complexity: O(n) • Space Complexity: O(1) 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Bit manipulation can simplify problems that seem to require extra space. XOR is especially powerful when dealing with pairs or duplicates. 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗟𝗶𝗻𝗸: https://lnkd.in/guP-fJnC #Day68of75 #LeetCode75 #DSA #Java #Python #BitManipulation #Algorithms #MachineLearning #DataScience #ML #DataAnalyst #LearningInPublic #TechJourney #LeetCode
To view or add a comment, sign in
-
-
Shipped a small end-to-end backend pipeline this month: • Ingested noisy vendor-style location events (dedupe + retries + basic health stats) • Normalized positions with a simple quality policy (accuracy / jitter / floor sanity) • Derived events: zone enter/exit + asset proximity • Sketched the relational model + example SQL for “where was X between T0–T1?” Nice reminder that most of the work isn’t algorithms—it’s clear boundaries, idempotency, and making the data trustworthy before you build features on top. #backend #python #systemdesign #dataengineering
To view or add a comment, sign in
-
🔥 Day 140/360 – This Trick Generates All Subsets Instantly 🚀 Most people solve this using recursion… But today I learned how to generate all subsets using Bit Manipulation👇 📌 Topic: Bit Manipulation + Array 🧩 Problem: Subsets (Power Set) 📝 Problem Statement: Given an integer array, return all possible subsets (the power set). 🔍 Example: Input: [1, 2, 3] Output: [[], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3]] 💡 Approach: Bit Masking (Optimized) ✔ Step 1 – Calculate total subsets = 2ⁿ using (1 << n) ✔ Step 2 – Loop from 0 to 2ⁿ - 1 (each number represents a subset) ✔ Step 3 – Use bits to decide whether to include an element ⚡ Key Idea: Each number (mask) represents a subset in binary form. If a bit is ON → include that element. ⏱ Complexity: Time → O(n × 2ⁿ) Space → O(n × 2ⁿ) 📚 What I Learned: Bit manipulation can replace recursion in subset generation and makes the logic easier to visualize in binary. 🚀 Why This Matters: This concept is widely used in backtracking, DP, and interview problems. #DSA #Java #Coding #ProblemSolving #InterviewPrep #LeetCode #BitManipulation #TechJourney #140DaysOfCode
To view or add a comment, sign in
-
-
The High Cost of the Wrong Initial Choice I have seen complex computation logic for over a million records take hours to run simply because of inefficient, row-by-row processing that is offered by database stored procedures and traditional java/python code. It is slow, impossible to scale, and eventually kills your product's edge in the market. By moving to vectorized logic with tools like NumPy or Polars, you can turn those hours of computation into milliseconds. This is not just about using newer tools, it is about leveraging modern execution like #SIMD (Single Instruction Multiple Data) and #multithreading to gain a massive competitive advantage. If your backend is computation heavy and you're still stuck in legacy loops, you are leaving performance, market edge and money on the table. References: https://lnkd.in/g8j3A5Bn https://lnkd.in/gaPnFUQm https://lnkd.in/gWt9WHnp #DataEngineering #SystemDesign #NumPy #PerformanceOptimization #Scalability #PythonProgramming #TechStrategy #Vectorization #TechToolChoice
To view or add a comment, sign in
-
Handling Time Data: Logic over Strings. Today I worked on a common challenge: comparing time values like '7:15' and '10:30' stored in a list.The Problem: Standard string comparison can be unreliable (e.g., '7:15' vs '10:30'), and using float numbers leads to mathematical inaccuracies.The Solution: I converted all time entries into a single unit — Total Minutes from the start of the day (hours * 60 + minutes).This transformation turns time-strings into simple integers, creating a robust and scalable logic for sorting and filtering. A solid foundation is everything, whether it's infrastructure or code. 🛡️🦾#Python #Coding #ProblemSolving #SoftwareEngineering #Backend #Summerson
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟲𝟳/𝟳𝟱 | 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝟳𝟱 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: 338. Counting Bits 𝗗𝗶𝗳𝗳𝗶𝗰𝘂𝗹𝘁𝘆: Easy 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝘂𝗺𝗺𝗮𝗿𝘆: Given an integer n, return an array where each index i (0 ≤ i ≤ n) contains the number of 1’s in the binary representation of i. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: This problem is solved efficiently using Dynamic Programming with bit manipulation. Instead of converting each number to binary separately, we reuse previously computed results. • Key Observation: – Right shifting a number (i >> 1) removes the last bit – (i & 1) tells whether the last bit is 1 or 0 • Transition: – ans[i] = ans[i >> 1] + (i & 1) This means: Take the count of 1’s from i/2 and add 1 if the current number is odd. • Base Case: – ans[0] = 0 • Final answer: – Array ans of size n + 1 This avoids repeated binary conversions and builds the solution in a bottom-up manner. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 𝗔𝗻𝗮𝗹𝘆𝘀𝗶𝘀: • Time Complexity: O(n) • Space Complexity: O(n) 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Problems involving binary representations often have patterns that can be reused. Bit manipulation + DP is a powerful combination for optimizing such computations. 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗟𝗶𝗻𝗸: https://lnkd.in/gydkB_rv #Day67of75 #LeetCode75 #DSA #Java #Python #DynamicProgramming #BitManipulation #MachineLearning #DataScience #ML #DataAnalyst #LearningInPublic #TechJourney #LeetCode
To view or add a comment, sign in
-
-
🚀 Solved: Trapping Rain Water Problem (Optimized Approach) Today, I tackled another classic problem from LeetCode — Trapping Rain Water. 🔍 Problem Statement Given an array representing elevation heights, compute how much water can be trapped after raining. 💡 Approach Used: Prefix Max Arrays Instead of checking water at each position repeatedly (which can be inefficient), I used a precomputation strategy: -> Compute the tallest bar on the left for every index -> Compute the tallest bar on the right for every index -> Water trapped at index i = min(leftMax, rightMax) - height[i] ⚡ Time Complexity: O(N) 📦 Space Complexity: O(N) 💻 Java Implementation: class Solution { public int trap(int[] height) { if (height == null || height.length == 0) { return 0; } int n = height.length; int[] maxL = new int[n]; int[] maxR = new int[n]; maxL[0] = height[0]; for (int i = 1; i < n; i++) { maxL[i] = Math.max(maxL[i - 1], height[i]); } maxR[n - 1] = height[n - 1]; for (int j = n - 2; j >= 0; j--) { maxR[j] = Math.max(maxR[j + 1], height[j]); } int water = 0; for (int i = 0; i < n; i++) { water += (Math.min(maxL[i], maxR[i]) - height[i]); } return water; } } 🎯 Key Insight: Water trapped at any index depends on the minimum of the tallest bars on both sides, not just local heights. #Java #DataStructures #Algorithms #LeetCode #CodingInterview #SoftwareEngineering #ProblemSolving
To view or add a comment, sign in
-
I just killed 1,904 MB of RAM bloat with 40 lines of C. 🚀 I was testing Python's standard json.loads() on a 500MB log file today. 🛑 The Result: 3.20 seconds of lag and a massive 1.9GB RAM spike. For a high-scale data pipeline, that’s not just "slow"—that’s a massive AWS bill and a system crash waiting to happen. So, I built a bridge. By offloading the heavy lifting to the metal using Memory Mapping (mmap) and C pointer arithmetic, I created the Axiom-JSON engine. ✅ Standard Python: 3.20s | 1,904 MB RAM ✅ Axiom-JSON (C-Bridge): 0.28s | ~0 MB RAM That is an $11\times$ speedup and near-perfect memory efficiency. Stop throwing more RAM at your problems. Start writing better architecture. CTA: If your data pipelines are hitting a performance wall, DM me. I’m looking to help 2 teams optimize their compute costs this week. #SystemsArchitecture #Python #CProgramming #PerformanceEngineering #DataEngineering #CloudOptimization
To view or add a comment, sign in
-
-
Day 105: Circular Arrays & Shortest Paths 🔄 Problem 2515: Shortest Distance to Target String in a Circular Array Today’s challenge involved finding the minimum steps to reach a target string in a circular array, allowing movement in both directions. The Strategy: • Bidirectional Search: Since the array is circular, the distance can be calculated in two ways: moving forward or moving backward. • Modular Arithmetic: I used (dist + n) % n to handle the wrap-around logic seamlessly, ensuring the index stays within bounds regardless of the direction. • Optimization: By iterating once through the array and comparing the distances for every occurrence of the target, I maintained an O(N) time complexity. Sometimes the most elegant way to handle a "circular" problem is simply embracing the symmetry of the path. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
Explore related topics
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
👍🏻👍🏻