面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
多数元素
Find the majority element in an array, where the element appears more than n/2 times, using efficient algorithms.
多数元素 II
Identify all elements in an integer array appearing more than ⌊ n/3 ⌋ times using efficient array scanning and hash coun…
猜数字游戏
Solve the Bulls and Cows problem using hash tables and string manipulation to track exact and misplaced digits.
前 K 个高频元素
Find the k most frequent elements from an array using efficient algorithms like hashing and sorting.
赎金信
Determine if a ransom note can be constructed from a magazine's letters using hash tables and string counting techniques…
字符串中的第一个唯一字符
Find the index of the first non-repeating character in a string using efficient queue-driven state processing.
根据字符出现频率排序
Sort Characters By Frequency requires counting characters efficiently and rearranging a string in descending frequency o…
最长和谐子序列
Find the length of the longest harmonious subsequence in an integer array using array scanning and hash-based frequency …
任务调度器
Task Scheduler is solved by counting task frequencies and computing how cooldown gaps force idle slots around the most f…
前K个高频单词
Solve Top K Frequent Words by counting each word, then ordering ties alphabetically so frequency wins before lexicograph…
重构字符串
Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.
子域名访问计数
The Subdomain Visit Count problem requires counting the visits to all subdomains of a given domain from a list of count-…
最常见的单词
Find the most frequent non-banned word in a paragraph, excluding punctuation, using an efficient array scan and hash tab…
重新排序得到 2 的幂
Determine if a number's digits can be rearranged to form a power of two using counting and hash-based checks.
两句话中的不常见单词
Find uncommon words from two sentences by counting word frequencies using hash tables.
RLE 迭代器
Design an efficient iterator for a run-length encoded array, handling large counts and sequential access correctly every…
卡牌分组
Solve the problem of determining if a deck can be partitioned into groups with equal occurrences of card values.
三数之和的多种可能
Count all unique triplets in an integer array whose sum equals the target, handling multiplicity efficiently using hashi…
使数组唯一的最小增量
This problem challenges you to find the minimum moves to make all elements in an array unique by incrementing elements.
K 个不同整数的子数组
Find subarrays with exactly k distinct integers in an integer array using sliding window and hash lookup techniques.
总持续时间可被 60 整除的歌曲
Calculate the number of song pairs whose total durations sum to a multiple of 60 using array scanning and hash lookups.
距离相等的条形码
Rearrange barcodes in an array so that no two adjacent elements are equal, using a greedy approach and hash table for ef…
活字印刷
Compute all unique non-empty sequences from given letter tiles using backtracking search with pruning efficiently.
受标签影响的最大值
Maximize the sum of selected item values while respecting label use limits using array scanning and hash tracking.
等价多米诺骨牌对的数量
Count all pairs of dominoes that are equivalent by scanning the array and using a hash table for fast lookup.
拼写单词
Compute the total length of words that can be fully constructed from given characters using array scanning and hash mapp…
“气球” 的最大数量
Find the maximum number of times the word 'balloon' can be formed from characters of the given string.
分割平衡字符串
Split a string into the maximum number of balanced substrings where each substring has an equal number of 'L' and 'R'.
统计参与通信的服务器
Count Servers that Communicate involves identifying servers in a grid that can communicate based on row or column connec…
制造字母异位词的最小步骤数
Calculate the minimum steps to transform one string into an anagram of another using character replacements efficiently.
根据数字二进制下 1 的数目排序
Sort an array of integers by the number of 1's in their binary representation and then by their value in case of ties.
通过投票对团队排名
Rank Teams by Votes requires counting position-based votes and resolving ties with array scanning and hash lookup techni…
上升下降字符串
Reorder the string based on a specific algorithm using hash tables and string manipulation.
找出数组中的幸运数
Identify the largest lucky integer in an array by counting frequencies and comparing values with their occurrences effic…
构造 K 个回文字符串
Determine if a string's characters can be rearranged to form exactly k non-empty palindrome strings using greedy validat…
数青蛙
Determine the minimum number of frogs required to sequentially produce all croaks in a mixed frog croak string efficient…
不同整数的最少数目
Find the least number of unique integers after removing exactly k elements from an array using efficient frequency count…
检查数组对是否可以被 k 整除
Check if array pairs are divisible by k by pairing elements whose sums are divisible by k using array scanning and hash …
好数对的数目
Count all index pairs in an array where elements match and the first index is smaller, using hash-based scanning efficie…
子树中标签相同的节点数
Compute the number of nodes in each subtree sharing the same label using DFS with hash table aggregation efficiently.
设计停车系统
Implement a class to manage a parking lot with fixed slots for big, medium, and small cars, tracking occupancy efficient…
确定两个字符串是否接近
Check if two strings can transform into each other using letter swaps and frequency reorganizations, leveraging hash tab…
统计一致字符串的数目
Count the number of strings fully composed of allowed characters using array scanning and hash lookup for efficiency.
判断字符串的两半是否相似
Check if two halves of a string contain the same number of vowels using a character counting approach efficiently.
同积元组
Given an array of distinct integers, return the number of tuples where the product of two pairs is the same.
满足三条件之一需改变的最少字符数
This problem asks for the minimum operations to change two strings so that one of three conditions is met.
盒子中小球的最大数量
The problem asks you to find the box with the maximum number of balls based on the sum of digits of ball numbers.
唯一元素的和
Given an array, find the sum of all its unique elements by identifying those that appear only once.
通过最少操作次数使数组的和相等
Solve the problem of balancing the sums of two integer arrays with minimal operations, using array scanning and hash loo…
所有子字符串美丽值之和
Calculate the total beauty of all substrings by counting character frequencies and computing frequency differences effic…
统计点对的数目
Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.
仅执行一次字符串交换能否使两个字符串相等
Check if one string swap can make two equal strings using hash table and string counting methods.
统计一个数组中好对子的数目
Count Nice Pairs in an Array requires efficiently pairing numbers where nums[i] + rev(nums[j]) equals nums[j] + rev(nums…
序列中不同最大公约数的数目
Given an array of positive integers, find the number of different subsequences' GCDs.
人口最多的年份
Find the earliest year with the highest population using an array plus counting approach.
有向图中最大颜色值
Compute the maximum color frequency along any valid path in a directed graph using topological ordering and dynamic prog…
长度为三且各字符不同的子字符串
Count all substrings of length three in a string where each character is unique using sliding window techniques efficien…
重新分配字符使所有字符串都相等
Determine if you can redistribute characters among strings so that all strings become identical using a counting approac…
检查是否所有字符出现次数相同
Check if a string has characters with equal occurrences using hash tables and string manipulation techniques.
好子集的数目
Find the number of good subsets in an integer array, where each subset's product is the product of distinct primes.
可互换矩形的组数
Count all pairs of rectangles that share the exact width-to-height ratio using efficient array scanning and hash lookup.
差的绝对值为 K 的数对数目
Find how many pairs (i, j) with i < j satisfy |nums[i] - nums[j]| == k using array scanning and hash lookup.
检测正方形
Detect Squares requires tracking points on a 2D plane to quickly count all possible axis-aligned squares using efficient…
重复 K 次的最长子序列
Find the longest subsequence repeated k times in a string using backtracking search with pruning.
连接后等于目标字符串的字符串对
Count all unique index pairs in a string array whose concatenation exactly matches the given target string using efficie…
分割数组的最多方案数
Determine the maximum number of ways to split an array into equal sums using at most one element change, leveraging pref…
石子游戏 IX
In the Stone Game IX problem, Alice and Bob take turns removing stones, and Alice wins if the sum of removed stones is d…
下一个更大的数值平衡数
Find the smallest numerically balanced number greater than a given integer using backtracking search and pruning.
数组中第 K 个独一无二的字符串
Find the kth distinct string in an array by identifying strings that appear only once, using efficient array scanning an…
检查两个字符串是否几乎相等
Solve Check Whether Two Strings are Almost Equivalent by counting letters and rejecting any character whose frequency ga…
统计出现过一次的公共字符串
Learn how to efficiently count strings appearing exactly once in both arrays using array scanning and hash lookup patter…
连接两字母单词得到的最长回文串
Find the maximum-length palindrome by combining two-letter words using array scanning and hash table lookups efficiently…
元素计数
Count elements in an array that have both strictly smaller and strictly greater numbers using array sorting efficiently.
找出数组中的所有孤独数字
Find lonely numbers in an array where each lonely number appears once and has no adjacent values.
使数组变成交替数组的最少操作数
Given an array, calculate the minimum number of operations needed to make it alternating.
构造限制重复的字符串
Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …
制造字母异位词的最小步骤数 II
Compute the fewest character insertions needed to turn two strings into anagrams using hash table frequency counts effic…
数组中紧跟 key 之后出现最频繁的数字
Scan the array once, count which value appears right after the key, and return the uniquely most frequent follower.
将数组划分成相等数对
Determine if an array of 2n integers can be partitioned into n pairs where each pair contains identical elements using h…
找出输掉零场或一场比赛的玩家
Identify players with zero or one losses by efficiently scanning arrays and counting losses using hash lookups for accur…
完成所有任务需要的最少轮数
The problem requires finding the minimum rounds to complete tasks, focusing on greedy algorithms and hash table lookups.
多个数组求交集
Find integers that are common across all arrays in a given list of arrays.
按位与结果大于零的最长组合
Find the largest group of integers in an array whose bitwise AND is greater than zero using array scanning and hash look…
判断一个数的数字计数是否等于数位的值
Determine if a number's digits correspond to their counts in the string representation.
最多单词数的发件人
Find the sender with the largest total word count by scanning messages and tallying counts using a hash table efficientl…
重排字符形成目标字符串
Calculate the maximum copies of a target string from letters in s using frequency counting and hash tables efficiently.
数组能形成多少数对
Given an array, count how many pairs can be formed and how many leftovers remain after pairing.
最好的扑克手牌
Determine the strongest poker hand from five cards using array scanning and hash table counting techniques efficiently.
第一个出现两次的字母
Find the first letter that repeats in a string using hash table tracking and early detection for efficiency.
统计坏数对的数目
Count the number of bad pairs in an array where the difference between indices and values does not match.
最大回文数字
Form the largest palindromic number from a string of digits while maintaining a valid palindrome structure.
出现最频繁的偶数元素
Identify the most frequent even element in an array using counting and hash lookup, handling ties by choosing the smalle…
字符串的前缀分数和
The 'Sum of Prefix Scores of Strings' problem involves calculating prefix scores for strings based on their occurrences …
删除字符使频率相同
Determine if removing a single letter from a string can make all remaining letters have identical frequency efficiently.
反转之后不同整数的数目
This problem requires counting distinct integers after performing reverse operations on each integer in an array.
摧毁一系列目标
Find the minimum seed value to destroy the most targets on a number line, using array scanning and hash lookup.
让数组不相等的最小总代价
Calculate the minimum cost to rearrange nums1 so that no element matches nums2 using optimal swaps and hash counting.
统计相似字符串对的数目
Count similar string pairs by converting each word into a character-set signature and counting matching signatures effic…
统计同位异构字符串数目
Learn to count distinct anagrams for a multi-word string using hash tables, math, and combinatorics efficiently.
找到数据流中的连续整数
Design a data stream checker to identify consecutive integers from a stream, focusing on handling state transitions effi…
正整数和负整数的最大计数
Compute the maximum count between positive and negative integers in a sorted array using efficient binary search countin…
使字符串中不同字符的数目相等
Determine if a single swap can equalize distinct character counts between two strings using hash tables for tracking fre…
拆分数组的最小代价
Minimize the cost of splitting an array into k subarrays by calculating importance values and applying dynamic programmi…
统计范围内的元音字符串数
Count the Number of Vowel Strings in Range asks to count vowel strings in a subarray of a given word list.
美丽下标对的数目
Count all index pairs in an array where the first digit of one number and last digit of another are coprime efficiently.
距离原点最远的点
Determine the maximum distance from origin using string moves and counting underscores optimally for efficient calculati…
删除数对后的最小数组长度
This problem involves minimizing the length of a sorted array by repeatedly removing adjacent pairs of equal elements.
使数组为空的最少操作次数
Minimize the number of operations to make an array empty by leveraging array scanning and hash lookup.
统计已测试设备
Simulate testing devices based on battery percentages to determine how many pass the test operations in sequence.
找出出现至少三次的最长特殊子字符串 I
Find the longest special substring in a string that appears at least three times, or return -1 if no such substring exis…
找出出现至少三次的最长特殊子字符串 II
Find the longest special substring that occurs at least three times in a given string using binary search and hash table…
最大频率元素计数
Count Elements With Maximum Frequency is solved by counting each value, tracking the highest count, and summing matching…
输入单词需要的最少按键次数 II
Given a word, find the minimum number of pushes to type it on a remapped keypad using a greedy approach.
回文字符串的最大数量
The problem focuses on maximizing the number of palindromes that can be formed from a given list of words through specif…
进行操作使字符串为空
Learn how to systematically apply operations on a string using array scanning and hash lookups to reduce it efficiently.
出现频率最高的质数
Find the most frequent prime over 10 from numbers generated by scanning a 2D matrix in all straight directions efficient…
分割数组
Determine if an even-length array can be split into two parts with all distinct elements using hash lookup scanning.
在矩阵上写出字母 Y 所需的最少操作次数
Find the minimum number of operations to write the letter Y on a grid by altering cell values.
替换字符串中的问号使分数最小
Minimize the cost of a string with '?' characters by replacing them with letters in lexicographical order while minimizi…
统计以给定字符开头和结尾的子字符串总数
Given a string and a character, find the total number of substrings that start and end with that character.
成为 K 特殊字符串需要删除的最少字符数
Minimize deletions to make a string k-special by adjusting character frequencies.
直角三角形
Count all possible right triangles in a 2D boolean grid using array scanning and hash lookup for efficiency.
K 周期字符串需要的最少操作次数
The problem requires calculating the minimum number of operations to make a string k-periodic using specific substring r…
同位字符串连接的最小长度
The problem asks to find the minimum length of a string t such that s is a concatenation of anagrams of t.
分割字符频率相等的最少子字符串
Partition a string into substrings with equal character frequencies using dynamic programming and state transitions.
所有数对中数位差之和
Sum of Digit Differences of All Pairs is a problem that involves counting digit differences in pairs from an array of in…
构成整天的下标对数目 I
Count all pairs in an array where their sum forms a complete day using hash-based counting for efficiency.
构成整天的下标对数目 II
Count the number of valid pairs of hours that form a complete day by checking if their sum is a multiple of 24.
施咒的最大总伤害
Calculate the maximum total damage by selectively casting spells while avoiding adjacent power conflicts using array sca…
操作后字符串的最短长度
Find the minimum length of a string after performing operations based on character frequency.
将 1 移动到末尾的最大操作次数
This problem requires finding the maximum number of operations to move ones to the end of a binary string.
求出胜利玩家的数目
Find how many players in a game win by picking more balls of a single color than their index position.
统计近似相等数对 I
Count Almost Equal Pairs I involves finding pairs of elements that can be made equal by swapping at most one digit.
统计近似相等数对 II
Count the number of almost equal integer pairs in an array using array scanning and hash lookup efficiently.
查询排序后的最大公约数
Solve the Sorted GCD Pair Queries problem by efficiently counting and locating GCDs of all array pairs using hash mappin…
字符串转换后的长度 I
Calculate the total number of characters in a string after repeated transformations using dynamic programming and freque…
字符串转换后的长度 II
Calculate the length of a string after repeated transformations using state transition dynamic programming for large t v…
识别数组中的最大异常值
Identify the largest outlier in an integer array using scanning and hash lookup for efficient detection and validation.
使字符频率相等的最少操作次数
This Hard problem asks to transform a string so all character frequencies match using minimal deletions, leveraging dyna…
找到字符串中合法的相邻数字
Identify the first valid adjacent digit pair in a string where each digit appears exactly as many times as its numeric v…
奇偶频次间的最大差值 I
Find the maximum difference between the frequency of characters in a string with odd and even frequencies.
K 次修改后的最大曼哈顿距离
Solve Maximum Manhattan Distance After K Changes by scanning prefixes and testing the four diagonal target pairs with li…
将数组按照奇偶性转化
Transform an array by sorting even numbers first, followed by odd numbers.
最小回文排列 II
Find the k-th lexicographically smallest palindromic rearrangement of a given palindromic string s.
找到最常见的回答
Find the most common survey response after eliminating duplicates within each day, using array scanning and hash lookups…
找到频率最高的元音和辅音
Given a string, calculate the sum of the most frequent vowel and consonant frequencies.
不同字符数量最多为 K 时的最少删除数
You need to delete characters in a string to reduce its distinct characters to at most k.
统计特殊三元组
Count Special Triplets requires scanning an array while tracking counts of previous and next values efficiently with has…
检查元素频次是否为质数
Check if any element in the array has a prime frequency count, leveraging array scanning and hash table lookup.