Strings and tries interview questions
Prefix trees for lookups and suggestions, expanding around centres, linear-time pattern search, and what Python strings cost.
– interview-ready · 10 questions in this topic
– of 10 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- How many words start with a given prefix?Predict
- Longest stretch that reads the same backwardsPredict
- First place a pattern appears in a textPredict
- Top three suggestions as you typePredict
- Look up words where '.' stands for any letterPredict
- Count the stretches that read the same backwardsPredict
- Longest start shared by every wordPredict
- What Python string operations costPredict
- Trie or hash set?Pick the fix
- Rolling hashes for pattern searchPredict
Practise this topic
Flashcards · 20
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 10 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 2 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
Strings are immutable
Python
strobjects never change;s += tbuilds a new string, so a loop of n appends can cost O(n²).str.join"".join(parts)computes the total length once and copies each part once: O(total length).str.startswithwith a tuples.startswith(("http://", "https://"))tests several prefixes in one call.str.findandintext.find(p)returns the first index or -1; CPython uses a fast search that is usually linear in practice.Kotlin
StringBuilderIn Kotlin, build strings in loops with
buildString { append(...) }or aStringBuilder.
Printable cheat sheet · Review your weak spots in this topic
Share your progress
Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license