{
  "id": 176081,
  "title": "LeetCode #345 in Go: reverse vowels of a string, and how strings, bytes, and runes work in Go",
  "url": "https://urgent.news/2026/08/05/leetcode-345-in-go-reverse-vowels-of-a-string-and-how-strings-bytes",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-05T13:33:25.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/ferztyle/leetcode-345-in-go-reverse-vowels-of-a-string-and-how-strings-bytes-and-runes-work-in-go-5dng"
  },
  "original_language": "en",
  "account": "LeetCode challenge #345, titled \"Reverse Vowels of a String,\" presents an intriguing exercise in Go programming. The problem requires reversing only the vowels in a given input string, while preserving the positions of all consonants. A key aspect of Go that comes into play is the immutability of strings, which necessitates converting the string into a mutable data structure before performing any swaps.\n\nThe solution employs a two-pointer approach, with one pointer starting at the beginning of the string and the other at the end. Both pointers move inward, skipping any non-vowel characters, until they encounter vowels. Upon finding vowels at both pointers, the characters are swapped. This process continues until the pointers meet or cross each other.\n\nThe implementation hinges on accurately identifying vowels, regardless of case. A convenient approach is to use a lookup set or map containing both lowercase and uppercase vowels, enabling efficient checks. Another crucial consideration is whether to use []byte or []rune for string manipulation. In this case, a []byte array suffices since the problem deals exclusively with ASCII vowels.\n\nThe key steps in the algorithm are:\n1. Initialize two pointers, left at the start and right at the end of the string.\n2. Increment left until a vowel is found or left surpasses right.\n3. Decrement right until a vowel is found or right precedes left.\n4. If both pointers are on vowels, swap the characters.\n5. Move left one step right and right one step left, repeating from step 2 until left >= right.\n\nThis method ensures that only vowels are reversed, while consonants retain their original positions. The example input \"IceCream\" is transformed into \"AceCream\" through this process, with the vowels 'e', 'i', and 'e' being reversed to 'e', 'i', and 'e'. Another example, \"Aa\", demonstrates the importance of handling both uppercase and lowercase vowels, resulting in the output \"aA\".\n\nThe provided solution approach, rooted in the two-pointer collision pattern, elegantly addresses the challenge by only manipulating vowels and leaving consonants untouched. This technique not only solves the problem efficiently but also highlights the power of understanding the underlying data structures and their manipulation in Go.",
  "summary": "Why I started this series A while back, I went through a job interview that included a coding challenge. It looked pretty easy, so I finished in like 90 seconds, and all tests passed! Then, the (non-technical) interviewer said to me: Interviewer: Why did you choose Golang? Do you actually know how to code in Golang? Me: I said, yes, that challenge was easy, and all tests passed!. Interviewer:…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}