💡 Day 42 of LeetCode Problem Solved! 🔧 🌟1876. Substrings of Size Three with Distinct Characters🌟 Task : • A string is good if there are no repeated characters. • Given a string s, return the number of good substrings of length three in s. • Note that if there are multiple occurrences of the same substring, every occurrence should be counted. • A substring is a contiguous sequence of characters in a string. Example 1: Input: s = "xyzzaz" Output: 1 Explanation: There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz". The only good substring of length 3 is "xyz". Example 2: Input: s = "aababcabc" Output: 4 Explanation: There are 7 substrings of size 3: "aab", "aba", "bab", "abc", "bca", "cab", and "abc". The good substrings are "abc", "bca", "cab", and "abc". #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
LeetCode Problem 1876: Substrings with Distinct Characters
More Relevant Posts
-
💡 Day 41 of LeetCode Problem Solved! 🔧 🌟28. Find the Index of the First Occurrence in a String🌟 Task : • Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. Example 2: Input: haystack = "leetcode", needle = "leeto" Output: -1 Explanation: "leeto" did not occur in "leetcode", so we return -1. #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
To view or add a comment, sign in
-
-
🚀 Day 67 of #LeetCode Challenge ✅ Problem Solved: Check If Two String Arrays are Equivalent 💡 What I learned today: • Learned how to compare two string arrays without joining them • Understood how to traverse multiple strings using pointers • Improved handling of indices across arrays and strings • Realized the importance of edge cases to avoid runtime errors 🧠 Approach: • Used four pointers to track positions in both arrays and strings • Compared characters one by one • Moved to the next string when current string ends • Ensured both arrays are fully traversed at the end 📊 Key Takeaway: Efficient solutions avoid extra space — comparing character by character is better than building new strings 🔥 Consistency + small improvements every day = big progress #Day67 #LeetCode #CodingJourney #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 58 of #100DaysOfCode Solved 165. Compare Version Numbers on LeetCode 🔗 🧠 Key Insight: Version strings are split by "." into multiple revisions. We compare each revision numerically (not lexicographically). Example: "1.01" = "1.1" (leading zeros don’t matter) ⚙️ Approach (Split + Compare): 1️⃣ Split both versions using "." 🔹 version1 → s1[] 🔹 version2 → s2[] 2️⃣ Traverse till max length of both arrays 3️⃣ For each index i: 🔹 num1 = i < s1.length ? parseInt(s1[i]) : 0 🔹 num2 = i < s2.length ? parseInt(s2[i]) : 0 4️⃣ Compare: 🔹 if num1 < num2 → return -1 🔹 if num1 > num2 → return 1 5️⃣ If all equal → return 0 ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) (for split arrays) #100DaysOfCode #LeetCode #DSA #Strings #TwoPointers #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 87/100 – 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 🚀 Problem: 228. 𝐒𝐮𝐦𝐦𝐚𝐫𝐲 𝐑𝐚𝐧𝐠𝐞𝐬 Today I solved a problem where we need to summarize consecutive numbers in a sorted unique array into ranges. 🔑 𝐈𝐝𝐞𝐚: Traverse the array and keep extending the range while consecutive numbers continue. Once the sequence breaks, close the range and store it. 💡 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Start with the first element as start Move forward while nums[i] + 1 == nums[i+1] If range exists → "start->end" Else → single number "start" 𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Efficient single pass solution (O(n)) by grouping consecutive elements on the fly. #LeetCode #Java #ProblemSolving #DSA #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Day 68 — LeetCode Progress Problem: Check if an array is “special” — meaning every pair of adjacent elements has different parity (one even, one odd). Required: Given an integer array, return true if no two adjacent elements have the same parity, otherwise return false. Idea: If two neighboring numbers are both even or both odd, the condition fails immediately. So just compare parity of adjacent elements throughout the array. Approach: Traverse the array starting from index 1 For each element: Compare it with the previous element If both have same parity → return false If the loop completes → return true Time Complexity: O(n) Space Complexity: O(1) Clean, simple, and a good reminder that not every problem needs something fancy — sometimes it’s just about spotting the pattern. #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
💡 Day 47 of LeetCode Problem Solved! 🔧 🌟 344. Reverse String 🌟 🔗 Solution Code: https://lnkd.in/gE6FQpQN Task: Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Example 1: Input: ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: ["H","a","n","n","a","h"] Output: ["h","a","n","n","a","H"] #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
To view or add a comment, sign in
-
-
The Two-Pointer streak continues! Today’s LeetCode Problem: Is Subsequence. After using multiple pointers to sort arrays and move zeroes, I applied the exact same pattern to string manipulation today. The challenge was figuring out if a shorter string (s) is a valid subsequence of a longer string (t) without disturbing the relative order of the characters. Instead of generating all possible subsequences (which would be a massive O(2ⁿ) performance drain), the Two-Pointer approach solves this beautifully in a single pass. Knocking this out in O(n) time and O(1) space is another great reminder of how incredibly versatile this algorithmic pattern is for both arrays and strings. #DSA #Java #LeetCode #IsSebsequenceProblem
To view or add a comment, sign in
-
-
💡Day 44 of LeetCode Problem Solved! 🔧 🌟205. Isomorphic Strings🌟 Task : • Given two strings s and t, determine if they are isomorphic. • Two strings s and t are isomorphic if the characters in s can be replaced to get t. • All occurrences of a character must be replaced with another character while preserving the order of characters. • No two characters may map to the same character, but a character may map to itself. Example 1: Input: s = "egg", t = "add" Output: true Explanation: The strings s and t can be made identical by: Mapping 'e' to 'a'. Mapping 'g' to 'd'. Example 2: Input: s = "f11", t = "b23" Output: false Explanation: The strings s and t can not be made identical as '1' needs to be mapped to both '2' and '3'. #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
To view or add a comment, sign in
-
-
💡 Day 48 of LeetCode Problem Solved! 🔧 🌟128. Longest Consecutive Sequence🌟 🔗 Solution Code: https://lnkd.in/gyN5ZJBr Task: Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Example 1: Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. Example 2: Input: nums = [0,3,7,2,5,8,4,6,0,1] Output: 9 Example 3: Input: nums = [1,0,1,2] Output: 3 #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
To view or add a comment, sign in
-
-
“Most people try to overcomplicate this one… but the simplest approach wins.” Day 69 — LeetCode Progress Problem: Height Checker Required: Given an array of student heights, return the number of indices where the heights are not in the expected non-decreasing order. Idea: If we sort the array, we get the expected order. Now just compare the original array with the sorted version — mismatches are the answer. Approach: Create a copy of the original array Sort the copied array Traverse both arrays: Compare elements at each index If they differ → increment count Return the count Time Complexity: O(n log n) Space Complexity: O(n) #LeetCode #DSA #Java #Arrays #Sorting #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