𝗗𝗮𝘆 𝟭𝟳/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Solved Isomorphic Strings using a HashMap for character mapping. ➤ Approach (O(n), O(n) space): • If lengths are different → return false • Traverse both strings together • Map each character from s to t • If a mapping already exists, ensure it matches • Also ensure two characters from s don’t map to the same character in t ➤ Key Insight: Isomorphic means maintaining a one-to-one mapping. The mapping must be consistent and unique. ➤ Two checks matter: • Existing mapping should match • No two characters map to the same target #LeetCode #Java #DSA #HashMap #StringProblems #ProblemSolving #20DaysChallenge #Consistency
Isomorphic Strings using HashMap in Java
More Relevant Posts
-
`✅ LeetCode Top Interview 150 – Day 73 Today I solved a classic Binary Tree problem: Validate Binary Search Tree (BST). key idea : Start with range. • Left subtree nodes must be strictly smaller than the root • Right subtree nodes must be strictly greater than the root • Both subtrees must also follow the BST property recursively This problem strengthened my understanding of tree traversal and constraints propagation in recursive algorithms. #LeetCode #DSA #BinaryTree #BinarySearchTree #Java #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Leetcode Problem || Number of Steps to Reduce a Number in Binary Representation to One(1404)🚀 Today I solved a binary manipulation problem where we must: If number is even → divide by 2 If odd → add 1 Count steps until number becomes 1 💡 Learned: How to simulate binary addition using carry Avoid integer overflow Optimize string-based numeric problems #Java #DSA #BitManipulation #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 40/100 | #100DaysOfDSA 💻🔥 Today’s problem: Subarray Sum Equals K Goal: Find the total number of subarrays whose sum equals k. Approach: Prefix Sum + HashMap Idea: • Keep track of the running sum while traversing the array • If (currentSum - k) was seen before, a subarray with sum k exists • Use a HashMap to store prefix sums and their frequencies Key insight: If prefixSum[j] - prefixSum[i] = k, then the subarray between them sums to k. Time Complexity: O(n) Space Complexity: O(n) Big takeaway: Prefix sums combined with hashing can turn many subarray problems from O(n²) to O(n). Day 40 — still stacking patterns. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #PrefixSum #HashMap #Java #CodingJourney #InterviewPrep #ProblemSolving
To view or add a comment, sign in
-
-
Day 23 – Find First and Last Position in Sorted Array Solved this Binary Search problem by finding the first and last occurrence of a target in a sorted array with O(log n) complexity. Key Learnings: Applying binary search twice for boundary detection Adjusting search space using left and right updates Writing overflow-safe mid calculation A great exercise in mastering binary search variations. #DSA #BinarySearch #Java #LeetCode #InterviewPrep
To view or add a comment, sign in
-
-
#Day54 of my second #100DaysOfCode Today’s problem was all about prefix sums and pattern recognition. DSA • Solved Largest Subarray with Sum 0 (GFG) • Started with brute force by checking all subarrays → O(n²) time • Moved to a better approach using prefix sum • Implemented the optimal solution using HashMap to store first occurrence of prefix sums → O(n) time, O(n) space • Key insight: if the same prefix sum appears twice, the elements in between sum to zero This one really strengthened my understanding of prefix sums and how hashing can reduce quadratic problems to linear time. Slow progress, strong foundations. #DSA #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
💡 Detecting Duplicates using Insertion Sort Logic (No Extra Space!) Instead of using HashSet or extra memory, I tried a different approach — modifying Insertion Sort. 👉 Idea: Assume the left part of the array is already sorted. When inserting the next element (key), we shift bigger elements right. During shifting: If we meet an element equal to the key → Duplicate found immediately If smaller → insert at correct position In simple words: Keep shifting while elements are bigger If equal → duplicate If smaller → insert 📊 Complexity: • Worst Case: O(n²) • Space: O(1) • Early exit if duplicate appears Nice reminder that sometimes classic sorting logic can double as a searching technique! #DSA #Java #Algorithms #ProblemSolving #CodingInterview
To view or add a comment, sign in
-
-
Day 3 #SDE Binary Search and Array problems. Solved: • Single Element in a Sorted Array (Binary Search) • Array Duplicates – Find elements appearing twice Key Learnings: • Binary Search can be applied beyond simple searching — it can help identify patterns like the single non-duplicate element in a sorted array. • For duplicate detection in arrays with values in the range 1..n, careful traversal and counting strategies help identify repeated elements efficiently. #LeetCode #DSA #Arrays #BinarySearch #Java #SoftwareEngineering
To view or add a comment, sign in
-
Day 23 - Find Minimum in Rotated Sorted Array Technique Used: Modified Binary Search Key Idea: Since the array is rotated but originally sorted, used binary search to identify the pivot (minimum element). Compared mid with end to determine which half is unsorted and adjusted boundaries accordingly. Time Complexity: O(log n) #Day23 #LeetCode #Java #BinarySearch #DSA #Algorithms
To view or add a comment, sign in
-
-
Day 3/100 – LeetCode Challenge Problem: Valid Palindrome Today’s problem focused on string manipulation and two-pointer logic. Problem Understanding: A string is a palindrome if: All uppercase letters are converted to lowercase All non-alphanumeric characters are removed The string reads the same forward and backward My Approach: Removed non-alphanumeric characters using regex. Converted the string to lowercase. Compared characters from both ends using a two-pointer technique. Key Concepts Practiced: Regular Expressions (replaceAll) String preprocessing Two-pointer traversal Time Complexity: O(n) Space Complexity: O(n) Consistency builds confidence. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #SoftwareEngineer #CodingJourney
To view or add a comment, sign in
-
-
Day 20 - Find Lucky Integer in an Array Technique Used: HashMap Frequency Counting Key Idea: Constructed a frequency map to count occurrences of each element. Iterated through the map to identify elements whose value equals their frequency, and returned the maximum among them. Time Complexity: O(n) #Day20 #LeetCode #Java #DSA #HashMap #ProblemSolving
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