💡 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
Elangovan P’s Post
More Relevant Posts
-
💡 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
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 35 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Valid Anagram Problem Insight: Given two strings, check if one is an anagram of the other. Approach: • First, check if the strings have the same length; if not, return false • Convert both strings to character arrays • Sort both arrays • Compare the sorted arrays — if equal, the strings are anagrams Time Complexity: • O(n log n) — due to sorting the arrays Space Complexity: • O(n) — for the character arrays Key Learnings: • Sorting is a simple and effective way to compare character compositions • Edge cases like different lengths should be handled first • Breaking the problem into small steps makes it easy to reason about Takeaway: Sometimes, sorting can reduce a seemingly complex problem into a simple comparison. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Strings
To view or add a comment, sign in
-
-
🚀 Day 48 of My #LeetCode Journey Today’s problem: 2615. Sum of Distances 💡 Key Idea: Instead of calculating distances between equal elements using brute force (O(n²)), I used: HashMap to group indices of same values Prefix Sum to efficiently compute distances This reduced the complexity to O(n) 🔥 🧠 What I Learned: How prefix sums can optimize distance calculations Efficient handling of repeated elements Writing clean and optimized code using Java ⚡ Approach: Store indices of each number Use prefix sums to calculate left & right distances Combine both to get final answer 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) Consistency is key. Small progress every day leads to big results 💪 #Day48 #Java #FullStackDeveloper #CodingJourney #100DaysOfCode #DSA #LeetCode
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
-
-
Some of the hardest problems become manageable once you recognize a repeating pattern. 🚀 Day 105/365 — DSA Challenge Solved: Subarrays with K Different Integers Problem idea: We need to count subarrays that contain exactly k distinct integers. Efficient approach: Use the powerful trick: subarrays with exactly k distinct = subarrays with ≤ k distinct − subarrays with ≤ (k − 1) distinct Steps: 1. Use a sliding window with a hashmap to track frequency of elements 2. Expand window by moving right pointer 3. If distinct count exceeds k, shrink window from the left 4. Count valid subarrays ending at each index 5. Subtract results to get exact count This pattern converts a hard problem into a manageable one. ⏱ Time: O(n) 📦 Space: O(n) Day 105/365 complete. 💻 260 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #SlidingWindow #HashMap #LeetCode #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 88 / 100 — LeetCode Challenge Solved: Find Minimum in Rotated Sorted Array 💡 Approach: Used Binary Search (O(log n)) to efficiently locate the minimum element in a rotated sorted array. Instead of scanning linearly, compared mid with high to decide the search direction. 🔍 Key Insight: If nums[mid] > nums[high] → minimum is in the right half Else → minimum is in the left half (including mid) ⚡ Performance: Runtime: 0 ms (Beats 100%) Memory: 43.92 MB 🧠 Learning: Understanding how sorted + rotated arrays behave helps reduce time complexity drastically from O(n) → O(log n) Consistency is key. 12 days to go 💯🔥 #Day88 #LeetCode #BinarySearch #Java #DSA #100DaysOfCode
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
-
-
Day 25/100: Finding the "Gap" 🎯 Today's challenge: Search Insert Position. We all know Binary Search finds an element in O(log n), but what if the element isn't there? I learned that by the end of the search, the `left` pointer doesn't just give up—it points exactly to where that missing number *should* be inserted to keep the array sorted. It’s a powerful way to handle dynamic data without breaking the order. Quarter of the way through the challenge! 🚀 #100DaysOfCode #Java #DSA #BinarySearch #ProblemSolving #Unit3 #Day25 #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 71/100 – LeetCode Challenge Solved: Remove Duplicates from Sorted List II (Medium) Today’s problem was a great test of Linked List manipulation and handling edge cases efficiently. 🔍 Key Insight: Since the list is sorted, duplicates appear consecutively. Instead of keeping one copy, the challenge is to remove all nodes with duplicate values, leaving only distinct elements. 💡 Approach: Used a dummy node to handle edge cases Applied two-pointer technique (prev & current) Skipped entire duplicate sequences in one pass ⚡ Result: Runtime: 0 ms (Beats 100%) Space Complexity: O(1) 🎯 Key Learning: Handling duplicates in linked lists requires careful pointer updates — especially when the head itself is part of duplicates. Consistency is key 🔥 #Day71 #LeetCode #100DaysOfCode #Java #DataStructures #LinkedList #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