🚀 Day 2 | Problem 3 of my 15-Day 50+ String DSA Challenge Problem: Swap Two Strings (Without Using a Third Variable) Today I learned how to swap two strings without using an extra variable. Since strings are immutable in Java, the solution uses concatenation and substring logic (with StringBuilder for efficiency). Key learnings: • Strings are immutable, so direct swapping isn’t possible • Concatenation + substring can be used to swap values • Understanding string length and indexing is crucial Building strong fundamentals step by step 💪 #DSA #Java #StringProblems #LearningInPublic #CodingJourney
Java String Swap Challenge Solution
More Relevant Posts
-
🚀 Day 2 | Problem 1 of my 15-Day 50+ String DSA Challenge Problem: Find Length of a String (without using length()) Today I practised a basic but important string problem in Java and focused on understanding different looping approaches. Key learnings: • Calculated string length without using built-in methods • Understood the difference between `for` loop and `for-each` loop • Learned when index-based iteration is needed and when simple traversal is enough Strengthening fundamentals step by step 💪 #DSA #Java #StringProblems #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 96 of #100DaysOfCode Solved LeetCode #1461 – Check If a String Contains All Binary Codes of Size K ✅ A solid mix of sliding window + bit manipulation, where efficiency really matters. Key Takeaways: -> Using rolling hash / bitmask to track binary substrings -> Avoiding substring overhead for better performance -> Understanding the limit: total required codes = 2^k -> Early pruning with length checks for optimization Language: Java -> Runtime: 6 ms (Beats 100%) ⚡ -> Memory: 47.73 MB Almost at the finish line — one binary string at a time 💻🔥 #LeetCode #Java #BitManipulation #SlidingWindow #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 25 of #100DaysOfLeetCode 💻✅ Solved #167. Two Sum II – Input Array Is Sorted on LeetCode using Java. Approach: • Used Two Pointer technique since the array is already sorted • Initialized one pointer at the beginning and one at the end • Calculated the sum of both elements • If sum < target, moved left pointer forward • If sum > target, moved right pointer backward • Returned 1-based indices as required in the problem Performance: ✓ Runtime: 1 ms (Efficient with O(n) time complexity) ✓ Memory: Constant extra space (O(1)) Key Learning: ✓ Understood when to apply Two Pointer technique instead of HashMap ✓ Improved ability to optimize space complexity ✓ Strengthened pattern recognition for sorted array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 17 of #100DaysOfCode Solved the Concatenation of Consecutive Binary Numbers problem today using Bit Manipulation + Modulo Arithmetic in Java. Instead of converting numbers to binary strings, we shift the current result left by the number of bits in i and add i. We increase the bit count only when i is a power of 2 using: (i & (i - 1)) == 0 #Java #DSA #BitManipulation #LeetCode #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
🚀 Day 76 of #100DaysOfCode Today I solved a string manipulation problem: Clear Digits 🧠 Problem: Given a string, whenever a digit appears, remove the previous character. Digits act like a backspace operation. 💡 Key Insight: Instead of modifying the string directly (since Strings are immutable in Java), I used a StringBuilder, which works like a stack: If character → append (push) If digit → delete last character (pop) 📌 What I Learned: StringBuilder is powerful for string modifications Always handle edge cases (like digit at the start) Many string problems are actually stack problems in disguise ⏱ Complexity: Time: O(n) Space: O(n) #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 36 of #100DaysOfLeetCode 💻✅ Solved #111. Minimum Depth of Binary Tree on LeetCode using Java. Approach: • Used recursive approach to calculate minimum depth • Returned 0 when root is null (base case) • If one subtree is null, avoided taking minimum of 0 (handled edge case carefully) • Returned 1 + minimum depth of valid subtree • Ensured correct handling of skewed trees Performance: ✓ Runtime: 6 ms ✓ Memory: 82.20 MB Key Learning: ✓ Understood difference between minimum depth and maximum depth logic ✓ Learned importance of handling null subtree cases correctly ✓ Improved confidence in solving binary tree recursion problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 18/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 1528. Shuffle String Used a direct indexing approach by placing each character at its correct position using the given indices array. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) A simple yet important problem to strengthen understanding of arrays and index mapping. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 2 | Problem 2 of my 15-Day 50+ String DSA Challenge Problem: Count Vowels in a String (Java) Today I worked on a basic but important string problem and focused on getting the logic and flow right instead of just writing code. Key learnings: • Iterating through each character of a string • Correct use of loop boundaries to avoid runtime errors • Understanding array indexing (0 to length-1) • Applying conditional checks cleanly for vowel detection Strengthening fundamentals step by step 💪 #DSA #Java #StringProblems #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 5 | Problem 1 – Score of a String Today I practised calculating the score of a string by finding the absolute difference between adjacent characters. Approach used: • Traverse the string from left to right • Calculate the absolute ASCII difference between consecutive characters • Add each difference to a running sum • Return the final score This problem helped me better understand character handling in strings, ASCII values, and loop-based traversal. #Java #DSA #StringProblems #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 1/100 – LeetCode Challenge 🚀 Problem: #867 Transpose Matrix Difficulty: Easy Language: Java Approach: Nested Loop with Index Swapping Time Complexity: O(m × n) Space Complexity: O(m × n) 🔍 Key Insight: The transpose of a matrix swaps rows and columns. If original matrix is m × n, the result will be n × m. Careful index handling is important to avoid dimension errors. 🧠 Solution Brief: Created a new matrix with reversed dimensions. Traversed the original matrix using nested loops. Assigned result[j][i] = matrix[i][j] to swap row and column indices. Returned the transposed matrix. this solution is basicaly bruteforce approach 📌 What I Learned: Even simple matrix problems improve understanding of 2D array traversal and index manipulation. Consistency starts today — 99 more days to go 💪 #LeetCode #Day1 #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney #LearningInPublic
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