Order and position

Episode 6 Strings

1 h 4 min · Java · Quiz

Title card of Episode 6: Strings

▶ This video is coming to YouTube soon.

The complete guide to strings in Java interviews. First how strings really work: characters are numbers, a String can never change, why += in a loop is O(n²) and how a StringBuilder makes it O(n), what every common method costs, 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 String is stored, and what charAt, substring, equals and indexOf cost
  • Characters are numbers: c − 'a' for letter counts, c − '0' for digits
  • Immutability, why += in a loop is O(n²), and the StringBuilder toolbox
  • Counting letters with int[26], and two pointers from both ends
  • Mapping letters both ways, and a StringBuilder used as a stack
  • Adding huge numbers digit by digit, and counting words with a HashMap
  • 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:20What's a string?
  3. 1:07Characters are numbers
  4. 2:03Character codes worth knowing
  5. 2:40Strings can't change
  6. 3:19Why += in a loop is O(n²)
  7. 4:02StringBuilder: add in place
  8. 4:53The StringBuilder toolbox
  9. 5:49What String methods cost
  10. 6:22Five traps
  11. 7:04Nine string techniques
  12. 7:42Type 1 · Compress runs of letters
  13. 13:36Type 2 · First unique character
  14. 19:10Type 3 · Is it a palindrome?
  15. 24:48Type 4 · Same pattern?
  16. 30:28Type 5 · Remove adjacent duplicates
  17. 36:27Type 6 · Add two number strings
  18. 43:26Type 7 · Most common word
  19. 49:13Type 8 · Longest odd palindrome
  20. 55:33Type 9 · Find a word in a text
  21. 1:01:38Spot the technique
  22. 1:02:24Quiz: which technique?
  23. 1:03:11Recap

Quiz: test yourself

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