5String Algorithms
One of the most important skills any entrepreneur should learn is to program a computer. This is a critical skill if you want to start a tech startup, but a basic knowledge of code is useful even in traditional fields, because software is changing everything.
Redi Hoffman
In this chapter, you will learn how to solve some of the most common string-based technical interview questions. While you most likely won't have to find anagrams at your software engineering job, learning how to detect them teaches you to solve problems using concepts such as sorting, which you will have to do. Furthermore, other things you will learn in this chapter, such as modular arithmetic and list comprehensions, will be useful in your day-to-day programming.
Anagram Detection
Two strings are anagrams if they contain the same letters, but not necessarily in the same order (case does not matter). For example, Car and arc are anagrams. The key to determining whether two strings are anagrams is to sort them. If the sorted strings are the same, they are anagrams. Here is how to write an algorithm that determines whether two strings are anagrams:
Anagrams sometimes contain multiple words and include uppercase and lowercase letters, so you start ...
Get The Self-Taught Computer Scientist now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.