𝗗𝗮𝘆 𝟱𝟵/𝟭𝟬𝟬 — 𝗢𝗻𝗲 𝗗𝗮𝘆 𝗧𝗼 𝟲𝟬 Day 59. One day away from another milestone. But today? Simple string manipulation. Two pointers. Classic reversal. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟮𝟬𝟬𝟬: Reverse Prefix of Word (Easy) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Given a word and a character, reverse the prefix up to the first occurrence of that character. Example: word = "abcdefd", ch = 'd' Result = "dcbaefd" (Reverse "abcd" → "dcba", keep "efd") 𝗧𝗵𝗲 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: Find the index. Two-pointer swap. Done. 👉 Find first occurrence of character 👉 If not found, return original word 👉 Two pointers: left = 0, right = index 👉 Swap characters while moving inward 👉 Return modified string Time: O(n), Space: O(n) for char array 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: Two-pointer reversal. Day 31 used it for linked lists. Day 59 uses it for strings. Same pattern. Different data structure. That's the power of understanding fundamentals—they transfer. 𝗖𝗼𝗱𝗲: https://lnkd.in/g7UXBf_u 59 down. 41 to go. Tomorrow = 60. 𝗗𝗮𝘆 𝟱𝟵/𝟭𝟬𝟬 ✅ #100DaysOfCode #LeetCode #Strings #TwoPointer #Algorithms #ProblemSolving #CodingInterview #Programming #Java #Fundamentals #Day60Tomorrow

To view or add a comment, sign in

Explore content categories