Interview questions
Find a company or topic. Read the sources, then practice.
Loading the question library…
Find a company or topic. Read the sources, then practice.
Loading the question library…
Showing 1,901–1,925
Count the number of substrings of s that start and end with character c: simply count k = occurrences of c and return k*(k+1)/2 (choose…
General practice
Count the substrings of word1 whose character counts dominate the counts of word2 (i.e., the substring can be rearranged so word2 appears as its prefix)…
General practice
Count the substrings of word1 that can be rearranged so word2 appears as a prefix — equivalently, substrings of length >= |word2| whose character-count vector…
General practice
Count the number of pairs of non-empty substrings—one from s and one from t—of the same length whose Hamming distance is exactly one (they differ…
General practice
Count the number of substrings of a binary string s such that either the number of 0s or the number of 1s in the substring…
General practice
Given a binary string s and integer k, for each query [l,r] count substrings of s[l..r] whose number of 0's is ≤ k or whose…
General practice
Count the number of substrings of s that contain at least one character appearing at least k times. The core challenge is to efficiently enumerate/count…
General practice
Given a string and an integer k, count substrings in which exactly k distinct characters each occur exactly k times (so valid substrings have length…
General practice
Count the number of substrings in a string that consist of a single repeated character (i.e., contain only one distinct letter). This is typically solved…
General practice
Count how many substrings of a given string contain only unique characters (no repeated characters within the substring). This is typically solved with a…
General practice
Given a tree (n ≤ 15), count for each d=1..n-1 how many connected node subsets (subtrees) have diameter exactly d — i.e., enumerate connected subsets…
General practice
Count how many integers in [low, high] have an even number of digits and whose first half of digits sums to the same value as…
General practice
Process the array left-to-right: whenever batteryPercentages[i] > 0 you test that device (increment count) and all later devices lose 1 battery (floored at 0). Equivalently…
General practice
Count how many digits of a given integer num (counting repeated digits) evenly divide num (i.e., num % digit == 0). Constraint: 1 <= num…
General practice
Given consecutive differences of a hidden length-(n+1) sequence, compute its prefix sums to find the relative min and max offsets and then count how many…
General practice
Count the number of length-n arrays with values in [1..m] that have exactly k adjacent equal pairs (equivalently exactly n-1-k transitions), returning the result mod…
General practice
Count the number of contiguous subarrays whose bitwise XOR is 0 (equivalently, every bit appears an even number of times in the subarray). This reduces…
General practice
Given an undirected graph with n vertices, count how many connected components are complete graphs (cliques). For each connected component of size k, check that…
General practice
Count the number of permutations of [0..n-1] (mod 1e9+7) starting with computer 0 unlocked, such that every other index i appears only after at least…
General practice
Given a set of allowed lowercase letters, count how many words in the array consist only of those letters. Return the number of words whose…
General practice
Given a list of experiments each described by a numeric value and a condition on their combined metric (e.g., sum, product, or probability threshold), count…
General practice
Count the number of index pairs (i<j) in nums whose sum lies in [lower, upper]. With n up to 1e5, the challenge is to do…
General practice
Given an undirected tree rooted at 0, count how many nodes have the property that all of their children’s subtrees have the same size. (n…
General practice
Count the number of ways to split an array into contiguous parts so that all occurrences of each value lie inside a single part; this…
General practice
Count the number of contiguous subarrays that contain at least k pairs of equal elements (i<j with arr[i]==arr[j]). This is typically solved with a sliding-window…
General practice