🔹 Day 46: Is Subsequence (LeetCode #392) 📌 Problem Statement: Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence is formed by deleting some (possibly none) characters from the original string without disturbing the relative order of the remaining characters. ✅ My Approach: I used a two-pointer technique — one pointer iterates through string t, and the other tracks progress through string s. Each time a matching character is found, the pointer for s moves forward. If we reach the end of s, it means all its characters appeared in sequence within t. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 2 ms (Beats 68.53%) Memory: 41.32 MB (Beats 87.28%) 💡 Reflection: A simple yet elegant problem that highlights how pointer movement can efficiently handle string comparisons without extra memory usage. ✨ #LeetCode #Java #Strings #TwoPointers #100DaysOfCode #Day46
"Is Subsequence (LeetCode #392) - Java Solution with Two Pointers"
More Relevant Posts
-
#100DaysOfCode – Day 67 Reverse Words in a String Problem: – Reverse Words in a String Task: – Given a string, reverse the order of the words and remove extra spaces. Example: Input: s = " the sky is blue " → Output: "blue is sky the" My Approach: Used trim() to remove leading and trailing spaces. Split the string using split("\\s+") to handle multiple spaces. Reversed the array and joined the words with a single space. Time Complexity: O(N) | Space Complexity: O(N) Even simple string problems can teach the importance of clean code and efficient use of built-in methods. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #CodeNewbie #StringManipulation
To view or add a comment, sign in
-
-
🎯 LeetCode 394 – Decode String Today I solved a really interesting Stack + String based problem! 💡 Problem Summary: We are given an encoded string containing patterns like 3[a2[c]] where: Numbers represent how many times the substring should repeat. Nested patterns are allowed. The goal is to decode the string correctly. 🧠 Approach: I used two stacks: One to store counts (how many times to repeat) One to store previously formed strings We iterate through the string: Build numbers when digits appear When [ appears, push state to stacks When ] appears, pop and reconstruct substring Else, just append characters normally ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) #LeetCode #Java #DSA #Stack #StringManipulation #CodingJourney #LearnEveryday #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
💡 LeetCode #344 — Reverse String Today I solved LeetCode Problem 344: Reverse String 🔁 Problem Summary: Write a function that reverses a string. The input string is given as a character array s, and you must reverse it in-place (without using extra space). Key Idea: Use the two-pointer technique 👈👉 Initialize one pointer at the start (left) and another at the end (right). Swap the characters at both pointers and move them toward the center. #LeetCode #Java #DSA #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 39 of #100DaysOfLeetCode Problem: 125. Valid Palindrome 🧩 Goal: Check if a given string is a palindrome — ignoring spaces, punctuation, and case. 💻 Approach: 1️⃣ Remove all non-alphanumeric characters. 2️⃣ Convert to lowercase. 3️⃣ Compare the cleaned string with its reverse. class Solution { public boolean isPalindrome(String s) { StringBuilder cleaned = new StringBuilder(); for (char c : s.toCharArray()) { if (Character.isLetterOrDigit(c)) { cleaned.append(Character.toLowerCase(c)); } } String str = cleaned.toString(); String rev = cleaned.reverse().toString(); return str.equals(rev); } } 🕒 Time Complexity: O(n) 💡 Concepts Used: String Manipulation, Two-Pointer Logic ✅ A simple yet powerful problem that helps strengthen string handling fundamentals in Java. #Day39 #LeetCode #Java #CodingChallenge #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 39 of #100DaysOfLeetCode Problem: 125. Valid Palindrome 🧩 Goal: Check if a given string is a palindrome — ignoring spaces, punctuation, and case. 💻 Approach: 1️⃣ Remove all non-alphanumeric characters. 2️⃣ Convert to lowercase. 3️⃣ Compare the cleaned string with its reverse. class Solution { public boolean isPalindrome(String s) { StringBuilder cleaned = new StringBuilder(); for (char c : s.toCharArray()) { if (Character.isLetterOrDigit(c)) { cleaned.append(Character.toLowerCase(c)); } } String str = cleaned.toString(); String rev = cleaned.reverse().toString(); return str.equals(rev); } } 🕒 Time Complexity: O(n) 💡 Concepts Used: String Manipulation, Two-Pointer Logic ✅ A simple yet powerful problem that helps strengthen string handling fundamentals in Java. #Day39 #LeetCode #Java #CodingChallenge #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 71 String Rotation Task: Given two strings s and goal, determine if s can become goal after some number of rotations (moving the first character to the end each time). Example: Input: s = "abcde", goal = "cdeab" Output: true My Approach First, check if both strings have the same length otherwise, rotation is impossible. Then, observe that any valid rotation of s will always appear as a substring in s + s. Simply check: return (s + s).contains(goal); Time Complexity: O(N²) Space Complexity: O(N) Sometimes, elegant insights lead to minimal code doubling a string can reveal every possible rotation effortlessly! #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #StringManipulation #takeUforward #GeeksForGeeks #CodeNewbie #InterviewPrep
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 85 Delete the Middle Node of a Linked List Problem Statement: Given the head of a singly linked list, delete the middle node and return the modified list. My Approach: Used two-pointer technique (slow & fast) to identify the middle node in a single traversal. Maintained a prev pointer to skip the middle node without extra space. Carefully handled the edge case when the list has only one node. Complexity: Time: O(N) Space: O(1) Linked lists are all about pointers and precision a small mistake (like an extra semicolon ";") can make a huge difference. Understanding how slow and fast pointers move gives deep insight into efficient traversal patterns. #LeetCode #100DaysOfCode #Java #LinkedList #ProblemSolving #takeUforward #CodingJourney #DataStructures #CodeNewbie
To view or add a comment, sign in
-
-
🚀 LeetCode #58 – Length of Last Word (Java Solution) Today I solved a classic string problem that tests how well you handle edge cases and string traversal logic. 🧩 Problem Statement: Given a string s consisting of words and spaces, return the length of the last word in the string. A word is defined as a maximal substring consisting of non-space characters only. 🧠 Dry Run Example Input: " fly me to the moon " ➡ After skipping spaces → "fly me to the moon" ➡ Last word = "moon" ➡ Output: 4 ⚙️ Time & Space Complexity Time Complexity: O(n) — we traverse the string once (from the end to the start). Space Complexity: O(1) — no extra space used apart from a few variables. 💡 Key Takeaways: ✅ Learned how to handle trailing spaces properly before counting. ✅ Strengthened understanding of string traversal in reverse. ✅ Explored an alternative approach using trim() + split("\\s+") for readability. ✅ Remembered to test with edge cases like "a" or "Hello " to ensure correctness. Every small problem like this helps in building stronger fundamentals 💪 #Java #LeetCode #ProblemSolving #CodingJourney #LearningInPublic #75DaysOfCode #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🔹 Day 62 of #100DaysOfLeetCodeChallenge 🔹 🚀 Problem: String to Integer (atoi) 🔑 Topic: String Manipulation 🧠 Approach: Step 1: Trim leading whitespaces. Step 2: Check for a sign (+ or -). Step 3: Convert valid digits to integer until a non-digit is found. Step 4: Clamp values beyond 32-bit signed range to [-2³¹, 2³¹ - 1]. Used a long to handle overflow safely before final conversion. ✅ ⏳ Time Complexity: O(n) 💾 Space Complexity: O(1) 📌 Example: Input: "42" → Output: 42 Input: " -042" → Output: -42 🎯 Takeaway: Always handle edge cases — whitespace, signs, and overflow — while converting strings to numbers. 💡 #LeetCode #String #Parsing #Java #ProblemSolving #100DaysOfLeetCodeChallenge 🚀
To view or add a comment, sign in
-
-
🔹 Day 37: Isomorphic Strings (LeetCode #205) 📌 Problem Statement: Given two strings s and t, determine if they are isomorphic — meaning each character in s can be replaced to get t, while maintaining order and uniqueness of mapping. ✅ My Approach: I used two HashMaps to track character mappings in both directions — one from s → t and another from t → s. While iterating through each character pair, I ensured that: A character maps consistently to the same one. No two characters map to the same character. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(n) ⚡ Submission Stats: Runtime: 24 ms (Beats 12.67%) Memory: 42.46 MB (Beats 72.43%) 💡 Reflection: This problem deepened my understanding of bidirectional mapping and consistency checks in string transformations. Elegant use of HashMaps for ensuring one-to-one character relationships! 🔁 #LeetCode #Java #HashMap #Strings #100DaysOfCode #Day37
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