Trie

Trie

Thirty questions on tries, for prefix matching, autocomplete, and word-search problems.

Count Prefix and Suffix Pairs I

easy
You are given a 0-indexed string array words.

Longest Common Prefix

easy
Write a function to find the longest common prefix string amongst an array of strings.

Maximum Strong Pair XOR I

easy
You are given a 0-indexed integer array nums.

Camelcase Matching

medium
Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.

Extra Characters in a String

medium
You are given a 0-indexed string s and a dictionary of words dictionary.

Find the Length of the Longest Common Prefix

medium
You are given two arrays with positive integers arr1 and arr2.

K Divisible Elements Subarrays

medium
Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p.

Lexicographical Numbers

medium
Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

Longest Word in Dictionary

medium
Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.

Maximum XOR of Two Numbers in an Array

medium
Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.

Minimum Number of Valid Strings to Form Target I

medium
You are given an array of strings words and a string target.

Number of Matching Subsequences

medium
Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.

Partition String

medium
Given a string s, partition it into unique segments according to the following procedure: Return an array of strings segments, where segments[i] is the ith segment created.

Remove Sub-Folders from the Filesystem

medium
Given a list of folders folder, return the folders after removing all sub-folders in those folders.

Replace Words

medium
In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative.

Search Suggestions System

medium
You are given an array of strings products and a string searchWord.

Short Encoding of Words

medium
A valid encoding of an array of words is any reference string s and array of indices indices such that: Given an array of words, return the length of the shortest reference string...

Shortest Uncommon Substring in an Array

medium
You are given an array arr of size n consisting of non-empty strings.

Top K Frequent Words

medium
Given an array of strings words and an integer k, return the k most frequent strings.

Word Break

medium
Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

Words Within Two Edits of Dictionary

medium
You are given two string arrays, queries and dictionary.

Concatenated Words

hard
Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.

Count Pairs With XOR in a Range

hard
Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.

Count Prefix and Suffix Pairs II

hard
You are given a 0-indexed string array words.

Delete Duplicate Folders in System

hard
Due to a bug, there are many duplicate folders in a file system.

Distinct Echo Substrings

hard
Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e.

K-th Smallest in Lexicographical Order

hard
Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].

Longest Common Prefix of K Strings After Removal

hard
You are given an array of strings words and an integer k.

Longest Common Suffix Queries

hard
You are given two arrays of strings wordsContainer and wordsQuery.

Maximum Genetic Difference Query

hard
There is a rooted tree consisting of n nodes numbered 0 to n - 1.