Day 1/100 – LeetCode Challenge 🚀 Problem: #867 Transpose Matrix Difficulty: Easy Language: Java Approach: Nested Loop with Index Swapping Time Complexity: O(m × n) Space Complexity: O(m × n) 🔍 Key Insight: The transpose of a matrix swaps rows and columns. If original matrix is m × n, the result will be n × m. Careful index handling is important to avoid dimension errors. 🧠 Solution Brief: Created a new matrix with reversed dimensions. Traversed the original matrix using nested loops. Assigned result[j][i] = matrix[i][j] to swap row and column indices. Returned the transposed matrix. this solution is basicaly bruteforce approach 📌 What I Learned: Even simple matrix problems improve understanding of 2D array traversal and index manipulation. Consistency starts today — 99 more days to go 💪 #LeetCode #Day1 #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney #LearningInPublic
Transpose Matrix Java LeetCode Challenge
More Relevant Posts
-
Day 6/100 – LeetCode Challenge 🚀 Problem: #189 Rotate Array Difficulty: Medium Language: Java Approach: Array Reversal Technique Time Complexity: O(n) Space Complexity: O(1) 🔍 Key Insight: Instead of shifting elements one by one, the array can be rotated efficiently using a three-step reversal strategy. Steps: 1️⃣ Reverse the entire array 2️⃣ Reverse the first k elements 3️⃣ Reverse the remaining elements This achieves the required rotation in-place with constant extra space. 🧠 Solution Brief: Calculated k % n to handle cases where k is greater than array length. Reversed the entire array first. Then reversed the first k elements and the remaining n-k elements. This sequence correctly rotates the array to the right. 📌 What I Learned: Understanding patterns like array reversal can simplify problems that initially seem complex. Optimizing from brute force shifting to an in-place O(n) solution improves efficiency. #LeetCode #Day6 #100DaysOfCode #Java #DSA #Arrays #RotateArray #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 76 of #100DaysOfCode Today I solved a string manipulation problem: Clear Digits 🧠 Problem: Given a string, whenever a digit appears, remove the previous character. Digits act like a backspace operation. 💡 Key Insight: Instead of modifying the string directly (since Strings are immutable in Java), I used a StringBuilder, which works like a stack: If character → append (push) If digit → delete last character (pop) 📌 What I Learned: StringBuilder is powerful for string modifications Always handle edge cases (like digit at the start) Many string problems are actually stack problems in disguise ⏱ Complexity: Time: O(n) Space: O(n) #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 96 of #100DaysOfCode Solved LeetCode #1461 – Check If a String Contains All Binary Codes of Size K ✅ A solid mix of sliding window + bit manipulation, where efficiency really matters. Key Takeaways: -> Using rolling hash / bitmask to track binary substrings -> Avoiding substring overhead for better performance -> Understanding the limit: total required codes = 2^k -> Early pruning with length checks for optimization Language: Java -> Runtime: 6 ms (Beats 100%) ⚡ -> Memory: 47.73 MB Almost at the finish line — one binary string at a time 💻🔥 #LeetCode #Java #BitManipulation #SlidingWindow #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfLeetCode Today I solved "Container With Most Water" problem on LeetCode. 🔹 Difficulty: Medium 🔹 Concept Used: Two Pointer Technique 🔹 Language: Java 📌 Problem Summary: Given an array representing heights of vertical lines, the goal is to find two lines that together with the x-axis can contain the maximum amount of water. 💡 Approach: Instead of checking all possible pairs (O(n²)), I used the Two Pointer approach which reduces the time complexity to O(n). Steps: 1️⃣ Start with two pointers at the beginning and end of the array. 2️⃣ Calculate the area using the smaller height. 3️⃣ Move the pointer with the smaller height inward. 4️⃣ Track the maximum area during each step. 📊 Result: ✅ Runtime: 5 ms (Beats 81.86%) ✅ Memory: Beats 95.54% This problem was a great exercise to understand optimization using two pointers instead of brute force. Consistency is the key — moving forward one problem at a time! 💪 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 34 of #100DaysOfLeetCode 💻✅ Solved #110. Balanced Binary Tree on LeetCode using Java. Approach: • Used a bottom-up recursive approach to calculate height • Returned -1 immediately if any subtree is unbalanced • Compared left and right subtree heights at each node • Checked if the height difference is greater than 1 • Stopped early to optimize unnecessary computations Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.33 MB (Beats 95.41% submissions) Key Learning: ✓ Understood how to combine height calculation with balance checking ✓ Learned early termination technique in recursion ✓ Improved problem-solving for tree-based recursive problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 14/100 – LeetCode Challenge 🚀 Problem: #169 Majority Element Difficulty: Easy Language: Java Approach: Sorting + Middle Element Time Complexity: O(n log n) Space Complexity: O(1) 🔍 Key Insight: The majority element appears **more than ⌊n / 2⌋ times** in the array. If we **sort the array**, the majority element must occupy the **middle position** because it appears more than half of the time. Therefore, the element at index **n/2** will always be the majority element. 🧠 Solution Brief: First sorted the array using `Arrays.sort()`. Since the majority element appears more than half of the array length, it will always be positioned at the middle index. Finally returned `nums[nums.length / 2]` as the majority element. 📌 What I Learned: Understanding problem constraints can simplify the solution significantly. Sometimes a simple observation (like majority occupying the middle after sorting) can avoid more complex implementations. #LeetCode #Day14 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode Day 18 – Complement of Base 10 Integer Today I solved LeetCode Problem 1009: Complement of Base 10 Integer using Java. 🧠 Problem: Given a non-negative integer n, return the complement of its binary representation. The complement means flipping all bits in the binary form of the number. 📌 Example: Input: n = 5 Binary of 5 → 101 Complement → 010 Output → 2 💡 Approach: • Create a bitmask with all bits set to 1 up to the highest bit of n. • Use the XOR (^) operator with the mask to flip the bits. 💻 Java Code: class Solution { public int bitwiseComplement(int n) { if (n == 0) return 1; int mask = 0, temp = n; while (temp > 0) { mask = (mask << 1) | 1; temp >>= 1; } return n ^ mask; } } ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) 📚 Practicing Data Structures & Algorithms daily to improve problem-solving skills. #LeetCode #Java #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 14/30 – LeetCode streak Today’s problem: Concatenation of Consecutive Binary Numbers You need the decimal value of '1' + '2' + '3' + ... + 'n' written in binary back-to-back, all under mod (10^9 + 7). Core trick: treat “concatenate in binary” as shift + OR: * When you append 'i' to the right, you’re really shifting the current result left by 'bits(i)' and OR-ing 'i' into the free space. * The number of bits only increases when 'i' hits a power of two (1, 2, 4, 8, …), so you just track 'bits' and bump it whenever '(i & (i - 1)) == 0'. Day 14 takeaway: Once you see that “stick this binary to the right” is the same as “shift by its bit length and OR”, the whole problem becomes a clean for-loop plus the power-of-two trick—no string building or big integer juggling needed. #leetcode #dsa #java #bitmanipulation #consistency
To view or add a comment, sign in
-
-
🚀 Day 97 of My 100 Days LeetCode Challenge | Java Today’s problem was a solid exercise in matrix processing and prefix sum optimization. The goal was to count the number of submatrices whose sum is less than or equal to a given value (k). A brute-force approach would be too slow, so the key was to use 2D prefix sums to efficiently compute submatrix sums. By converting the matrix into a prefix sum matrix, we can calculate the sum of any submatrix in constant time, making the overall solution much more efficient. ✅ Problem Solved: Count Submatrices With Sum ≤ K ✔️ All test cases passed (859/859) ⏱️ Runtime: 7 ms 🧠 Approach: 2D Prefix Sum 🧩 Key Learnings: ● Prefix sums are powerful for optimizing repeated range sum queries. ● 2D prefix sums extend the same idea from arrays to matrices. ● Preprocessing can drastically reduce computation time. ● Avoiding brute force is key in large input problems. ● Matrix problems often become easier with the right transformation. This problem reinforced how preprocessing techniques like prefix sums can turn complex problems into efficient solutions. 🔥 Day 97 complete — sharpening matrix optimization and prefix sum skills. #LeetCode #100DaysOfCode #Java #PrefixSum #Matrix #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 36 of #100DaysOfLeetCode 💻✅ Solved #111. Minimum Depth of Binary Tree on LeetCode using Java. Approach: • Used recursive approach to calculate minimum depth • Returned 0 when root is null (base case) • If one subtree is null, avoided taking minimum of 0 (handled edge case carefully) • Returned 1 + minimum depth of valid subtree • Ensured correct handling of skewed trees Performance: ✓ Runtime: 6 ms ✓ Memory: 82.20 MB Key Learning: ✓ Understood difference between minimum depth and maximum depth logic ✓ Learned importance of handling null subtree cases correctly ✓ Improved confidence in solving binary tree recursion problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
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
Good 👍