Visualized DSA Strategies

Episode 6 Strings

1 h 10 min · Go · Quiz

Title card of Episode 6: Strings

▶ This video is coming to YouTube soon.

The complete guide to strings in Go interviews. First how Go strings really work: a string is a read-only row of bytes, characters are numbers (bytes and runes), why += in a loop is O(n²) and how a strings.Builder or a byte slice makes it O(n), what every common operation costs (a slice shares memory, []byte(s) copies), and five traps that catch everyone. Then nine techniques, each worked as a small problem in full: examples, the brute force animated beside the running line of code, the complete code, every line explained, and the better solution the same way.

What you'll learn

  • How a Go string is stored, and what len, s[i], slicing, == and strings.Index cost
  • Characters are numbers: bytes and runes, c − 'a' for letter counts, c − '0' for digits
  • Immutability, why += in a loop is O(n²), and the strings.Builder and []byte toolbox
  • Counting letters with a [26]int array, and two pointers from both ends
  • Mapping letters both ways, and a byte slice used as a stack
  • Adding huge numbers digit by digit, and counting words with strings.Fields and a map
  • Expanding palindromes from their centre
  • Finding a pattern with a rolling hash (the idea behind Rabin–Karp)
  • How to spot which technique a problem wants

Chapters

  1. 0:00Intro
  2. 0:22What's a string?
  3. 1:23Characters are numbers
  4. 2:28Character codes worth knowing
  5. 3:09Strings can't change
  6. 3:59Why += in a loop is O(n²)
  7. 5:03strings.Builder: write in place
  8. 6:01The strings.Builder and []byte toolbox
  9. 7:35What string operations cost
  10. 8:20Five traps
  11. 9:20Nine string techniques
  12. 10:00Type 1 · Compress runs of letters
  13. 16:28Type 2 · First unique character
  14. 22:20Type 3 · Is it a palindrome?
  15. 28:22Type 4 · Same pattern?
  16. 34:19Type 5 · Remove adjacent duplicates
  17. 40:51Type 6 · Add two number strings
  18. 48:53Type 7 · Most common word
  19. 54:59Type 8 · Longest odd palindrome
  20. 1:01:40Type 9 · Find a word in a text
  21. 1:08:05Spot the technique
  22. 1:08:56Quiz: which technique?
  23. 1:09:44Recap

Quiz: test yourself

The 5 questions from the end of the episode. Pick an answer to see why it's right.