Day 39/100 – #100DaysOfCode 🚀 | #Java #LeetCode #HashMap ✅ Problem Solved: Minimum Index Sum of Two Lists 🧩 Problem Summary: Given two string arrays, find the common strings with the smallest index sum (index in list1 + index in list2). If multiple answers exist, return all of them. 💡 Approach Used: ➤ Stored the elements of the first list in a HashMap with their indices. ➤ Iterated the second list and checked for matches. ➤ Tracked the minimum index sum and collected all strings that match that sum. This avoids nested loops and improves efficiency. ⚙️ Time Complexity: O(n + m) 📦 Space Complexity: O(n) ✨ Takeaway: HashMaps continue to be one of the most effective tools for reducing time complexity through direct lookups 🔍⚡ #Java #LeetCode #HashMap #DataStructures #ProblemSolving #100DaysOfCode #CodingJourney
Solved Minimum Index Sum of Two Lists with HashMap in Java
More Relevant Posts
-
Day 45/100 – #100DaysOfCode 🚀 | #Java #Hashing #SlidingWindow ✅ Problem Solved: Contains Duplicate III (LeetCode 220) 🧩 Problem Summary: Given an integer array and integers k and t, determine if there exist two distinct indices i and j such that: |i - j| ≤ k |nums[i] - nums[j]| ≤ t 💡 Approach Used: Used a Sliding Window + TreeSet to maintain numbers in a sorted structure. Steps: Traverse the array and maintain a window of at most size k. For each element x, find if there exists another element in the set such that |x - y| ≤ t. This is done using ceiling() to find the closest value ≥ x. Insert the element in TreeSet and remove the element that slides out. ⚙️ Time Complexity: O(n log k) 📦 Space Complexity: O(k) ✨ Takeaway: This problem teaches how ordered data structures like TreeSet help efficiently handle range queries in sliding window scenarios. #Java #TreeSet #SlidingWindow #LeetCode #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 29/100 – #100DaysOfCode 🚀 | #Java #LeetCode #BinaryTree ✅ Problem Solved: Verify Preorder Serialization of a Binary Tree 🌲 🧩 Problem Summary: Given a string representing a preorder serialization of a binary tree, determine if it’s valid. Example: "9,3,4,#,#,1,#,#,2,#,6,#,#" → ✅ valid "1,#" → ❌ invalid 💡 Approach Used: Used the slot-counting method 🧠 Each node uses one slot and non-null nodes create two new slots. Process the preorder string, ensuring slots never go negative and exactly zero remain at the end. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Takeaway: This problem teaches how binary tree structure can be validated with simple counting logic — no need to rebuild the tree! 🌱 #Java #LeetCode #BinaryTree #100DaysOfCode #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 44/100 – #100DaysOfCode 🚀 | #Java #LinkedList ✅ Problem Solved: Reverse Nodes in k-Group (LeetCode 25) 🧩 Problem Summary: Given a linked list, reverse every group of k consecutive nodes. If the last group has fewer than k nodes, leave it as is. 💡 Approach Used: We first count whether k nodes exist — only then we reverse that segment. Steps: Traverse ahead k nodes to ensure reversal is possible. Reverse exactly k nodes iteratively. Recursively process the remaining list. Connect the reversed part with the next processed segment. This allows efficient in-place operations without extra memory. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) (Reversing done in-place) ✨ Takeaway: This problem strengthens understanding of pointer manipulation and linked list segment handling — vital for clean and bug-free list operations. #Java #LinkedList #Pointers #Recursion #LeetCode #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 48/100 – #100DaysOfCode 🚀 | #Java #Backtracking #Recursion ✅ Problem Solved: Palindrome Partitioning (LeetCode 131) 🧩 Problem Summary: Given a string s, partition it such that every substring in the partition is a palindrome. Return all possible palindrome partitioning combinations. 💡 Approach Used: Used Backtracking to explore all possible substring splits. Key Idea: At each position, expand and check if the substring s[start…i] is a palindrome. If yes → include it and recurse for the rest of the string. If no → skip and continue searching. Helper Components: Recursive DFS function for exploring partitions. A fast palindrome-checking utility. ⚙️ Time Complexity: O(N × 2ⁿ) 📦 Space Complexity: O(N) (recursion stack + path building) ✨ Takeaway: This problem strengthens understanding of recursion tree exploration, decision branching, and string-based backtracking. #Java #LeetCode #Backtracking #Recursion #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
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
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
-
-
🚀#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
-
🚀 𝐉𝐚𝐯𝐚 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐒𝐞𝐫𝐢𝐞𝐬 – 𝐃𝐚𝐲 𝟖 𝐇𝐨𝐰 𝐝𝐨𝐞𝐬 𝐉𝐚𝐯𝐚 𝐡𝐚𝐧𝐝𝐥𝐞 𝐏𝐚𝐬𝐬-𝐛𝐲-𝐕𝐚𝐥𝐮𝐞 𝐯𝐬 𝐏𝐚𝐬𝐬-𝐛𝐲-𝐑𝐞𝐟𝐞𝐫𝐞𝐧𝐜𝐞? 🧠 𝐄𝐱𝐩𝐥𝐚𝐧𝐚𝐭𝐢𝐨𝐧: In Java, everything is 𝐩𝐚𝐬𝐬-𝐛𝐲-𝐯𝐚𝐥𝐮𝐞, but the tricky part lies in understanding what that “𝐯𝐚𝐥𝐮𝐞” is. When you pass a 𝐩𝐫𝐢𝐦𝐢𝐭𝐢𝐯𝐞 type (like int, double, boolean): 👉 A copy of the value is passed to the method. Any changes inside the method don’t affect the original variable. When you pass an 𝐨𝐛𝐣𝐞𝐜𝐭: 👉 A copy of the reference (address) is passed. So, you can modify the object’s data inside the method, but if you reassign the object to a new one, the original reference remains unchanged. 📘 𝐄𝐱𝐚𝐦𝐩𝐥𝐞: 𝑐𝑙𝑎𝑠𝑠 𝐷𝑒𝑚𝑜 { 𝑖𝑛𝑡 𝑣𝑎𝑙𝑢𝑒 = 10; } 𝑝𝑢𝑏𝑙𝑖𝑐 𝑐𝑙𝑎𝑠𝑠 𝑇𝑒𝑠𝑡 { 𝑝𝑢𝑏𝑙𝑖𝑐 𝑠𝑡𝑎𝑡𝑖𝑐 𝑣𝑜𝑖𝑑 𝑚𝑎𝑖𝑛(𝑆𝑡𝑟𝑖𝑛𝑔[] 𝑎𝑟𝑔𝑠) { 𝐷𝑒𝑚𝑜 𝑑 = 𝑛𝑒𝑤 𝐷𝑒𝑚𝑜(); 𝑚𝑜𝑑𝑖𝑓𝑦(𝑑); 𝑆𝑦𝑠𝑡𝑒𝑚.𝑜𝑢𝑡.𝑝𝑟𝑖𝑛𝑡𝑙𝑛(𝑑.𝑣𝑎𝑙𝑢𝑒); // 𝑂𝑢𝑡𝑝𝑢𝑡: 20 } 𝑠𝑡𝑎𝑡𝑖𝑐 𝑣𝑜𝑖𝑑 𝑚𝑜𝑑𝑖𝑓𝑦(𝐷𝑒𝑚𝑜 𝑜𝑏𝑗) { 𝑜𝑏𝑗.𝑣𝑎𝑙𝑢𝑒 = 20; // 𝑚𝑜𝑑𝑖𝑓𝑖𝑒𝑠 𝑜𝑟𝑖𝑔𝑖𝑛𝑎𝑙 𝑜𝑏𝑗𝑒𝑐𝑡 𝑜𝑏𝑗 = 𝑛𝑒𝑤 𝐷𝑒𝑚𝑜(); 𝑜𝑏𝑗.𝑣𝑎𝑙𝑢𝑒 = 30; // 𝑡ℎ𝑖𝑠 𝑤𝑜𝑛'𝑡 𝑎𝑓𝑓𝑒𝑐𝑡 𝑡ℎ𝑒 𝑜𝑟𝑖𝑔𝑖𝑛𝑎𝑙 𝑜𝑏𝑗𝑒𝑐𝑡 } } ✅ 𝐎𝐮𝐭𝐩𝐮𝐭: 20 — because the object reference was passed by value, not the object itself. 💡 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Java always uses pass-by-value — even for objects, it passes the reference value, not the actual object. 🔖 #JavaInterviewQuestions #CoreJava #JavaConcepts #JavaDeveloper #ProgrammingTips #OOPsInJava #PassByValue #JavaCommunity #TechLearning #100DaysOfCode
To view or add a comment, sign in
-
Day 51/100 – #100DaysOfCode 🚀 | #Java #LinkedList #Heap ✅ Problem Solved: Merge k Sorted Lists (LeetCode) 🧩 Problem Summary: You’re given k sorted linked lists. The task is to merge them into one sorted linked list. 💡 Approach Used: Use a Min-Heap (PriorityQueue) to always pick the node with the smallest value among all current heads of the lists. Steps: Push the head of each non-null list into the Min-Heap. Extract the smallest, attach to result, and push its next node (if exists). Continue until heap becomes empty. This ensures efficient merging. ⚙️ Time Complexity: O(N log k) 📦 Space Complexity: O(k) ✨ Takeaway: When multiple sorted streams exist, heaps provide clean and optimal merging. #Java #LeetCode #Heap #LinkedList #ProblemSolving #CodingChallenge #100DaysOfCode
To view or add a comment, sign in
-
-
💻 Day 30 🚀of #30DaysOfLeetCode Problem: Move Zeroes https://lnkd.in/gBYJphPM Language: Java ☕ 🧠 Logic: Traverse the array, move all non-zero elements forward, and fill remaining positions with zeros — all done in-place! ✅ Result: Runtime: 2 ms (Beats 79.18%) Memory: 46.02 MB (Beats 80.31%) 🗣️ “Optimization isn’t about speed alone — it’s about clean, efficient logic.” #LeetCode #Java #CodingChallenge #30DaysOfCode #ProblemSolving #MoveZeroes #Day30 #CodeDaily
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