----Continuing my DSA practice using Java.---- Today I solved “Isomorphic Strings.” Two strings are isomorphic if characters in one string can be replaced to get the other, while maintaining a consistent one-to-one mapping. Instead of using HashMaps, I used two fixed-size arrays to track character mappings in both directions. If the mapping didn’t match at any index, the strings were not isomorphic. Key takeaway: When character constraints are small (like ASCII), arrays can be faster and cleaner than HashMaps. #DSA #Java #Strings #ProblemSolving #LearningJourney
Isomorphic Strings in Java with Arrays
More Relevant Posts
-
Day 5/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 205. Isomorphic Strings (Easy) Today’s problem focused on understanding character mapping between two strings. It helped strengthen my knowledge of HashMap usage and maintaining one-to-one relationships between characters. 🔎 Approach: Traverse both strings simultaneously Use a HashMap to map characters from string s to string t Ensure each character maps to only one unique character Also verify that two different characters do not map to the same character If all mappings are valid, return true, otherwise false 📌 Example: Input: s = "egg", t = "add" Output: true Explanation: 'e' → 'a' 'g' → 'd' This problem improved my understanding of character mapping, HashMap logic, and string traversal in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
Solved the classic Binary Tree traversal problem using recursion in Java. 🔎 Approach: Inorder follows the pattern: Left → Root → Right ✔️ If the node is null, return (base case) ✔️ Recursively traverse the left subtree ✔️ Add the current node’s value to the result list ✔️ Recursively traverse the right subtree This traversal is especially important because in a Binary Search Tree (BST), inorder traversal gives elements in sorted order. ⏱️ Runtime: 0 ms Understanding recursion + tree traversal patterns makes so many tree problems easier to approach.
To view or add a comment, sign in
-
-
Day 3/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 1768. Merge Strings Alternately (Easy) Today’s problem focused on string manipulation and efficient merging techniques. It helped reinforce my understanding of string traversal and handling different string lengths. 🔎 Approach: Use a loop to iterate through both strings simultaneously Append characters alternately from word1 and word2 Check if one string is longer than the other Append the remaining characters at the end Return the final merged string 📌 Example: Input: word1 = "abc", word2 = "pqr" Output: "apbqcr" This problem improved my understanding of string handling, indexing, and building efficient logic using Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
Day 3/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 977. Squares of a Sorted Array (Easy) Today’s problem focused on array manipulation and sorting logic. It helped me understand how negative numbers affect order after squaring and how to maintain sorted order efficiently. 🔎 Approach: Traverse the array and calculate the square of each element Store the squared values in a new array Sort the new array in non-decreasing order Return the sorted squared array 📌 Example: Input: nums = [-4, -1, 0, 3, 10] Output: [0, 1, 9, 16, 100] This problem strengthened my understanding of arrays, sorting, and handling negative values in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
Entry-level Algorithm Challenge: Array Manipulation in Java. Today I tackled a foundational exercise: reading a list of numbers and filtering out only the negative values. It was a great opportunity to reinforce some core Java concepts: 1. Flow control with do-while loop: Ensuring valid input within a specific range. 2. Simplified iteration with for-each loop: Improving code readability. 3. Handling flags (boolean signals): Providing clear, user-friendly feedback. Check out the logic below! 👇 #Java #Algorithms #SoftwareDevelopment #Coding
To view or add a comment, sign in
-
-
#100daysofcodingchallenge - Day14 Question: Write a Java program to read an array of integers and print the minimum and maximum sum of n-1 elements from the array. Input: Enter number of elements: 5 Enter elements: 1 2 3 4 5 Output: Minimum sum of n-1 elements: 10 Maximum sum of n-1 elements: 14 #100daysofcodingchallenge #codingchallenge #day14 #practicecoding #corejava #problemsolving
To view or add a comment, sign in
-
-
Day 7/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 167. Two Sum II - Input Array Is Sorted (Medium) Today’s problem focused on finding two numbers in a sorted array that sum up to a target. It helped reinforce the two-pointer technique and efficient array traversal. 🔎 Approach: Use two pointers: one at the start (left) and one at the end (right) of the array Calculate the sum of numbers at both pointers If sum equals target, return the 1-indexed positions [left+1, right+1] If sum < target, move left pointer forward If sum > target, move right pointer backward Continue until the solution is found 📌 Example: Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Explanation: 2 + 7 = 9 → indices 1 and 2 This problem strengthened my understanding of two-pointer techniques, sorted arrays, and constant space solutions in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
Day 5/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 1662. Check If Two String Arrays are Equivalent (Easy) Today’s problem focused on string concatenation and comparison. It helped reinforce my understanding of arrays, string handling, and equality checks. 🔎 Approach: Concatenate all elements of word1 to form a single string Concatenate all elements of word2 to form another string Compare the two resulting strings If both strings are equal, return true, otherwise false 📌 Example: Input: word1 = ["ab","c"], word2 = ["a","bc"] Output: true Explanation: word1 → "ab" + "c" = "abc" word2 → "a" + "bc" = "abc" Both strings are equal. This problem strengthened my understanding of string manipulation and array traversal in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
To view or add a comment, sign in
-
-
✅ DSA Day 7 / 100 Solved Median of Two Sorted Arrays on LeetCode using Java. Logic : - Combine both sorted arrays into one array -Sort the merged array - Find the middle index - If the total length is odd → median is the middle element -If even → median is the average of the two middle elements #DSA #100DaysOfCode #Java #LeetCode #BeginnerDSA #LearningInPublic #Consistency
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