6.4. Summary

Programmers use strings and arrays all the time, so it's not surprising to see problems about them showing up in a programming interview. A string can even be thought of as an array of characters — and if not actually implemented that way, there's usually an easy way to convert it to an array and back.

Arrays are not treated identically in all languages. All languages support static arrays, but few offer native support for dynamic arrays. C++ and C don't do any bounds checking of array access, whereas Java and C# do.

String manipulation is so fundamental that it's normally handled via built-in library routines or system classes. Languages like C# and Java consider strings to be immutable, making changes to a string nontrivial and requiring the use of special mutable string classes. If you're not careful, string manipulation can greatly degrade the performance of your algorithms.

You should know how to convert a string to an array of characters and back for each language you're using, because your answers to many interview problems will require such conversions.

Get Programming Interviews Exposed: Secrets to Landing Your Next Job, Second Edition 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.