100 Days of Coding Challenge – Day 19 📌 Problem: Merge Sorted Array 💻 Language: Java 🧠 Concept Used: Array Manipulation + Sorting 🔍 Platform: LeetCode Today’s challenge was to merge two sorted arrays into a single sorted array. The result must be stored inside the first array (nums1). Approach: ✔ Copy elements from both arrays into a temporary array ✔ Place the combined elements back into nums1 ✔ Sort the final array to maintain non-decreasing order Time Complexity: O((m+n) log (m+n)) Space Complexity: O(m+n) 🔗 Problem Link: https://lnkd.in/gyFfUaiE 🔗 Code: https://lnkd.in/gA-MrnqG #100DaysOfCode #Day19 #Java #DSA #LeetCode #Arrays #ProblemSolving #CodingJourney
Java Merge Sorted Arrays Challenge
More Relevant Posts
-
100 Days of Coding Challenge – Day 26 📌 Problem: Remove Duplicates from Sorted Array II 💻 Language: Java 🧠 Concept Used: Two Pointer Technique + Counting 🔍 Platform: LeetCode Today’s challenge was to remove duplicates from a sorted array in-place, but this time allowing at most two occurrences of each element. Approach: ✔ Traverse the array and track occurrences using a counter ✔ Allow elements to appear at most twice ✔ Use a pointer k to place valid elements in the correct position ✔ Skip elements when they exceed the allowed count Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gm2_CHbz 🔗 Code: https://lnkd.in/gKxuTbsG #100DaysOfCode #Day26 #Java #DSA #LeetCode #TwoPointers #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 30 📌 Problem: Find the Index of the First Occurrence in a String 💻 Language: Java 🧠 Concept Used: String Matching (Brute Force) 🔍 Platform: LeetCode Today’s challenge was to find the first occurrence of a substring (needle) in a given string (haystack). If not found, return -1. Example: Input: "sadbutsad", "sad" Output: 0 Approach: ✔ Traverse the string from index 0 to n - m ✔ Extract substring of length m at each position ✔ Compare it with the target string ✔ Return index immediately when match is found ✔ If no match → return -1 Time Complexity: O(n × m) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/g2ktYFFS 🔗 Code: https://lnkd.in/gynFixSQ #100DaysOfCode #Day30 #Java #DSA #LeetCode #Strings #ProblemSolving #CodingJourney
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
-
-
100 Days of Coding Challenge – Day 23 📌 Problem: Longest Consecutive Sequence 💻 Language: Java 🧠 Concept Used: Sorting + Sequence Counting 🔍 Platform: LeetCode Today’s challenge was to find the length of the longest sequence of consecutive numbers in an unsorted array. The numbers do not need to be adjacent in the original array, but they must form a continuous sequence like 1,2,3,4. Example: Input: [100, 4, 200, 1, 3, 2] Output: 4 → Longest sequence: [1,2,3,4] Approach: ✔ First sort the array ✔ Traverse the array and check if the next number is consecutive ✔ Skip duplicates ✔ Track the longest streak using a counter Time Complexity: O(n log n) (due to sorting) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gguN6KnH 🔗 Code: https://lnkd.in/gyVFpsbg #100DaysOfCode #Day23 #Java #DSA #LeetCode #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 21 📌 Problem: Word Pattern 💻 Language: Java 🧠 Concept Used: HashMap + String Mapping 🔍 Platform: LeetCode A valid pattern means there must be a one-to-one mapping (bijection) between characters in the pattern and words in the string. In other words: • Each pattern character maps to exactly one unique word • Each word maps to only one pattern character Example: pattern = "abba" s = "dog cat cat dog" → ✅ true Approach: ✔ Split the string into words using split(" ") ✔ Use a HashMap to map pattern characters to words ✔ Ensure no two characters map to the same word ✔ Verify consistency during traversal Time Complexity: O(n) Space Complexity: O(n) 🔗 Problem Link: https://lnkd.in/grDzg_82 🔗 Code: https://lnkd.in/gA9CCyc5 #100DaysOfCode #Day21 #Java #DSA #LeetCode #HashMap #Strings #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 28 📌 Problem: Find First and Last Position of Element in Sorted Array 💻 Language: Java 🧠 Concept Used: Binary Search (Modified) 🔍 Platform: LeetCode Today’s challenge was to find the starting and ending positions of a target value in a sorted array. If the target is not found → return [-1, -1]. Approach: ✔ Use Binary Search since the array is sorted ✔ Perform two searches: • One to find the first occurrence • One to find the last occurrence ✔ Narrow the search space based on comparisons ✔ Combine both results into the final answer Time Complexity: O(log n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gK5EM63Z 🔗 Code: https://lnkd.in/gMwMsF7R #100DaysOfCode #Day28 #Java #DSA #LeetCode #BinarySearch #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 61 of #100DaysOfLeetCode 💻✅ Solved #541. Reverse String II problem in Java. Approach: • Converted the string into a character array • Traversed the array in steps of 2k • For every segment, reversed the first k characters • Used two-pointer technique to perform in-place reversal • Math.min() to handle cases where remaining characters are less than k Performance: ✓ Runtime: 2 ms (Beats 16.04% submissions) ✓ Memory: 44.80 MB (Beats 73.53% submissions) Key Learning: ✓ Practiced handling strings with fixed pattern intervals ✓ Improved control over indexing and boundaries ✓ Strengthened in-place modification techniques Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #TwoPointers #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 49 of #100DaysOfLeetCode 💻✅ Solved #387. First Unique Character in a String problem in Java. Approach: • Created an array of size 26 to store the frequency of each character • Traversed the string and counted how many times each character appears • Traversed the string again to find first character with frequency equal to 1 • Returned the index of that character • If no unique character is found, returned -1 Performance: ✓ Runtime: 6 ms (Beats 84.58% submissions) ✓ Memory: 47.16 MB (Beats 36.29% submissions) Key Learning: ✓ Practiced using frequency arrays for string problems ✓ Learned how counting characters helps find unique elements efficiently ✓ Strengthened understanding of string traversal and indexing Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
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
-
Explore related topics
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