Rushil Sharma’s Post

View profile for Rushil Sharma, graphic

CS Freshman | Full Stack Developer | MERN Stack | JUIT

🚀 𝗗𝗮𝘆 𝟳: Just solved LeetCode Problem 28: a string challenge to find the 𝗜𝗻𝗱𝗲𝘅 𝗼𝗳 𝗮 𝗦𝘂𝗯𝘀𝘁𝗿𝗶𝗻𝗴’𝘀 𝗙𝗶𝗿𝘀𝘁 𝗢𝗰𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝗲 in a larger string! 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given two strings 𝗻𝗲𝗲𝗱𝗹𝗲 and 𝗵𝗮𝘆𝘀𝘁𝗮𝗰𝗸, return the index of the first occurrence of needle in haystack, or -𝟭 if needle is not part of haystack. The task was to locate where one string (the needle) first appears in another string (the haystack). I used a straightforward iteration with the 𝘀𝘂𝗯𝗦𝘁𝗿() method to extract slices of the haystack string matching the length of the needle. Each slice was compared to the needle to check for a match, allowing me to efficiently locate the index of the first occurrence. If no match was found, the function returned -𝟭 as specified by the problem. 📍 Excited to continue tackling more problems and sharpening my skills one challenge at a time. Onward to the next! #LeetCode #CodingJourney #DataStructures #Algorithms #Cpp #DSA #FindingIndex #FirstOccurance #Programming #DailyLearning #Developer #ProblemSolving

  • No alternative text description for this image

To view or add a comment, sign in

Explore topics