🚀 𝐃𝐚𝐲 89/100 – 𝐈𝐬 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 Today’s problem was 𝐈𝐬 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 — a simple yet fundamental problem to understand two-pointer technique. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: We can efficiently check if one string is a subsequence of another using two pointers. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Traverse both strings Move pointer of s only when characters match Always move pointer of t 𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? We try to match characters of s in order within t without disturbing sequence. ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Initialize two pointers i (for s) and j (for t) If characters match → move both Else → move only j If i reaches end of s → subsequence exists ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(1) #Day89 #100DaysOfCode #Java #DSA #LeetCode #TwoPointers #CodingJourney
Chhaya Shah’s Post
More Relevant Posts
-
🚀 𝐃𝐚𝐲 93/100 ✅ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦: 𝐋𝐨𝐧𝐠𝐞𝐬𝐭 𝐂𝐨𝐧𝐭𝐢𝐧𝐮𝐨𝐮𝐬 𝐈𝐧𝐜𝐫𝐞𝐚𝐬𝐢𝐧𝐠 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 Today’s problem focused on finding the length of the longest continuous increasing subarray. Unlike LIS, this must be strictly increasing AND contiguous. 💡 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬: Use a simple linear scan Maintain two variables: curr and maxLen Reset streak when order breaks Time Complexity: O(n), Space: O(1) 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Traverse the array and compare each element with the previous one: If increasing → extend streak Else → reset streak Keep updating maximum length #Day93 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #KeepLearning
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 94/100 ✅ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦: 𝐑𝐞𝐩𝐞𝐚𝐭𝐞𝐝 𝐒𝐮𝐛𝐬𝐭𝐫𝐢𝐧𝐠 𝐏𝐚𝐭𝐭𝐞𝐫𝐧 Today’s problem was about checking whether a string can be formed by repeating one of its substrings multiple times. 💡 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬: Try all possible substring lengths up to n/2 Only consider lengths that divide the string completely Build and compare repeated string with original Time Complexity: O(n²) in worst case 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Iterate over possible substring sizes If length divides string → repeat substring Compare with original string If match found → return true #Day94 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 47/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 448. Find All Numbers Disappeared in an Array Used an in-place marking technique by treating indices as a hash map and marking visited numbers as negative to identify missing elements. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) Strengthening understanding of array manipulation and in-place hashing tricks. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 33/50 🚀 — Valid Palindrome (Two Pointer Approach) Today’s problem was a great mix of string manipulation + two pointers. 🔹 Ignored non-alphanumeric characters 🔹 Handled case-insensitivity 🔹 Compared characters from both ends efficiently Key insight: Instead of preprocessing the string, we can optimize in-place using two pointers, skipping unwanted characters on the go. 💡 This improves both readability and performance. Performance: ⚡ Runtime: 2 ms (99%+) 📦 Memory: Efficient #Day33 #LeetCode #TwoPointers #DSA #Java #CodingJourney #50DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 46/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 2315. Count Asterisks Used a boolean flag approach to track whether the current position is inside a pair of '|' and count only the valid '*' outside those sections. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening understanding of state-based string traversal and conditional counting. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 92/100 ✅ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦: 𝐓𝐡𝐢𝐫𝐝 𝐌𝐚𝐱𝐢𝐦𝐮𝐦 𝐍𝐮𝐦𝐛𝐞𝐫 Today’s problem was about finding the third distinct maximum number in an array. If it doesn’t exist, we return the maximum number instead. 💡 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬: Maintain three variables to track top 3 distinct values Handle 𝐝𝐮𝐩𝐥𝐢𝐜𝐚𝐭𝐞𝐬carefully Use 𝐋𝐨𝐧𝐠.𝐌𝐈𝐍_𝐕𝐀𝐋𝐔𝐄 to avoid edge case issues Single pass solution → 𝐎(𝐧) 𝐭𝐢𝐦𝐞 𝐜𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Instead of sorting, we efficiently track max1, max2, and max3 while iterating through the array. This improves performance and avoids unnecessary computations. #Day92 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
Solved a problem where we need to check if two strings can be made equal using a special operation. The rule is: you can swap characters only if the distance between their positions is even. So basically, characters at even indices can only swap among themselves, and same for odd indices. Idea: Instead of actually swapping, I just counted characters separately for even and odd positions in both strings. If both match, then it’s possible — otherwise not. Simple concept, but interesting twist! 😊 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 62 of #100DaysOfLeetCode 💻✅ Solved #219. Contains Duplicate II problem in Java. Approach: • Used two nested loops to compare elements within range k • For each element, checked next k elements • If any duplicate is found within distance k, returned true • If no such pair exists, returned false Key Learning: ✓ Practiced checking duplicates within a given range ✓ Strengthened understanding of array traversal with conditions ✓ Learned the importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 88 - LeetCode Journey Solved LeetCode 24: Swap Nodes in Pairs in Java ✅ This problem is a great exercise in pointer manipulation in linked lists. Instead of changing values, I swapped the actual nodes by carefully adjusting the next pointers. Using a dummy node made the process much cleaner and helped handle edge cases smoothly. Step by step, I swapped pairs while moving forward in the list. Key takeaways: • Deep understanding of pointer manipulation • Importance of dummy node in linked list problems • Clean handling of edge cases • Iterative approach for swapping nodes ✅ All test cases passed ⚡ Efficient O(n) time and O(1) space Linked list problems like this really sharpen your fundamentals 🔥 #LeetCode #DSA #Java #LinkedList #Pointers #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 69/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 2103. Rings and Rods Used a 2D boolean array to track presence of colors (R, G, B) on each rod and counted rods containing all three. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening understanding of mapping, indexing, and state tracking techniques. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
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