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
Implementing strStr() function in Java with sliding window technique
More Relevant Posts
-
Leetcode Question Number 1848: Minimum Distance to the Target Element. I solved an interesting problem on finding the minimum distance in an array using Java!(Leetcode Daily Challenge) Given an array, a target value, and a starting index, the task is to find the minimum distance between the start index and any occurrence of the target element. Approach I used: 1.Traverse the array 2.Check for target element 3.Calculate distance using Math.abs(start - i) 4.Track minimum using Math.min() #Leetcode #DSA #Leetcode1848 #Java #Leetcodedailychallenge
To view or add a comment, sign in
-
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 92 of #100DaysOfLeetCode 💻✅ Solved #739. Daily Temperatures problem in Java. Approach: • Used Monotonic Stack to track indices • Compared current temperature with stack top • Updated result when a warmer day was found • Stored indices for future comparisons Performance: ✓ Runtime: 60 ms (Beats 79.01% submissions) 🚀 ✓ Memory: 107.89 MB (Beats 17.53% submissions) Key Learning: ✓ Learned Monotonic Stack technique ✓ Improved handling of next greater element problems ✓ Strengthened stack-based problem solving Learning one problem every single day 🚀 #Java #LeetCode #DSA #Stack #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Solved LeetCode 17 – Letter Combinations of a Phone Number using backtracking in Java. Approach: Mapped each digit (2–9) to its corresponding characters using a simple array for O(1) access. Then used backtracking to build combinations digit by digit. For every digit: Pick each possible character Append → explore next digit → backtrack Key idea: Treat it like a tree of choices, where each level represents a digit and branches represent possible letters. Key learnings: Backtracking = build → explore → undo StringBuilder helps avoid unnecessary string creation Problems like this are about systematic exploration of choices Time Complexity: O(4^n * n) Space Complexity: O(n) recursion stack + output Consistent DSA practice is strengthening pattern recognition day by day. #Java #DSA #Backtracking #LeetCode #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 23 of #75DaysOfCode Solved: Equal Row and Column Pairs 🔹 Problem: Given an n x n matrix, count the number of pairs (ri, cj) such that row ri and column cj are exactly the same. 🔹 Approach: • Stored all rows in a HashMap with their frequency • Converted each column into a comparable string format • Matched columns with stored rows to count equal pairs 🔹 Key Learning: Using StringBuilder instead of String concatenation significantly improves performance due to immutability of Strings in Java. 🔹 Time Complexity: O(n²) 🔹 Takeaway: Smart use of HashMap + efficient string handling can simplify and optimize matrix-based problems. #Day22 #75DaysOfCode #Java #DSA #LeetCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 73 of #100DaysOfLeetCode 💻✅ Solved #389. Find the Difference problem in Java. Approach: • Initialized a variable to store the sum • Added ASCII values of all characters in string t • Subtracted ASCII values of all characters in string s • The remaining value represents the extra character • Converted the result back to character and returned it Performance: ✓ Runtime: 1 ms (Beats 99.89% submissions) 🚀 ✓ Memory: 42.77 MB (Beats 97.03% submissions) Key Learning: ✓ Practiced optimized string traversal using enhanced for-loop ✓ Reinforced understanding of ASCII-based solutions ✓ Learned how mathematical approaches can simplify problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Math #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 68 of #100DaysOfLeetCode 💻✅ Solved #977. Squares of a Sorted Array problem in Java. Approach: • Traversed the array and squared each element • Used Arrays.sort() to sort the squared values • Returned the sorted array as the result Performance: ✓ Runtime: 10 ms (Beats 37.38% submissions) ✓ Memory: 47.98 MB (Beats 18.78% submissions) Key Learning: ✓ Practiced array transformation and sorting ✓ Learned how squaring affects order in sorted arrays ✓ Understood the importance of optimizing from O(n log n) to O(n) using two pointers Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 48/100:-Odd String Difference Not every problem is about writing code — some are about seeing patterns clearly. 🧠 Today, I worked on the "Odd String Difference" problem using Java. 🔍 Instead of comparing strings directly, I learned to: • Convert each string into a difference array • Identify patterns between characters • Detect the one string that breaks the pattern 💡 Key takeaway: Breaking a problem into smaller transformations makes complex logic much easier to handle. ⚡ Result: Efficient solution with strong runtime and memory performance ✅ Step by step, improving not just coding — but the way I think. #Day48 #100DaysOfCode #DSA #Java #ProblemSolving #LeetCode #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 15 of #DSAwithEdSlash Solved: Bulb Switcher 💡 Today’s problem looked simple at first but had a really interesting mathematical insight behind it. Instead of simulating all the toggles, the key realization is that only perfect squares remain ON after all rounds. 💡 Key Takeaways: Importance of pattern recognition 🔍 Optimization using mathematical logic instead of brute force Counting perfect squares ≤ n gives the answer 📊 Result: ⚡ Optimized Time Complexity: O(√n) 💻 Efficient Java implementation Consistency is building confidence day by day 💪 #Day15 #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency #PlacementPrep
To view or add a comment, sign in
-
-
Day 87 of #100DaysOfLeetCode 💻✅ Solved #334. Increasing Triplet Subsequence problem in Java. Approach: • Used Greedy approach with two variables • Tracked smallest and second smallest values • Updated values while traversing array • Returned true when a valid triplet was found Performance: ✓ Runtime: 2 ms (Beats 99.30% submissions) 🚀 ✓ Memory: 122.40 MB (Beats 80.69% submissions) Key Learning: ✓ Learned efficient Greedy strategy for subsequences ✓ Improved tracking of minimum values dynamically ✓ Strengthened understanding of pattern detection in arrays Learning one problem every single day 🚀 #Java #LeetCode #DSA #Greedy #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
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