Order and position
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
- 0:00Intro
- 0:20What's a string?
- 1:07Characters are numbers
- 2:03Character codes worth knowing
- 2:40Strings can't change
- 3:19Why += in a loop is O(n²)
- 4:02StringBuilder: add in place
- 4:53The StringBuilder toolbox
- 5:49What String methods cost
- 6:22Five traps
- 7:04Nine string techniques
- 7:42Type 1 · Compress runs of letters
- 13:36Type 2 · First unique character
- 19:10Type 3 · Is it a palindrome?
- 24:48Type 4 · Same pattern?
- 30:28Type 5 · Remove adjacent duplicates
- 36:27Type 6 · Add two number strings
- 43:26Type 7 · Most common word
- 49:13Type 8 · Longest odd palindrome
- 55:33Type 9 · Find a word in a text
- 1:01:38Spot the technique
- 1:02:24Quiz: which technique?
- 1:03:11Recap
Quiz: test yourself
The 5 questions from the end of the episode. Pick an answer to see why it's right.