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
Java Two Pointer Technique for Subsequence Problem
More Relevant Posts
-
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 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
To view or add a comment, sign in
-
-
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 27 📌 Problem: Maximum Average Subarray I 💻 Language: Java 🧠 Concept Used: Sliding Window Technique 🔍 Platform: LeetCode Today’s challenge was to find a contiguous subarray of length k that has the maximum average value. Example: Input: [1,12,-5,-6,50,3], k = 4 Output: 12.75 Approach: ✔ Calculate the sum of the first window of size k ✔ Slide the window by removing the left element and adding the next element ✔ Keep track of the maximum sum ✔ Divide by k to get the maximum average Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/ghU4zrpt 🔗 Code: https://lnkd.in/g7qXeHx6 #100DaysOfCode #Day27 #Java #DSA #LeetCode #SlidingWindow #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
-
-
🚀 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
-
-
Day 21 of #100DaysOfCode Today, I worked on the classic string problem: implementing the strStr() function in Java. The goal: Find the first occurrence of a substring (needle) inside another string (haystack). Approach I used: - Applied a sliding window technique - Compared substrings using "substring(i, j)" - Returned the starting index when a match is found Key learning: Understanding how index-based string operations work and how "substring()" helps in breaking down problems step-by-step. Also realized the importance of optimizing solutions to avoid unnecessary string creation. Consistency is slowly turning concepts into confidence! Looking forward to improving this further with more optimized approaches #Java #Coding #DSA #LeetCode #ProblemSolving #LearningJourney #Consistency
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 29 📌 Problem: Isomorphic Strings 💻 Language: Java 🧠 Concept Used: HashMap + Bidirectional Mapping 🔍 Platform: LeetCode Two strings are isomorphic if characters in one string can be replaced to get the other string with a one-to-one mapping, while preserving order. Example: s = "egg", t = "add" → ✅ true Approach: ✔ Traverse both strings simultaneously ✔ Use two HashMaps: • One for mapping s → t • One for mapping t → s ✔ Ensure consistency in both directions ✔ If any mismatch occurs → return false Time Complexity: O(n) Space Complexity: O(n) 🔗 Problem Link: https://lnkd.in/gHJ3Vn2a 🔗 Code: https://lnkd.in/gWrRUiN4 #100DaysOfCode #Day29 #Java #DSA #LeetCode #HashMap #Strings #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
-
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