#day327 of #1001daysofcode problem statement (1582): Special Positions in a Binary Matrix -First counted the number of 1s in each row and column, then identified positions where both counts were exactly one. -Brute force tc=O(m*n*(m+n)), sc=O(1) -Reduced repeated checks and brought the solution down to O(m × n) but it costs some space. sc=O(m+n) #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
Counting Special Positions in Binary Matrix
More Relevant Posts
-
#day329 of #1001daysofcode problem statement (1784): Check if Binary String Has at Most One Segment of Ones Approach 1: If the pattern "01" appears in the string, it means the sequence of '1's was broken Approach 2: Traverse the string and count segments of consecutive '1's. Whenever a '1' is found, skip the entire sequence of continuous '1's and increase the segment count. If the number of segments of '1's is exactly one, the condition is satisfied. --both approaches have same time and space complexity. ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(1) #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
Day: 78/365 📌 LeetCode POTD: Equal Sum Grid Partition I Medium Key takeaways/Learnings from this problem: 1. This problem highlights how prefix sums make grid partitioning super efficient instead of recalculating sums again and again. 2. The key is trying splits smartly (row-wise or column-wise) and checking if both parts can balance out. 3. It’s a good reminder that many 2D problems become easier when you reduce them to 1D cumulative sums. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
Day 60 - Remove Duplicates from Sorted List Worked on removing duplicate elements from a sorted linked list. Approach: • Traverse the list once • Compare current node with next node • Skip duplicate nodes by adjusting pointers Time Complexity: O(n) Space Complexity: O(1) #Day60 #LeetCode #Java #LinkedList #CodingPractice #DSA #TechJourney
To view or add a comment, sign in
-
-
#day334 of #1001daysofcode problem statement (1009): Complement of Base 10 Integer 💡 Approach: To find the complement of a number, I converted it into binary and flipped every bit (0 → 1 and 1 → 0). After flipping the bits, the resulting binary string was converted back to decimal. Example: 5 → Binary: 101 Complement: 010 → 2 ⏱ Time Complexity: O(log n) 🧠 Space Complexity: O(log n) #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
#day328 of #1001daysofcode problem statement (1758): Minimum Changes To Make Alternating Binary String An alternating binary string can only follow two patterns: "010101..." or "101010...". I counted the number of changes required to convert the string into both patterns and returned the minimum of the two. ⏱Time Complexity: O(n) 🧠Space Complexity: O(1) Consistency check ✅ One LeetCode problem a day to sharpen problem-solving skills. #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
🚀 Day 21 of #100DaysOfDSA (Java) Today I explored ArrayList, an important part of the Java Collections Framework. Covered: 🔹 Difference between arrays and ArrayList 🔹 Dynamic resizing of ArrayList 🔹 Adding, removing, and updating elements 🔹 Accessing elements using index 🔹 Iterating through ArrayList 🔹 Basic operations and time complexity Key takeaway: Unlike arrays, ArrayList provides flexibility with dynamic size, making it very useful in real-world applications where data size is not fixed. Also understood how ArrayList internally works and why operations like add/remove have different time complexities. Day 21 ✅ From static arrays → to dynamic data structures. #DSA #Java #ArrayList #CollectionsFramework #100DaysOfCode #ProblemSolving #DeveloperJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfCode 🌱 Topic: Linked List / Recursion ✅ Problem Solved: LeetCode 24 – Swap Nodes in Pairs 🛠 Approach: Used a recursive approach to swap every two adjacent nodes in the linked list. If the list has 0 or 1 node, return it directly (base case). Store the second node (head.next) as a temporary node. Recursively swap the remaining list starting from temp.next. Adjust pointers so the second node becomes the new head of the pair. Connect the swapped pair with the recursively processed list. This swaps nodes without modifying their values, only changing pointers. #100DaysOfCode #Day38 #DSA #LinkedList #Recursion #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 15/100 – LeetCode Challenge Problem: Reverse Linked List Today’s problem focused on reversing a singly linked list using an iterative approach. Approach: Used three pointers to reverse the links: prev → keeps track of the previous node curr → current node being processed next → stores the next node before changing the link Steps: Store curr.next in next Reverse the link → curr.next = prev Move prev and curr one step forward Continue until the list ends. Finally, prev becomes the new head of the reversed list. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List pointer manipulation Iterative reversal technique In-place algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 42 / 100 | Remove Duplicates from Sorted List II -Intuition: -The linked list is sorted, so duplicate values appear next to each other. -The goal is to remove all nodes that contain duplicate numbers and keep only distinct values. -To handle cases where duplicates appear at the beginning of the list, use a temp node before the head. -When a duplicate sequence is detected, we skip all nodes with that value. -Approach: O(n) -Create a temp node pointing to the head of the linked list. -Use two pointers: prev (last confirmed unique node) and curr (current node). -Traverse the linked list while checking if the current node has duplicates. -If duplicates are found, skip all nodes with that value. -Update prev.next to the next non-duplicate node. -If no duplicate is found, move both pointers forward. -Repeat the process until the end of the list. -Complexity: Time Complexity: O(n) Space Complexity: O(1) #100DaysOfCode #Java #DSA #LeetCode #linkedlist
To view or add a comment, sign in
-
-
Day 59 - Merge Two Sorted Lists Worked on merging two sorted linked lists into one sorted list. Approach: • Used a dummy node to simplify pointer handling • Compared nodes from both lists and attached the smaller one • Appended remaining elements after traversal A classic linked list problem that strengthens pointer manipulation skills. Time Complexity: O(n + m) Space Complexity: O(1) #Day59 #LeetCode #Java #LinkedList #CodingPractice #DSA #TechJourney
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