Day 48 - LeetCode Journey Solved LeetCode 1108: Defanging an IP Address in Java ✅ A super clean and beginner-friendly string problem that focuses on simple transformation. Problem idea: Replace every "." in the IP address with "[.]" to create a defanged version. Approach: Used built-in replace() method to directly modify the string. No loops, no extra logic — just one line solution. Key takeaways: • Understanding string manipulation basics • Knowing when to use built-in functions for efficiency • Writing clean and concise code • Avoiding overcomplication Time Complexity: O(n) Space Complexity: O(n) ✅ All test cases passed ✅ Optimal and readable solution Sometimes the simplest problems teach the most — clarity in coding matters 🚀 #LeetCode #DSA #Java #Strings #ProblemSolving #CodingJourney #Programming #InterviewPrep #Consistency
Defanging an IP Address in Java: Simple String Transformation
More Relevant Posts
-
Day 11/100 Day Coding Challenge Today, I solved the LeetCode problem: Container With Most Water using Java. Here’s a detailed breakdown of my approach and learning: Problem Statement: Given an array of non-negative integers representing heights of vertical lines on a coordinate plane, find two lines that, along with the x-axis, form a container that holds the maximum water. Challenges: A brute-force approach would check all possible pairs of lines (O(n²)), which is inefficient for large arrays. I aimed for an optimized solution using the two-pointer technique. Approach (Two-Pointer Technique): Initialize two pointers: l at the start, r at the end of the array. Compute the current area: curWater = (r - l) * min(height[l], height[r]). Update maximum area found so far. Move the pointer pointing to the shorter line inward: If height[l] < height[r], increment l. Else, decrement r. Repeat until the pointers meet. #100DaysOfCode #Java #LeetCode #TwoPointerTechnique #ProblemSolving #Algorithms #SoftwareEngineering #Day11
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge 🧩 Problem: 1784 – Check if Binary String Has at Most One Segment of Ones Today’s problem looked confusing at first. Honestly, the problem description wasn’t very intuitive, and I had to read it a couple of times to understand what it was actually asking. 💡 What the question really means: We’re given a binary string without leading zeros, and we need to check if all the 1s appear in only one continuous block. Valid examples: 111 110 1000 Invalid example: 1001 → because the 1s appear in two separate segments So the key idea is simple: If the string ever contains the pattern "01", it means we finished a block of 1s and then encountered another 1 later — which creates multiple segments. ⚡ Approach Just check if "01" exists in the string. If it does → return false Otherwise → return true 🧠 Takeaway Sometimes the hardest part of a problem isn’t the coding — it’s understanding the problem statement clearly. Once the logic clicked, the solution became very straightforward. Consistency with daily problem solving continues. 🔁 #LeetCode #DailyChallenge #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 7 / 100 – LeetCode Challenge Today I solved Length of Last Word (LeetCode #58) using Java. 🔹 Problem: Given a string "s" containing words and spaces, return the length of the last word in the string. 📌 Approach: - Traverse the string from the end. - Ignore trailing spaces. - Start counting characters of the last word. - Stop when a space appears after counting begins. 💡 Key Concepts Practiced: - String traversal - "charAt()" usage - Reverse iteration - Conditional logic ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) ✅ Key Takeaway: Sometimes solving a problem becomes easier when we traverse the data from the end instead of the beginning. #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 12 📌 Problem: Sort Even and Odd Indices Independently 💻 Language: Java 🧠 Concept Used: Array Manipulation + Sorting 🔍 Platform: LeetCode Today’s challenge was to sort elements at even indices in non-decreasing order and elements at odd indices in non-increasing order. Example: Input: [4,1,2,3] Output: [2,3,4,1] This problem improved my understanding of index-based manipulation and conditional sorting. 🔗 Problem Link: https://lnkd.in/gPgaF8zX 🔗 Code: https://lnkd.in/g39vqHiM #100DaysOfCode #Day12 #Java #DSA #LeetCode #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 18 📌 Problem: Is Subsequence 💻 Language: Java 🧠 Concept Used: Two Pointer Technique 🔍 Platform: LeetCode Today’s challenge was to determine whether a string s is a subsequence of another string t. A subsequence means the characters appear in the same order, but not necessarily consecutively. Approach: ✔ Use two pointers to traverse both strings ✔ If characters match, move both pointers ✔ Otherwise, move the pointer of the second string ✔ If all characters of s are matched, it is a valid subsequence ✔ Time Complexity: O(n) ✔ Space Complexity: O(1) This problem reinforced how powerful the two-pointer technique can be for efficient string traversal. 🔗 Problem Link: https://lnkd.in/g_43jvhm 🔗 Code: https://lnkd.in/gG_7d2BC #100DaysOfCode #Day18 #Java #DSA #LeetCode #TwoPointers #Strings #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 49 - LeetCode Journey Solved LeetCode 1021: Remove Outermost Parentheses in Java ✅ A neat stack-depth problem that tests your understanding of valid parentheses and string building. Problem idea: Given a valid parentheses string, remove the outermost parentheses of every primitive substring. Approach: Used a counter to track the depth of parentheses. • For '(' → add only if depth > 0, then increase depth • For ')' → decrease depth first, then add only if depth > 0 This way, we skip the outermost layer of each primitive. Key takeaways: • Understanding primitive decomposition of strings • Using counters instead of stacks for optimization • Writing efficient string manipulation logic • Clean handling of conditions without extra space Time Complexity: O(n) Space Complexity: O(n) ✅ All test cases passed ✅ Efficient and optimized approach Sometimes, tracking depth is all you need instead of a full stack 😄 #LeetCode #DSA #Java #Strings #Stack #ProblemSolving #CodingJourney #InterviewPrep #Consistency
To view or add a comment, sign in
-
-
🚀 Day 19 of my Java DSA Journey Today I solved Decode Ways — LeetCode Problem #91. 🔹 Problem A message containing digits can be decoded using the mapping: 1 → A 2 → B ... 26 → Z The task is to determine how many possible ways the string can be decoded. 🔹 Approach Used: Dynamic Programming Idea • At each position we check two possibilities • Decode a single digit (1–9) • Decode two digits together (10–26) By storing previous results, we avoid recomputing overlapping subproblems. 📊 Complexity • Time Complexity: O(n) • Space Complexity: O(n) 💡 Key Learning This problem introduces Dynamic Programming, where we store intermediate results to efficiently compute the final answer. 🔗 GitHub Solution https://lnkd.in/gW8atfqw Each day of practice is helping me improve my algorithmic thinking and problem-solving skills. #Java #DSA #LeetCode #DynamicProgramming #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 4 – LeetCode Practice Today, I solved the Valid Parentheses problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given a string containing just the characters ()[]{}, the task was to check whether the input string is valid — meaning every opening bracket has a matching closing bracket in the correct order. • I used a stack to match brackets: – When encountering an opening bracket, push it onto the stack. – When encountering a closing bracket, check whether the top of the stack matches the corresponding opening type. – At the end, if the stack is empty, all brackets matched correctly. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(n) 📚 Key Takeaway: This problem helped reinforce stack usage and careful handling of matching pairs — a foundational technique for many parsing and syntax-checking problems. Consistent problem-solving practice continues to build my confidence and coding fundamentals. 💪 #LeetCode #Java #DSA #Stack #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 20 📌 Problem: Remove Duplicates from Sorted Array 💻 Language: Java 🧠 Concept Used: Two Pointer Technique 🔍 Platform: LeetCode Today’s challenge was to remove duplicates from a sorted array in-place while keeping the relative order of elements the same. Approach: ✔ Use two pointers — one to traverse the array and another to track the position of unique elements ✔ Compare the current element with the previous one ✔ If they are different, place the element at the next unique position ✔ Time Complexity: O(n) ✔ Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/g83THPD6 🔗 Code: https://lnkd.in/gmrtpCRT #100DaysOfCode #Day20 #Java #DSA #LeetCode #TwoPointers #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 3 – LeetCode Practice Today, I solved the Longest Common Prefix problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given an array of strings, the task was to find the longest common prefix shared among all strings. • I assumed the first string as the prefix and compared it with each subsequent string. • While characters matched, I kept shortening the prefix when mismatches occurred. • This simple iterative check helped determine the common prefix efficiently. ⏱ Complexity: • Time Complexity: O(n × m) (where n = number of strings, m = length of the shortest string) • Space Complexity: O(1) 📚 Key Takeaway: This problem reinforced my understanding of string traversal, comparison logic, and how to efficiently reduce search space through early termination. Consistent problem-solving practice continues to build my confidence and coding fundamentals. 💪 #LeetCode #Java #DSA #Strings #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
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