Day 28/100 – #100DaysOfCode 🚀 | #Java #LeetCode #DynamicProgramming ✅ Problem Solved: Scramble String 🔀 🧩 Problem Summary: Given two strings s1 and s2, determine whether one is a scrambled version of the other. A string is scrambled by recursively dividing it into two non-empty substrings and swapping them. 💡 Approach Used: Implemented Recursion + Memoization using a HashMap for overlapping subproblems. Used character frequency checks to prune unnecessary recursion calls. Used Java’s BiFunction with inline helper logic for recursion. ⚙️ Time Complexity: O(n⁴) (due to substring operations and recursion) 📦 Space Complexity: O(n²) ✨ Takeaway: Even complex recursive problems can be optimized efficiently with Memoization and early pruning. 🚀 #Java #LeetCode #DynamicProgramming #Recursion #ProblemSolving #100DaysOfCode #CodingChallenge
Solved Scramble String problem using Java and recursion
More Relevant Posts
-
Day 90 of #100DaysOfCode Solved Squares of a Sorted Array in Java 🔠 Approach The task was to take an array of integers sorted in non-decreasing order, square each number, and then return the result array also sorted in non-decreasing order. Brute-Force Method The solution implemented here is a straightforward two-step brute-force approach: Squaring: I iterated through the input array nums and replaced each element with its square (i.e., nums[i] * nums[i]). This handles both positive and negative numbers correctly. Sorting: After squaring all elements, I used Java's built-in Arrays.sort(nums) method to sort the entire array. While correct, this approach has a time complexity dominated by the sorting step, which is O(NlogN), where N is the number of elements. The runtime of 10 ms shows that a more efficient, two-pointer approach (which can solve this in O(N) time) is generally preferred for optimal performance. #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Array #Sorting #ProblemSolving
To view or add a comment, sign in
-
-
#Day45 of #50DaysOfCoding Divisible Sum Pairs Problem (Java) Today, I tackled the “Divisible Sum Pairs” problem from HackerRank using Java. The objective was to identify all pairs of numbers in a list whose sum is divisible by a specified integer k. Concepts Used: - Nested loops to check every unique pair (i, j) where i < j. - Modulo operation to verify divisibility: (ar[i] + ar[j]) % k == 0. - Basic iteration and condition checking logic. Working: - Read input values n, k, and the array ar. - Iterate through all pairs. - Count how many pairs have sums divisible by k. - Print the total count. Example: If n = 6, k = 3, and ar = [1, 3, 2, 6, 1, 2], the valid pairs are (1,2), (3,6), (2,4), etc. Output: 5 Complexity: - Time Complexity: O(n²) - Space Complexity: O(1) This exercise enhanced my understanding of modulo operations, loops, and pair iteration logic — essential concepts for many coding interviews. #Java #ProblemSolving #CodingJourney #Programming #LearningEveryday #LogicBuilding #leetcode #DSA #CodingChallenge #LearnJava #CodeNewbie #Algorithms #DataStructures #TechJourney #javaProgramming #LearningInPublic #PentagonSpace
To view or add a comment, sign in
-
-
🚀 Day 18/100 of #100DaysOfCode ✅ Solved “Isomorphic Strings” (LeetCode #205) using Java! 🧩 Problem: Given two strings s and t, determine if they are isomorphic. 👉 Two strings are isomorphic if characters in one string can be replaced to get the other — while keeping order and unique mapping intact. 🧠 Approach: Used a HashMap to store the mapping of characters from s → t. Checked if each character in s has a consistent mapping in t. Also ensured that no two characters in s map to the same character in t. ✨ Example: s = "egg", t = "add" → true (e→a, g→d) s = "foo", t = "bar" → false 📈 Complexity: Time: O(n) Space: O(n) 💡 Key Learnings: Understood how to maintain one-to-one character mapping using a HashMap. Reinforced logic building for pattern matching between strings. 💻 Tech Used: Java | HashMap | Problem Solving #LeetCode #100DaysOfCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing #DevCommunity
To view or add a comment, sign in
-
-
How do you make Java code more readable and robust? With Algebraic Data Types (records + sealed types) and Pattern Matching, you can encode valid state and simplify logic—without extra libraries. https://lnkd.in/eEHyKkwb ← Full guide by Balkrishna Rawool! #PatternMatching #ProjectAmber #DataOrientedProgramming #Java #CleanCode
To view or add a comment, sign in
-
-
Just solved “Search in a Binary Search Tree” in Java with 100% runtime efficiency This problem was a great reminder of how elegant and efficient Binary Search Tree (BST) traversal can be when approached iteratively. 🔍 Key Idea: Start from the root and navigate left or right based on the target value — no recursion, just clean and optimized logic! 💡 Takeaway: Sometimes the simplest, most readable solutions are also the fastest. Writing clean and efficient code is a skill built through consistency and understanding the fundamentals. #Java #LeetCode #DSA #BinarySearchTree #CodingJourney #ProblemSolving #CleanCode
To view or add a comment, sign in
-
-
🎯 Day 62 of #100DaysOfLeetCode Today I solved the “Merge Two Sorted Lists” problem using Java This problem is a great exercise in understanding how to work with Linked Lists and pointer manipulation. The goal is to merge two sorted linked lists into one sorted list — without using extra space for another list. Key Concepts Practiced: Linked List traversal Dummy node technique Efficient merging using pointers Handling null edge cases Approach Summary: Create a dummy node to simplify edge cases. Use two pointers to traverse both lists. Compare values and link nodes in sorted order. Attach any remaining nodes at the end. #100DaysOfCode #LeetCode #Java #CodingChallenge #DataStructures #LinkedList #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 80 of #100DaysOfCode Solved Frequency Sort in Java 🔠 Approach Today's problem was to sort an array based on the frequency of its numbers. My initial solution was accepted, but it exposed a major efficiency gap! My strategy involved: Sorting the array first. Using nested loops to count the frequency of each number and store it in a HashMap. (Implied) Using the counts to perform the final custom sort. The core issue was the counting method: running a full loop inside another full loop to get the frequency. This quadratic $O(N^2)$ counting completely tanked the performance. ✅ Runtime: 29 ms (Beats 12.02%) ✅ Memory: 45.26 MB (Beats 5.86%) Another great lesson in algorithmic complexity! The difference between $O(N^2)$ and the optimal $O(N \log N)$ for this problem is massive. Time to refactor and implement the fast, single-pass $O(N)$ frequency count using getOrDefault! 💪 #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Arrays #HashMap #Optimization #ProblemSolving
To view or add a comment, sign in
-
-
Today I worked on the problem "Convert Sorted List to Binary Search Tree" in Java — a perfect blend of Linked List and Tree logic! 🌳 🔍 Key Concepts Covered: Finding the middle element of a Linked List using the slow & fast pointer approach Recursively constructing a height-balanced BST Strengthening understanding of Divide and Conquer strategies This problem really sharpened my thinking around recursive structures and pointer management — small yet powerful steps toward writing more efficient and elegant Java code. 💻✨ 💬 What’s your favorite data structure to work with — Linked Lists or Trees? #LeetCode #Java #DataStructures #Algorithms #CodingJourney #LearningEveryday #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 75 / 100 Days of Code 🌳 Problem: Check if a Binary Tree is Univalue A tree is univalue if all nodes contain the same value. ✅ My Approach Recursively check both left and right subtree If a node doesn't match the root value → return false Base case: null nodes naturally return true Result: 0 ms runtime, beating 100% submissions 🚀 💡 Takeaway Recursion really shines when validating conditions across tree structures. 🧩 Tech Stack: Java </> Algorithm | Recursion | Trees #100DaysOfCode #LeetCode #Java #DataStructures #CodingJourney #ProblemSolving #LinkedList
To view or add a comment, sign in
-
-
🚀#Day29 of my #120DaysOfCodingChallenge in #JavaFullStack 🎯 Today’s Concept: String vs StringBuffer in Java In Java, String and StringBuffer are used to handle text data, but they differ in how they store and modify values. Understanding the difference helps in choosing the right one for efficient and optimized memory usage. 💡 Key Points I Learned: 🔹 String is Immutable Once created, its value cannot be changed. If we try to change it, a new object is created in memory. 🔹 StringBuffer is Mutable Its value can be changed without creating new objects. It is used when frequent modifications or updates are required. 🔹 Performance Difference String → slower for repeated modifications. StringBuffer → faster and memory-efficient in such cases. 🔹 Usage Use String when the value is constant. Use StringBuffer when the text changes often (ex: loops, dynamic data). 🧠 Learning Outcome: This concept helped me understand how memory management works in Java when handling text. Choosing the right type improves performance and makes code more efficient and scalable. 🙏 A big thanks to my mentor Anand Kumar Buddarapu Sir for continuous guidance throughout this journey 🙌 #Java #String #StringBuffer #MemoryManagement #OOPS #JavaFullStack #CleanCode #LearningJourney #120DaysOfCodingChallenge
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