Day 86 | LeetCode #1790 – Check if One String Swap Can Make Strings Equal 🔹 Problem: Given two strings s1 and s2 of equal length, determine if you can make them equal by swapping exactly one pair of characters in s1. 🔹 Approach: • Traverse both strings and track the indices where characters differ. • If there are exactly two differences, check if swapping those characters in s1 makes the strings equal. • If the strings are already equal, return true. If differences are more than two or only one, return false. 🔹 Complexity Analysis: • Time: O(n) — single pass through the strings • Space: O(1) — only two integer variables used to store indices 🔹 Key Learning: Handling differences systematically and validating the swap condition ensures correctness efficiently. #LeetCode #CodingChallenge #Java #ProblemSolving #InterviewPrep #Algorithms #DataStructures #Day86 #100DaysOfCode #SoftwareEngineering
LeetCode 1790: Swap One Pair to Equal Strings
More Relevant Posts
-
🚀 DSA Series – Day 29 📌 Problem: Find the Duplicate Number (LeetCode) Today I worked on a classic array problem where the goal is to find the single duplicate number in an array containing n+1 integers from 1 to n. 🧠 What I learned Instead of sorting or nested loops, we can use a frequency array to track how many times each number appears. If a number appears more than once, that is our duplicate. 💡 My Approach -Create an extra array to store counts -Traverse the input array and increase the count -Scan the count array to find the value with frequency > 1 ⏱ Complexity Time: O(n) Space: O(n) #DSA #LeetCode #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day 13/100 – LeetCode Challenge ✅ Problem: #368 Largest Divisible Subset Difficulty: Medium Language: Java Approach: Dynamic Programming with Path Reconstruction Time Complexity: O(n²) Space Complexity: O(n) Key Insight: After sorting, a divisible subset maintains divisibility chain: If nums[i] % nums[j] == 0, extend subset from j to i. Track both DP count and previous index for reconstruction. Solution Brief: Sorted array and initialized dp[i]=1, prev[i]=-1. Nested loops to build longest divisible chain, storing parent indices. Reconstructed subset by backtracking from maxi using prev array. Finding structured subsets with divisibility chains #LeetCode #Day13 #100DaysOfCode #DynamicProgramming #Java #Algorithm #CodingChallenge #ProblemSolving #LargestDivisibleSubset #MediumProblem #PathReconstruction #Subset #DSA #Array
To view or add a comment, sign in
-
-
Day 7 / 60 – DSA Journey 🚀 | Set Matrix Zeroes (LeetCode 73) Today was all about thinking beyond brute force. Solved Set Matrix Zeroes using an in-place O(1) space solution, where the first row and first column act as markers instead of using extra memory. Approach snapshot: Detect if the first row or first column contains zero Use them to mark rows and columns that need to be zeroed Update the matrix based on those markers This problem clearly shows how small observations lead to optimal solutions. Understanding the pattern matters more than memorizing the code. Consistency over perfection — one problem at a time. #DSA #DSAJourney #Day7 #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 147 | Frequency Counting Across Multiple Strings Today’s problem was a clean exercise in comparing character frequencies across multiple inputs. 🧩 Problem Solved: 1002. Find Common Characters 🔍 Approach: • Initialized a frequency array using the first word. • For each subsequent word, counted character frequencies and kept the minimum count for each character. • Constructed the result by adding each character as many times as its final minimum frequency. ✨ Key Insight: Using minimum frequency across all strings ensures only truly common characters are included. 📚 Topics: Hashing · Strings · Frequency Counting 💻 Platform: LeetCode #LeetCode #DSA #ProblemSolving #DailyCoding #Strings #Hashing #Java #Consistency
To view or add a comment, sign in
-
-
🚀 Day 41 of #100DaysOfCode Solved LeetCode Problem #840 – Magic Squares in Grid ✨🔢 This problem focused on identifying all 3×3 subgrids that form a valid magic square, where every row, column, and diagonal sums to the same value and all numbers from 1 to 9 appear exactly once. Key Learnings: -> Iterated through all possible 3×3 subgrids efficiently -> Validated uniqueness of numbers using a boolean check array -> Verified row, column, and diagonal sums against a target sum -> Reinforced careful condition checking to avoid false positives Language Used: Java -> Runtime: 0 ms (Beats 100.00%) -> Memory: 43.22 MB Precision and validation go hand in hand—small grids, strict rules, clean logic 🚀 #LeetCode #Java #BruteForce #Matrix #ProblemSolving #Algorithms #100DaysOfCode
To view or add a comment, sign in
-
-
📅 Day 62 of #100DaysOfLeetCode 🔢 Problem: 1458. Max Dot Product of Two Subsequences 🟥 Difficulty: Hard 🧠 Problem Summary Given two integer arrays, find the maximum dot product between non-empty subsequences of equal length while preserving order. 💡 Key Insight This problem is a DP + subsequence variant similar to LCS, but with an important twist: 👉 The answer can be negative, so initializing DP with 0 will fail. 👉 We must ensure at least one pair is chosen. 🚀 Approach (Memoization / Top-Down DP) Use recursion with indices (i, j) At each step, consider: Pairing nums1[i] with nums2[j] Skipping an element from either array Use Math.max(0, previous) to avoid extending negative subsequences Memoize results to achieve O(n × m) complexity ⏱ Complexity Time: O(n × m) Space: O(n × m) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🔹 Day 95 – LeetCode Practice 📌 Problem: Maximum Depth of Binary Tree (LeetCode #104) 📊 Difficulty: Easy 🧠 Problem Overview: Given the root of a binary tree, the task is to determine its maximum depth. The maximum depth is defined as the number of nodes along the longest path from the root node down to the farthest leaf node. ✅ Approach Used: Traversed the binary tree using depth-first search. At each node, tracked the current depth. Updated the maximum depth whenever a deeper level was reached. Recursively explored both left and right subtrees. 📈 Complexity Analysis: Time Complexity: O(n), where n is the number of nodes Space Complexity: O(h), where h is the height of the tree 🚀 Submission Results: Status: Accepted ✅ Runtime: 0 ms (Beats 100%) Memory: 44.51 MB (Beats 27.65%) 💡 Reflection: This problem reinforces the fundamentals of tree traversal and recursion. A simple yet important exercise to strengthen understanding of binary tree depth calculations. #LeetCode #DSA #BinaryTree #DFS #ProblemSolving #Java #CodingPractice #Learning
To view or add a comment, sign in
-
-
#Day_59 Problem: 4Sum (LeetCode 18) Day 57 pushed the limits with 4Sum — finding all unique quadruplets equal to a target! 💥 🧠 Key Takeaways: This is an extension of 3Sum → fix two elements + two pointers. Sorting is the backbone. Duplicate skipping at both outer and inner levels is critical. Use long for sum to avoid overflow. ⚙️ Optimized Approach: Sort the array. Fix i and j. Apply two pointers for remaining part. Carefully skip duplicates. ⏱️ Complexity: O(n³), but still efficient compared to brute force. 📌 This problem taught me: How patterns scale from 2Sum → 3Sum → 4Sum. Writing clean, duplicate-free logic. Consistency + patterns = confidence! 💪 #Day57 #4Sum #LeetCode #Java #DSA #CodingPractice #LearnByDoing
To view or add a comment, sign in
-
-
📅 Day 53 of #100DaysOfLeetCode Problem: 840. Magic Squares In Grid Difficulty: Medium 🔍 Problem Insight A 3×3 magic square must: Contain distinct numbers from 1 to 9 Have the same sum for all rows, columns, and both diagonals The task is to count how many such 3×3 subgrids exist inside a given grid. 💡 Key Observations Magic squares are strictly limited to 3×3 Any number outside 1–9 immediately invalidates the square Duplicate values break the magic condition Grid size is small, allowing safe sliding-window checks ⚙️ Approach Slide a 3×3 window across the grid For each window: Use a HashSet to ensure values are unique and within 1–9 Compute the target sum from the first row Validate: All rows All columns Both diagonals Count all valid magic squares ⏱️ Complexity Time: O(m × n) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
📅 Day 43 of #100DaysOfLeetCode 🧩 Problem: 944. Delete Columns to Make Sorted ⚡ Difficulty: Easy 🚀 What I learned today: Visualized the input as a grid of characters (row-wise strings, column-wise comparison) Iterated column by column and checked if characters are lexicographically sorted top to bottom As soon as a column violates sorting (strs[i][j] < strs[i-1][j]), it must be deleted Early break optimization avoids unnecessary comparisons 🧠 Approach: Loop through each column Compare adjacent rows in that column Count columns where the order is not non-decreasing ⏱️ Complexity: Time: O(n × m) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
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