✅ Day 84 of 100 Days LeetCode Challenge Problem: 🔹 #2946 – Matrix Similarity After Cyclic Shifts 🔗 https://lnkd.in/g3uy6WKa Learning Journey: 🔹 Today’s problem was about checking if a matrix remains the same after applying cyclic shifts k times. 🔹 Instead of handling even and odd rows separately, I simplified the logic by focusing on the final shifted state. 🔹 I used modulo (k % n) to reduce unnecessary full rotations. 🔹 For each row, I generated its left cyclic shift using slicing: • row[k % n:] + row[:k % n] 🔹 Then, I directly compared the shifted row with the original row. 🔹 If any row doesn’t match, return False; otherwise, True. Concepts Used: 🔹 Modular Arithmetic 🔹 Array Slicing 🔹 Matrix Traversal Key Insight: 🔹 Full rotations don’t change the array, so reducing k using modulo is critical. 🔹 Direct row comparison after a single computed shift avoids repeated simulation and keeps the solution concise. Complexity: 🔹 Time: O(n × m) 🔹 Space: O(m) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
100 Days LeetCode Challenge: Matrix Similarity After Cyclic Shifts
More Relevant Posts
-
✅ Day 88 of 100 Days LeetCode Challenge Problem: 🔹 #1252 – Cells with Odd Values in a Matrix 🔗 https://lnkd.in/g5eE9A-e Learning Journey: 🔹 Today’s problem focused on simulating row and column increment operations on a matrix. 🔹 I initialized an m × n matrix with all zeros. 🔹 For each index [ri, ci], I incremented: • All elements in row ri • All elements in column ci 🔹 After applying all operations, I traversed the matrix to count how many cells contain odd values. Concepts Used: 🔹 Matrix Simulation 🔹 Nested Loops 🔹 Conditional Counting 🔹 Basic Array Manipulation Key Insight: 🔹 Direct simulation works efficiently due to small constraints. 🔹 Each operation affects an entire row and column, so tracking increments carefully is key. Complexity: 🔹 Time: O(m × n + k × (m + n)) 🔹 Space: O(m × n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
🚀 Stop iterating through rows like it’s 2010. In a recent pipeline, we were processing 5 million records to calculate a rolling score. Using a standard loop took forever and pegged the CPU at 100%. Before optimisation: for i in range(len(df)): df.at[i, 'score'] = df.at[i, 'val'] * 1.05 if df.at[i, 'flag'] else df.at[i, 'val'] After optimisation: import numpy as np df['score'] = np.where(df['flag'], df['val'] * 1.05, df['val']) Performance gain: 85x faster execution. Vectorisation isn’t just a "nice to have"—it’s the difference between a pipeline that crashes at 2 AM and one that finishes in seconds. By letting NumPy handle the heavy lifting in C, we eliminated the Python overhead entirely. If you're still using `.iterrows()` or manual loops for column transformations, it’s time to refactor. The performance delta on large datasets is simply too massive to ignore. What is the biggest "bottleneck" function you’ve refactored recently that gave you a massive speedup? #DataEngineering #Python #PerformanceTuning #Vectorization #DataScience
To view or add a comment, sign in
-
✅ Day 97 of 100 Days LeetCode Challenge Problem: 🔹 #1281 – Subtract the Product and Sum of Digits of an Integer 🔗 https://lnkd.in/gxTAZc6U Learning Journey: 🔹 Today’s problem involved extracting digits of a number and performing two operations simultaneously. 🔹 I initialized two variables: one for product (pr) and one for sum (sm). 🔹 Using a while loop, I extracted each digit using n % 10. 🔹 Updated the product by multiplying the digit and updated the sum by adding it. 🔹 Reduced the number using integer division (n //= 10) after each step. 🔹 Finally returned the difference between product and sum. Concepts Used: 🔹 Digit Extraction 🔹 While Loop 🔹 Arithmetic Operations 🔹 Number Manipulation Key Insight: 🔹 Both product and sum can be computed in a single traversal of digits. 🔹 Efficient use of modulus and division avoids converting the number to a string. Complexity: 🔹 Time: O(d) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
Day 30/100 — Solved “Maximum Depth of N-ary Tree” . today, A simple problem on the surface, but a great exercise to reinforce recursive thinking and traversal strategies. Approach 1: Depth-First Search (DFS) Used recursion to explore each branch of the tree as deep as possible. For every node, I computed the depth of all its children and took the maximum among them. The final answer for each node becomes 1 + max depth of its children. Base cases handled: If the node is null → depth = 0 If the node has no children → depth = 1 This approach is intuitive and closely follows the definition of depth itself. Approach 2: Breadth-First Search (BFS) Traversed the tree level by level using a queue. Each iteration processes one full level of nodes, and the depth counter increments after finishing each level. This approach is useful when thinking in terms of layers rather than paths. Complexity: Both approaches run in O(n) time since every node is visited once. Space complexity differs based on recursion depth (DFS) vs queue size (BFS). Key takeaway: Understanding both DFS and BFS gives flexibility in tackling tree problems from different perspectives—path-based vs level-based thinking. #Day30 #100DaysOfCode #DSA #LeetCode #Python #CodingJourney #Algorithms #DataStructures #ProblemSolving
To view or add a comment, sign in
-
-
✅ Day 99 of 100 Days LeetCode Challenge Problem: 🔹 #999 – Available Captures for Rook 🔗 https://lnkd.in/gAw_XpbJ Learning Journey: 🔹 Today’s problem focused on simulating rook movement on a chessboard. 🔹 First, I located the position of the rook 'R' on the board. 🔹 Then, I explored all four directions: up, down, left, and right. 🔹 In each direction, I moved step-by-step until: • I hit a bishop 'B' → stop (blocked) • I found a pawn 'p' → increment count and stop • Or reached the board boundary 🔹 Summed all valid captures and returned the result. Concepts Used: 🔹 Matrix Traversal 🔹 Simulation 🔹 Direction Vectors 🔹 Boundary Checking Key Insight: 🔹 The rook’s movement is linear in 4 directions, and each direction is independent. 🔹 Early stopping (on bishop or pawn) is critical for correctness and efficiency. Complexity: 🔹 Time: O(1) (fixed 8×8 board, constant work) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #100DaysOfCode #Python #CodingJourney #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
The Magic of the Mirror: Image Flipping with NumPy! 🤳🔄 Day 85/100 Ever wondered how your phone 'mirrors' your selfies instantly? It’s just one line of array slicing! For Day 85 of my #100DaysOfCode, I explored Image Flipping and Mirroring. In the world of Computer Vision, an image is just a matrix, and to flip it, we simply reverse the order in which we read the rows or columns. Technical Highlights: 🔄 Axis Reversal: Mastering the [::-1] slicing syntax to reverse array indices without complex loops. 🤳 Mirror Logic: Implementing horizontal flips to simulate the front-camera 'selfie' experience. 🌊 Vertical Reflection: Creating water surface reflection effects by reversing the row order of 2D matrices. 🤖 AI Data Augmentation: Learning how flipping images is used in Machine Learning to double the size of training datasets and prevent model bias. Do check my GitHub repository here : https://lnkd.in/d9Yi9ZsC #100DaysOfCode #ComputerVision #NumPy #Python #BTech #IILM #AIML #ImageProcessing #DataAugmentation #SoftwareEngineering #LearningInPublic #WomenInTech
To view or add a comment, sign in
-
-
✅ Day 89 of 100 Days LeetCode Challenge Problem: 🔹 #1480 – Running Sum of 1D Array 🔗 https://lnkd.in/gSTZrxF7 Learning Journey: 🔹 Today’s problem focused on computing the running (prefix) sum of an array. 🔹 Instead of using an extra array, I optimized the solution by modifying the input array in-place. 🔹 Starting from index 1, I updated each element as: • nums[i] += nums[i-1] 🔹 This way, each index stores the cumulative sum up to that point. 🔹 Finally, returned the modified array. Concepts Used: 🔹 Prefix Sum 🔹 In-place Computation 🔹 Array Traversal Key Insight: 🔹 The previous element already stores the prefix sum, so we can reuse it directly. 🔹 Eliminates the need for extra space while maintaining linear time. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 95 of 100 Days LeetCode Challenge Problem: 🔹 #869 – Reordered Power of 2 🔗 https://lnkd.in/gkNXaSFM Learning Journey: 🔹 Today’s problem focused on checking whether the digits of a number can be rearranged to form a power of 2. 🔹 I created a helper function to extract and store the digits of a number. 🔹 Then I sorted the digits of the input number for comparison. 🔹 Next, I generated powers of 2 iteratively and compared their sorted digit lists with the input. 🔹 If any match was found, I returned True. Otherwise, continued until the digit length exceeded the input. Concepts Used: 🔹 Digit Extraction 🔹 Sorting 🔹 Simulation of Powers of 2 🔹 Brute Force Optimization Key Insight: 🔹 Instead of generating permutations (which is expensive), sorting digits allows quick comparison. 🔹 Any valid rearrangement must have the same digit frequency as some power of 2. Complexity: 🔹 Time: O(log n * d log d) 🔹 Space: O(d) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 87 of 100 Days LeetCode Challenge Problem: 🔹 #2840 – Check if Strings Can be Made Equal With Operations II 🔗 https://lnkd.in/gY73RBb5 Learning Journey: 🔹 Today’s problem extended the previous one, allowing swaps between indices where the difference is even. 🔹 I observed that this again partitions the string into two independent groups: • Even indices (0, 2, 4, …) • Odd indices (1, 3, 5, …) 🔹 I extracted characters from even and odd positions separately for both strings. 🔹 Then, I sorted these groups and compared them between s1 and s2. 🔹 If both even-index groups and odd-index groups match, the strings can be made equal. Concepts Used: 🔹 String Manipulation 🔹 Index Grouping (Parity-based) 🔹 Sorting 🔹 Greedy Observation Key Insight: 🔹 Since swaps are allowed only between indices with even distance, characters can only move within their parity group. 🔹 Therefore, the problem reduces to checking if both parity groups have identical character distributions. Complexity: 🔹 Time: O(n log n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
Day 45 of #GeekStreak60: Architecting the Minimum Spanning Tree! 🏙️🕸️ Tackled the "Minimum cost to connect all houses in a city" problem on @GeeksforGeeks today. Key Learning: When finding a Minimum Spanning Tree (MST), the shape of your data dictates your algorithm. Because every house can connect to any other house, this forms a "Dense Graph." Using Kruskal's Algorithm here is a trap—generating and sorting every possible edge creates massive memory overhead. Instead, I implemented an optimized version of Prim’s Algorithm. By growing the network one node at a time and calculating the Manhattan distances on the fly, I bypassed the need to store an edge list. This dropped the auxiliary space complexity from the expected O(n^2) down to a highly efficient O(n)! Understanding the trade-offs between memory overhead and dynamic computation is exactly what makes system design so fascinating. 🚀 3/4 of the way to the finish line! #geekstreak60 #npci #coding #Algorithms #Python #DataStructures #GraphTheory #SystemDesign #Optimization
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