Hard Strings Interview Questions

In one of our final sections of the course, we'll study some hard string problems. Recall that strings are a sequence of characters, either as a literal constant or as some kind of variable, that can have its elements be mutated and length changed.

In this section, we'll study some problems that require a bit more thought than the previous ones. Some of them may involve multiple data structures, and some may involve some clever algorithms. We'll start with a problem that involves a bit of both.

Section Menu

How do I use this section?

1. CHALLENGE

Length of String Compression

Let's define the "compacting" of a string as taking an input like the following: 'sstttrrrr'. We want to take the number of sequential appearances (number of times it shows up in a row) of each letter: ` s: 2 t: 3 r: 4 ` And denote them next to the original character in the string, getting rid of the duplicates....

2. CHALLENGE

Generate All String Permutations

Write an algorithm that takes an input string like "abc", and prints out all possible permutations of the string. A permutation of a group of elements is defined as one of the n! number possible arrangements the elements can take, where n is the number of elements in the range. We'd expect the following to hold true, note...

3. CHALLENGE

String Breakdown

We're given a string and need to see if it can be broken down into words from a dictionary array. For example: `js const str = "applecomputer"; const dictArr = ["apple", "computer"]; stringBreakdown(str, dictArr); // true ` Assuming that there are no repeats in the dictionary array, can you write a method that will r...

4. CHALLENGE

Convert Number to Words

Can you convert a number to its text equivalent? This is otherwise known as number spelling. For example, given 1234, we expect to get "one thousand two hundred and thirty four" back....

5. CHALLENGE

Longest Palindromic Substring

We're given a string that's a mixture of several alphabetical characters. `js const str = "algototheehtotdaily"; ` Could you write a method to find the longest substring that is considered a palindrome? In the above example, it would be "totheehtot". Where there are multiple longest palindromic substrings of the sa...

6. CHALLENGE

Text Justification

Can you justify input text represented by an array of words so it looks pretty when printed and the whitespaces are balanced? For example, in the above image, we have an input array of `["wow", "s...

7. CHALLENGE

Longest Substring With No Duplicate Characters

Given a string of characters, can you find the longest substring of the string that has no repeating characters? An example is shown below: `js lengthOfLongestSubstring("abracadabar"); // 4 becau...

8. CHALLENGE

Remove Invalid Parentheses

Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid. Return all the possible results. image For example, consider the followi...

9. CHALLENGE

Valid Numeric String

Valid Numeric String You are working as a software engineer at a company that develops a financial trading platform. Your team is working on a new feature that allows users to enter numeric strings into a text field and have them parsed and converted into numbers. One of the requirements for this feature is that the numeric str...