Strings interview questions
Practice 28 questions on strings. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
28 questions
- EASY
Roman to Integer
Convert a Roman numeral string to its integer value, handling subtractive pairs like IV and IX.
15 minAlgorithmsAmazon · Microsoft · Adobe - EASY
String.prototype.padStart
Implement String.prototype.padStart — pad a string to a target length on the left, truncating a multi-char pad.
15 minJavaScript - EASY
String.prototype.repeat
Implement String.prototype.repeat — join a string n times, throwing RangeError on a negative or infinite count.
15 minJavaScript - EASY
String.prototype.trim
Implement String.prototype.trim — strip leading and trailing whitespace, including Unicode whitespace, from a string.
15 minJavaScript - MEDIUM
Base Converter
PREMIUMConvert a number's string representation between any two bases from 2 to 36 — parse the digits in the source base, then re-emit them in the target base.
25 minJavaScript - MEDIUM
BigInt String Arithmetic
PREMIUMAdd and multiply arbitrarily large non-negative integers given as decimal strings, using digit-by-digit schoolbook arithmetic with carries.
25 minJavaScript - MEDIUM
Caesar Cipher / ROT13
Shift each letter by a fixed amount with wraparound, preserving case and passing non-letters through — with ROT13 as the self-inverse case.
25 minJavaScript - MEDIUM
Case Converters
Convert any string between camelCase, snake_case, kebab-case, and PascalCase by tokenizing it into words first.
35 minJavaScript - MEDIUM
Edit Distance
PREMIUMCompute the minimum number of insertions, deletions, and replacements to turn one string into another — the Levenshtein distance via a 2D dynamic-programming table.
25 minAlgorithms - MEDIUM
Excel Column ↔ Number
Convert between Excel column titles and numbers in both directions — A is 1, Z is 26, AA is 27 — the classic bijective base-26 system with no zero digit.
25 minJavaScript - MEDIUM
Generate Parentheses
Generate every well-formed combination of n pairs of parentheses by backtracking — add an open bracket while any remain, and a close bracket only while it stays balanced.
25 minAlgorithms - MEDIUM
IPv4 / IPv6 Validate
Validate IPv4 dotted-quad and IPv6 addresses, handling octet ranges, leading zeros, and :: zero-group compression.
25 minJavaScript - MEDIUM
Longest Repeating Substring After Replacements
Implement a function that finds the longest substring made of one repeated character allowing up to k swaps.
25 minAlgorithmsGoogle · Amazon · Meta - MEDIUM
Palindrome Partitioning
Split a string every possible way so that each piece is a palindrome — backtrack over cut positions, extending a piece only while it reads the same both ways.
25 minAlgorithms - MEDIUM
Phone Letter Combinations
List every letter string a phone number could spell, mapping each digit to its keypad letters and backtracking through the choices.
25 minAlgorithms - MEDIUM
Roman Numerals ↔ Integer
Convert between Roman numerals and integers in both directions, handling subtractive notation like IV, IX, and XL.
25 minJavaScript - MEDIUM
Run-Length Encoding
Implement run-length encoding: compress runs of repeated characters into count+char pairs, and decode them back.
25 minJavaScript - MEDIUM
Segment Words
Implement a function that decides whether a string can be broken into a sequence of words from a given dictionary.
25 minAlgorithmsAmazon · Google · Meta - MEDIUM
Semver Compare
PREMIUMParse and compare two semantic version strings — major, minor, patch, and prerelease — returning -1, 0, or 1 with correct prerelease precedence.
25 minJavaScript - MEDIUM
Slugify
Turn a string into a URL-safe slug: lowercase, strip accents, and collapse non-alphanumeric runs into single hyphens.
25 minJavaScript - MEDIUM
String replaceAll / matchAll
Implement replaceAll and matchAll — replace every occurrence of a substring or global pattern, and iterate every match with its capture groups.
35 minJavaScript - MEDIUM
String to Number (parseInt)
Reimplement JavaScript's parseInt — skip leading whitespace, read an optional sign and radix prefix, consume valid digits for the base, and stop at the first invalid character.
25 minJavaScript - MEDIUM
Thousands Separator
Group a number's integer digits with separators — 1234567 to 1,234,567 — handling decimals, negatives, and a custom separator.
25 minJavaScript - MEDIUM
Trie (Prefix Tree)
PREMIUMImplement a Trie data structure supporting insert, exact word search, and prefix lookup operations.
25 minAlgorithms - MEDIUM
Truncate String
Implement lodash truncate — cut a string to a maximum length, append an ellipsis, and optionally break on the last word boundary before the limit.
25 minJavaScript - MEDIUM
URLSearchParams
Implement a URLSearchParams-style class with get, getAll, append, set, and toString over an encoded query string.
25 minJavaScript - HARD
Integer to English Words
PREMIUMSpell out a non-negative integer in English words — break it into groups of three digits and name each group with its scale word.
40 minJavaScript - HARD
Wildcard Matching
PREMIUMDecide whether a string matches a pattern containing `?` (any single character) and `*` (any sequence) — a two-dimensional dynamic-programming match over string and pattern.
40 minAlgorithms