{"id":776,"date":"2026-10-05T17:00:00","date_gmt":"2026-10-05T11:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/"},"modified":"2026-11-29T01:29:39","modified_gmt":"2026-11-28T19:59:39","slug":"go-string-manipulation-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/","title":{"rendered":"Go String Manipulation Programs: Anagram, Duplicates, Windows"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go string manipulation means changing or analysing text in smart ways, such as finding anagrams, removing duplicate letters or compressing &#8220;aaabb&#8221; into &#8220;a3b2&#8221;. These problems are a step up from basic string programs, and they show up often in product company interviews. In this post, you will write fourteen string manipulation programs with their exact output, and then practice the tricky questions around them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should first finish our <a href=\"https:\/\/smitabharat.com\/blog\/go-string-programs\/\">Go string programs<\/a>, because we reuse runes, <code>strings.Builder<\/code> and frequency maps here. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-functions-beginners-guide\/\">Go functions guide<\/a> also helps, since every solution is a small function. All programs were tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Go String Manipulation?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go string manipulation is any program that builds a new string from an old one, or answers a question about its characters. Common tasks are reordering, filtering, counting and encoding text.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of it like editing a sentence on paper. You cannot erase ink, so you write a new, better copy. In Go, strings cannot be changed either, so every manipulation builds a fresh string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go String Manipulation Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Real apps clean and reshape text all day. For example, a search box ignores case and extra spaces, a chat app hides bad words and a URL shortener encodes IDs. These same skills appear in coding rounds as anagram, duplicate and window problems.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Interviews:<\/strong> anagram, first unique character and longest substring are top questions.<\/li>\n\n\n<li><strong>Clean data:<\/strong> remove spaces, symbols and duplicates before you save or compare text.<\/li>\n\n\n<li><strong>Speed thinking:<\/strong> many problems have a slow and a fast answer, and interviewers want the fast one.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go String Manipulation Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most Go string manipulation programs use one of three patterns. The diagram shows each one.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1-1024x640.png\" alt=\"Go string manipulation diagram showing count, filter and two pointer patterns\" class=\"wp-image-769\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Count characters with a map, filter them into a builder, or move two pointers across the text.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below matches each pattern to the problems in this post.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Pattern<\/th><th>Idea<\/th><th>Problems<\/th><\/tr><\/thead><tbody><tr><td>Count with a map<\/td><td>Store how often each rune appears<\/td><td>Anagram, first unique, word count<\/td><\/tr><tr><td>Filter into a builder<\/td><td>Keep only the runes you want<\/td><td>Remove duplicates, remove symbols<\/td><\/tr><tr><td>Two pointers or window<\/td><td>Move a start and end index<\/td><td>Longest substring, palindromes<\/td><\/tr><tr><td>Build piece by piece<\/td><td>Write runs or words one at a time<\/td><td>Compress, capitalise, Caesar cipher<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Counting Go String Manipulation Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go string manipulation programs count characters with a map or an array. We begin with a tiny counting program that needs only a loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Count How Many Times a Letter Appears<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This easy program counts one chosen letter in a word.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    word := \"banana\" \/\/ := creates a new variable and sets its value\n    target := 'a'    \/\/ single quotes make a rune (one character)\n    count := 0\n\n    \/\/ range gives each letter of the word, one at a time.\n    for _, letter := range word {\n        if letter == target {\n            count++ \/\/ found one more match\n        }\n    }\n    fmt.Printf(\"%c appears %d times in %s\\n\", target, count, word) \/\/ %c prints a rune as a letter\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>a appears 3 times in banana<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop looks at &#8220;b&#8221;, &#8220;a&#8221;, &#8220;n&#8221; and so on. Each time the letter equals <code>target<\/code>, the count goes up by one. So after the loop, <code>count<\/code> holds 3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Check if Two Strings are Anagrams<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Two words are anagrams if they use the same letters the same number of times, like &#8220;listen&#8221; and &#8220;silent&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ isAnagram reports whether both words use exactly the same letters.\nfunc isAnagram(first, second string) bool {\n    \/\/ Step 1: ignore upper and lower case.\n    first = strings.ToLower(first)\n    second = strings.ToLower(second)\n    if len(first) != len(second) {\n        return false\n    }\n\n    \/\/ Step 2: add one for every letter of the first word.\n    count := map[rune]int{} \/\/ a map from letter to how many we have\n    for _, letter := range first {\n        count[letter]++\n    }\n\n    \/\/ Step 3: take one away for every letter of the second word.\n    for _, letter := range second {\n        count[letter]--\n        if count[letter] &lt; 0 {\n            return false \/\/ second word has a letter the first one lacks\n        }\n    }\n    return true\n}\n\nfunc main() {\n    fmt.Println(isAnagram(\"Listen\", \"Silent\"))\n    fmt.Println(isAnagram(\"rat\", \"car\"))\n    fmt.Println(isAnagram(\"Dormitory\", \"dirtyroom\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true\nfalse\ntrue<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We add one for each letter in the first word and take one away for the second. If any count goes below zero, the words cannot match. This runs in O(n) time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: First Non-Repeating Character<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ firstUnique returns the first letter that appears only once.\n\/\/ The bool is false when there is no such letter.\nfunc firstUnique(text string) (rune, bool) {\n    \/\/ Step 1: count every letter.\n    count := map[rune]int{}\n    for _, letter := range text {\n        count[letter]++\n    }\n\n    \/\/ Step 2: walk the text again and return the first letter seen once.\n    for _, letter := range text {\n        if count[letter] == 1 {\n            return letter, true\n        }\n    }\n    return 0, false\n}\n\nfunc main() {\n    words := []string{\"swiss\", \"golang\", \"aabb\"}\n\n    for _, word := range words {\n        letter, ok := firstUnique(word) \/\/ ok is true if a letter was found\n        if ok {\n            fmt.Printf(\"%s -&gt; %c\\n\", word, letter)\n        } else {\n            fmt.Printf(\"%s -&gt; none\\n\", word)\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>swiss -&gt; w\ngolang -&gt; o\naabb -&gt; none<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first loop counts, and the second loop finds the first rune with a count of 1. We loop over the string again, not the map, because map order is random. When no letter is unique, <code>ok<\/code> is false and we print &#8220;none&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Word Frequency in a Sentence<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"maps\"\n    \"slices\"\n    \"strings\"\n)\n\nfunc main() {\n    text := \"go is fast and go is simple and go is fun\"\n    counts := map[string]int{}\n\n    \/\/ Fields splits the text into words at the spaces.\n    for _, word := range strings.Fields(text) {\n        counts[word]++\n    }\n\n    \/\/ maps.Keys gives every word, and slices.Sorted puts them in A to Z order.\n    sortedWords := slices.Sorted(maps.Keys(counts))\n\n    for _, word := range sortedWords {\n        fmt.Printf(\"%s=%d \", word, counts[word])\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>and=2 fast=1 fun=1 go=3 is=3 simple=1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Fields<\/code> gives us the words, and the map counts each one. Maps have no fixed order, so we sort the words before printing. That keeps the output the same on every run.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Filtering Go String Manipulation Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go string manipulation programs keep some characters and drop others.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Remove Duplicate Characters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We keep the first time each rune appears and skip later ones.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ removeDuplicates keeps only the first copy of every letter.\nfunc removeDuplicates(text string) string {\n    seen := map[rune]bool{}     \/\/ letters we have already written\n    var builder strings.Builder \/\/ collects the result piece by piece\n\n    for _, letter := range text {\n        if !seen[letter] { \/\/ ! means \"not\"; a missing key gives false\n            seen[letter] = true\n            builder.WriteRune(letter) \/\/ add this letter to the result\n        }\n    }\n    return builder.String()\n}\n\nfunc main() {\n    fmt.Println(removeDuplicates(\"programming\"))\n    fmt.Println(removeDuplicates(\"aabbccdd\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>progamin\nabcd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>seen<\/code> map remembers which runes we already wrote. Since we keep the first copy, the original order stays the same.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Remove Spaces and Special Characters<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"unicode\"\n)\n\n\/\/ keepLetterOrDigit returns the letter to keep it, or -1 to drop it.\nfunc keepLetterOrDigit(letter rune) rune {\n    if unicode.IsLetter(letter) || unicode.IsDigit(letter) {\n        return letter\n    }\n    return -1 \/\/ -1 tells strings.Map to drop this rune\n}\n\nfunc main() {\n    text := \"Hello, World! Go@2026 #rocks\"\n\n    \/\/ strings.Map calls keepLetterOrDigit for every rune in text.\n    clean := strings.Map(keepLetterOrDigit, text)\n    fmt.Println(clean)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>HelloWorldGo2026rocks<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Map<\/code> calls our function for every rune. Letters and digits come back unchanged, so they stay. Returning -1 tells it to drop that rune, which removes spaces and symbols.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Toggle the Case of Each Letter<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"unicode\"\n)\n\n\/\/ toggleCase turns a capital letter into a small one, and the other way round.\nfunc toggleCase(letter rune) rune {\n    if unicode.IsUpper(letter) {\n        return unicode.ToLower(letter)\n    }\n    return unicode.ToUpper(letter)\n}\n\nfunc main() {\n    text := \"GoLang Is FUN\"\n    toggled := strings.Map(toggleCase, text)\n    fmt.Println(toggled)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>gOlANG iS fun<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For each rune, <code>toggleCase<\/code> checks if it is a capital. Capitals become small letters, and everything else goes through <code>ToUpper<\/code>. Spaces have no case, so they stay as they are.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building Go String Manipulation Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These programs build a new string step by step, which is the heart of Go string manipulation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Make a URL Slug from a Title<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A slug is the friendly part of a web address, like &#8220;learn-go-fast&#8221;. This is a simple everyday example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ makeSlug turns a title into small words joined with dashes.\nfunc makeSlug(title string) string {\n    \/\/ Step 1: make every letter small.\n    lower := strings.ToLower(title)\n\n    \/\/ Step 2: split into words, which also drops extra spaces.\n    words := strings.Fields(lower)\n\n    \/\/ Step 3: join the words with a dash between them.\n    return strings.Join(words, \"-\")\n}\n\nfunc main() {\n    fmt.Println(makeSlug(\"Learn Go Fast\"))\n    fmt.Println(makeSlug(\"  Go String   Manipulation \"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>learn-go-fast\ngo-string-manipulation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>ToLower<\/code> makes the whole title small. Then <code>Fields<\/code> splits it into words and throws away extra spaces. Finally, <code>Join<\/code> puts the words back together with dashes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Capitalise Each Word<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"unicode\"\n)\n\n\/\/ capitalise makes the first letter of every word a capital.\nfunc capitalise(sentence string) string {\n    words := strings.Fields(sentence)\n\n    for i, word := range words {\n        letters := []rune(word)                   \/\/ a changeable list of characters\n        letters[0] = unicode.ToUpper(letters[0]) \/\/ change only the first letter\n        words[i] = string(letters)               \/\/ put the new word back\n    }\n    return strings.Join(words, \" \")\n}\n\nfunc main() {\n    fmt.Println(capitalise(\"learn go one   program at a time\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Learn Go One Program At A Time<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Fields<\/code> also cleans up the extra spaces. Then we change only the first rune of each word. <code>Join<\/code> adds single spaces back between the words.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Compress a String (Run-Length Encoding)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;aaabbc&#8221; becomes &#8220;a3b2c1&#8221;. We count each run of the same character.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n    \"strings\"\n)\n\n\/\/ compress writes each letter followed by how many times it repeats in a row.\nfunc compress(text string) string {\n    letters := []rune(text)\n    var builder strings.Builder\n    start := 0\n\n    for start &lt; len(letters) {\n        \/\/ Step 1: move end forward while the letter stays the same.\n        end := start\n        for end &lt; len(letters) &amp;&amp; letters[end] == letters[start] {\n            end++\n        }\n\n        \/\/ Step 2: write the letter and the length of its run.\n        runLength := end - start\n        builder.WriteRune(letters[start])\n        builder.WriteString(strconv.Itoa(runLength)) \/\/ Itoa turns a number into text\n\n        \/\/ Step 3: the next run starts where this one ended.\n        start = end\n    }\n    return builder.String()\n}\n\nfunc main() {\n    fmt.Println(compress(\"aaabbc\"))\n    fmt.Println(compress(\"wwwwaaadexxxxxx\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>a3b2c1\nw4a3d1e1x6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The inner loop moves <code>end<\/code> to the end of the run. Then <code>end - start<\/code> is the length of that run. After writing it, <code>start<\/code> jumps to <code>end<\/code>, and the next run begins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Caesar Cipher<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A Caesar cipher shifts each letter by a fixed number. With a shift of 3, &#8220;a&#8221; becomes &#8220;d&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ shiftLetter moves one letter forward by shift places, wrapping after \"z\".\nfunc shiftLetter(letter rune, shift int) rune {\n    if letter &gt;= 'a' &amp;&amp; letter &lt;= 'z' {\n        position := letter - 'a' \/\/ 0 for \"a\", 1 for \"b\", and so on\n        return 'a' + (position+rune(shift)+26)%26\n    }\n    if letter &gt;= 'A' &amp;&amp; letter &lt;= 'Z' {\n        position := letter - 'A'\n        return 'A' + (position+rune(shift)+26)%26\n    }\n    return letter \/\/ spaces and symbols stay the same\n}\n\n\/\/ caesar shifts every letter in the text.\nfunc caesar(text string, shift int) string {\n    var builder strings.Builder\n    for _, letter := range text {\n        builder.WriteRune(shiftLetter(letter, shift))\n    }\n    return builder.String()\n}\n\nfunc main() {\n    secret := caesar(\"Hello, Go!\", 3)\n    fmt.Println(secret)\n    fmt.Println(caesar(secret, -3)) \/\/ shifting back gives the original\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Khoor, Jr!\nHello, Go!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>shiftLetter<\/code> turns the letter into a position from 0 to 25 and adds the shift. <code>% 26<\/code> wraps &#8220;z&#8221; back to &#8220;a&#8221;. Adding 26 first keeps the result positive when we shift backwards.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Window and Pointer Go String Manipulation Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These problems move indexes across the string, which is faster than checking every pair.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Longest Substring Without Repeating Characters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is a famous sliding window problem.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ longestUnique finds the longest part of text with no repeated letters.\nfunc longestUnique(text string) (int, string) {\n    lastSeen := map[rune]int{} \/\/ letter -&gt; the last index where we saw it\n    letters := []rune(text)\n    windowStart := 0\n    bestLength := 0\n    bestStart := 0\n\n    for i, letter := range letters {\n        \/\/ Step 1: if this letter is already inside the window, move the start past it.\n        position, found := lastSeen[letter]\n        if found &amp;&amp; position &gt;= windowStart {\n            windowStart = position + 1\n        }\n        lastSeen[letter] = i\n\n        \/\/ Step 2: remember the window if it is the longest so far.\n        windowLength := i - windowStart + 1\n        if windowLength &gt; bestLength {\n            bestLength = windowLength\n            bestStart = windowStart\n        }\n    }\n    return bestLength, string(letters[bestStart : bestStart+bestLength]) \/\/ slice from bestStart\n}\n\nfunc main() {\n    for _, text := range []string{\"abcabcbb\", \"bbbbb\", \"pwwkew\"} {\n        length, part := longestUnique(text)\n        fmt.Println(text, length, part)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>abcabcbb 3 abc\nbbbbb 1 b\npwwkew 3 wke<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>windowStart<\/code> marks the left edge of the window. When we see a repeat inside the window, we move it just past the last position of that letter. So the window always holds unique runes, and we keep the longest one we saw.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: Check if One String is a Rotation of Another<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;waterbottle&#8221; rotated is &#8220;erbottlewat&#8221;. A rotation always appears inside the string joined to itself.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ isRotation reports whether second is first with some letters moved from front to back.\nfunc isRotation(first, second string) bool {\n    if len(first) != len(second) {\n        return false\n    }\n    doubled := first + first \/\/ \"golang\" becomes \"golanggolang\"\n    return strings.Contains(doubled, second)\n}\n\nfunc main() {\n    fmt.Println(isRotation(\"waterbottle\", \"erbottlewat\"))\n    fmt.Println(isRotation(\"golang\", \"langgo\"))\n    fmt.Println(isRotation(\"golang\", \"gonalg\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true\ntrue\nfalse<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Doubling &#8220;golang&#8221; gives &#8220;golanggolang&#8221;, and every rotation hides inside it. So &#8220;langgo&#8221; is found, but &#8220;gonalg&#8221; is not. The length check stops shorter strings from matching by mistake.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: All Permutations of a Short String<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ permutations returns every order of the letters in a short ASCII word.\nfunc permutations(word string) []string {\n    \/\/ A word with 0 or 1 letters has only one order: itself.\n    if len(word) &lt;= 1 {\n        return []string{word}\n    }\n\n    var result []string\n    for i := 0; i &lt; len(word); i++ {\n        \/\/ Step 1: pick the letter at i to go first.\n        first := word[i : i+1]\n        \/\/ Step 2: the rest is every letter except the one at i.\n        rest := word[:i] + word[i+1:]\n        \/\/ Step 3: put the picked letter in front of every order of the rest.\n        for _, ending := range permutations(rest) {\n            result = append(result, first+ending)\n        }\n    }\n    return result\n}\n\nfunc main() {\n    result := permutations(\"abc\")\n    fmt.Println(result, len(result))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[abc acb bac bca cab cba] 6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each call picks one letter for the first position and calls itself on the rest. This is called recursion. A string of n unique letters has n! permutations, so only use this for short strings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Map Counting vs Sorting in Go String Manipulation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Anagram checks can be done by counting or by sorting. The diagram and table below compare the two.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2-1024x640.png\" alt=\"Go string manipulation comparison of map counting and sorting for anagrams\" class=\"wp-image-770\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Counting with a map is faster, while sorting is shorter to write and easy to explain.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Count with a map<\/th><th>Sort both strings<\/th><\/tr><\/thead><tbody><tr><td>Time<\/td><td>O(n)<\/td><td>O(n log n)<\/td><\/tr><tr><td>Extra memory<\/td><td>One map<\/td><td>Two rune slices<\/td><\/tr><tr><td>Code length<\/td><td>Medium<\/td><td>Short<\/td><\/tr><tr><td>Works with Unicode<\/td><td>Yes<\/td><td>Yes, with []rune<\/td><\/tr><tr><td>Best for<\/td><td>Long text, interviews<\/td><td>Quick scripts<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use counting when speed matters, and sorting when you want the shortest clear code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Solve Go String Manipulation Problems in an Interview<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers care about how you think, not just the final code. So use the same five steps for every Go string manipulation question.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Ask about the input<\/strong>: Can it be empty? Is it only lower case letters, or any Unicode text?<\/li>\n\n\n<li><strong>Give a simple answer first<\/strong>, such as checking every pair, and say its time cost.<\/li>\n\n\n<li><strong>Pick a better pattern<\/strong>, like counting with a map or a sliding window.<\/li>\n\n\n<li><strong>Write the code as a small function<\/strong> that returns a value.<\/li>\n\n\n<li><strong>Test it aloud<\/strong> with an empty string, one letter and a normal example.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For example, for &#8220;first non-repeating character&#8221;, the simple answer checks each letter against all others, which is O(n squared). Then you improve it to two passes with a map, which is O(n). This step from slow to fast is exactly what the interviewer wants to hear.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go String Manipulation<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Working with bytes:<\/strong> indexing <code>s[i]<\/code> breaks non-ASCII letters, so convert to <code>[]rune<\/code> first.<\/li>\n\n\n<li><strong>Looping over a map for order:<\/strong> map order is random, so loop over the string again.<\/li>\n\n\n<li><strong>Forgetting case:<\/strong> &#8220;Listen&#8221; and &#8220;silent&#8221; fail without <code>strings.ToLower<\/code>.<\/li>\n\n\n<li><strong>Slow joins:<\/strong> using <code>+=<\/code> in a loop is slow, so use <code>strings.Builder<\/code>.<\/li>\n\n\n<li><strong>Ignoring empty input:<\/strong> decide what an empty string should return before you start.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go String Manipulation<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pick the pattern first<\/strong>: count, filter, window or build.<\/li>\n\n\n<li><strong>Use strings.Map<\/strong> for one-to-one rune changes, since it is short and clear.<\/li>\n\n\n<li><strong>Return values from functions<\/strong>, so each program is easy to test.<\/li>\n\n\n<li><strong>Test with tricky input<\/strong>, such as empty strings, one letter and Unicode text.<\/li>\n\n\n<li><strong>Explain time complexity<\/strong>, because interviewers always ask about it.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go String Manipulation Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go string manipulation questions build on the programs above. Each answer has real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pattern Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What is the time complexity of the map-based anagram check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is O(n), because we pass over each string once. The map holds at most one entry per unique character.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. How do you check an anagram by sorting?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"slices\"\n    \"strings\"\n)\n\n\/\/ sortedRunes returns the letters of the word in A to Z order.\nfunc sortedRunes(word string) string {\n    letters := []rune(strings.ToLower(word))\n    slices.Sort(letters) \/\/ sorts the slice in place\n    return string(letters)\n}\n\nfunc main() {\n    fmt.Println(sortedRunes(\"Listen\"), sortedRunes(\"Silent\"))\n    fmt.Println(sortedRunes(\"Listen\") == sortedRunes(\"Silent\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>eilnst eilnst\ntrue<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Sorting puts the letters of both words in the same order. If the two sorted strings are equal, the words are anagrams.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ isSeparator reports whether the rune is a comma, semicolon or space.\nfunc isSeparator(letter rune) bool {\n    return letter == ',' || letter == ';' || letter == ' '\n}\n\nfunc main() {\n    text := \"a,b;c d\"\n    parts := strings.FieldsFunc(text, isSeparator)\n    fmt.Printf(\"%q\\n\", parts) \/\/ %q shows each part in quotes\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[\"a\" \"b\" \"c\" \"d\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>FieldsFunc<\/code> splits wherever your function returns true. It is handy when text has more than one kind of separator.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. How do you count characters faster than with a map?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For plain lower case letters, use an array like <code>var count [26]int<\/code> and index it with <code>r - 'a'<\/code>. Arrays are faster than maps, but they only work when you know the character set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    var count [26]int \/\/ 26 boxes, one per letter, all starting at 0\n\n    for _, letter := range \"banana\" {\n        count[letter-'a']++ \/\/ \"a\" goes in box 0, \"b\" in box 1, and so on\n    }\n    fmt.Println(count[0], count[1], count['n'-'a'])\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3 1 2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Index 0 is &#8220;a&#8221;, index 1 is &#8220;b&#8221;, and <code>'n' - 'a'<\/code> is the index for &#8220;n&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Output Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ nextLetter moves a rune one step forward, so \"H\" becomes \"I\".\nfunc nextLetter(letter rune) rune {\n    return letter + 1\n}\n\nfunc main() {\n    word := \"Go\"\n    fmt.Println(strings.Repeat(word, 0) == \"\", strings.ToUpper(word+word))\n    fmt.Println(strings.Map(nextLetter, \"HAL\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true GOGO\nIBM<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Repeating a string 0 times gives an empty string, so the first check is true. Each letter of &#8220;HAL&#8221; moves forward by one, which gives &#8220;IBM&#8221;. This is a well-known little joke among programmers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    fmt.Println(strings.Count(\"cheese\", \"e\"))\n    fmt.Println(strings.Count(\"five\", \"\"))\n    fmt.Println(strings.Count(\"aaaa\", \"aa\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3\n5\n2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">An empty search string matches at every position plus one, so &#8220;five&#8221; gives 5. Also, <code>Count<\/code> does not overlap matches, so &#8220;aaaa&#8221; holds &#8220;aa&#8221; twice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    \/\/ Each pair is \"old\", \"new\": &lt; becomes &amp;lt; and &gt; becomes &amp;gt;\n    replacer := strings.NewReplacer(\"&lt;\", \"&amp;lt;\", \"&gt;\", \"&amp;gt;\")\n    fmt.Println(replacer.Replace(\"&lt;b&gt;Go&lt;\/b&gt;\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&amp;lt;b&amp;gt;Go&amp;lt;\/b&amp;gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.NewReplacer<\/code> swaps many pairs in a single pass. It is faster than calling <code>ReplaceAll<\/code> several times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. How do you reverse the words in a sentence?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"slices\"\n    \"strings\"\n)\n\nfunc main() {\n    words := strings.Fields(\"Go is really fun\")\n    slices.Reverse(words) \/\/ flips the order of the words\n    fmt.Println(strings.Join(words, \" \"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>fun really is Go<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>slices.Reverse<\/code> flips the slice in place. Then <code>Join<\/code> puts the words back together with spaces.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    \/\/ Cut gives the part before \"@\", the part after it, and whether \"@\" was found.\n    before, after, found := strings.Cut(\"user@example.com\", \"@\")\n    fmt.Println(before, after, found)\n\n    \/\/ _ throws away values we do not need.\n    _, _, found = strings.Cut(\"no-at-sign\", \"@\")\n    fmt.Println(found)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>user example.com true\nfalse<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Cut<\/code> splits a string at the first match and tells you if it found one. It is cleaner than using <code>Index<\/code> and slicing by hand.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. How do you check if a string has all unique characters?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Put each rune in a <code>map[rune]bool<\/code>. If a rune is already in the map, return false. Without extra memory, you could sort the runes and compare neighbours.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    text := \"hello world\"\n\n    byteIndex := strings.IndexByte(text, 'o') \/\/ first \"o\"\n    runeIndex := strings.IndexRune(text, 'w') \/\/ first \"w\"\n    anyIndex := strings.IndexAny(text, \"xyzw\") \/\/ first of x, y, z or w\n\n    fmt.Println(byteIndex, runeIndex, anyIndex)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4 6 6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All three return the byte position of the first match. <code>IndexAny<\/code> looks for any one of the given characters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Grouping anagrams is a classic Go string manipulation task. Write a function that groups words that are anagrams of each other, such as &#8220;eat&#8221;, &#8220;tea&#8221; and &#8220;ate&#8221;. Print each group on one line. Hint: use the sorted letters of each word as a map key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/strings\">strings package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/unicode\">unicode package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/slices\">slices package documentation<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go string manipulation always builds new strings, because strings cannot change.<\/li>\n\n\n<li>Count with a map for anagrams, first unique characters and word frequency.<\/li>\n\n\n<li>Filter with <code>strings.Map<\/code> or a <code>strings.Builder<\/code> to remove or change runes.<\/li>\n\n\n<li>Use a sliding window for longest substring problems.<\/li>\n\n\n<li>Always test empty strings, single letters and Unicode text.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we move from text to fixed lists. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-array-programs\/\">Go array programs with output<\/a>, where we find the largest, second largest and reverse an array. For the theory first, see <a href=\"https:\/\/smitabharat.com\/blog\/go-slices-arrays-explained\/\">Go slices and arrays explained<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go string manipulation means changing or analysing text in smart ways, such as finding anagrams, removing duplicate letters or compressing &#8220;aaabb&#8221; into &#8220;a3b2&#8221;. These&hellip;<\/p>\n","protected":false},"author":1,"featured_media":771,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,95,11,104,47],"swapz_series":[],"class_list":["post-776","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-programs","tag-go-strings"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go String Manipulation: Anagram and Duplicates<\/title>\n<meta name=\"description\" content=\"Go string manipulation programs with output: anagram, remove duplicates, first unique character, compress, longest substring and interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go String Manipulation: Anagram and Duplicates\" \/>\n<meta property=\"og:description\" content=\"Go string manipulation programs with output: anagram, remove duplicates, first unique character, compress, longest substring and interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T11:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go String Manipulation Programs: Anagram, Duplicates, Windows\",\"datePublished\":\"2026-10-05T11:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/\"},\"wordCount\":1966,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-manipulation-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\",\"Go Strings\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/\",\"name\":\"Go String Manipulation: Anagram and Duplicates\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-manipulation-programs-featured.png\",\"datePublished\":\"2026-10-05T11:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:39+00:00\",\"description\":\"Go string manipulation programs with output: anagram, remove duplicates, first unique character, compress, longest substring and interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-manipulation-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-string-manipulation-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go String Manipulation featured image: anagram, duplicates and compress output\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-string-manipulation-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go String Manipulation Programs: Anagram, Duplicates, Windows\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go String Manipulation: Anagram and Duplicates","description":"Go string manipulation programs with output: anagram, remove duplicates, first unique character, compress, longest substring and interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go String Manipulation: Anagram and Duplicates","og_description":"Go string manipulation programs with output: anagram, remove duplicates, first unique character, compress, longest substring and interview questions.","og_url":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-05T11:30:00+00:00","article_modified_time":"2026-11-28T19:59:39+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go String Manipulation Programs: Anagram, Duplicates, Windows","datePublished":"2026-10-05T11:30:00+00:00","dateModified":"2026-11-28T19:59:39+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/"},"wordCount":1966,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Programs","Go Strings"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/","name":"Go String Manipulation: Anagram and Duplicates","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-featured.png","datePublished":"2026-10-05T11:30:00+00:00","dateModified":"2026-11-28T19:59:39+00:00","description":"Go string manipulation programs with output: anagram, remove duplicates, first unique character, compress, longest substring and interview questions.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-string-manipulation-programs-featured.png","width":2400,"height":1260,"caption":"Go String Manipulation featured image: anagram, duplicates and compress output"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-string-manipulation-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go String Manipulation Programs: Anagram, Duplicates, Windows"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=776"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/776\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/776\/revisions\/878"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/771"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=776"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}