2.14 ✅ Sắp xếp (Sorting)

  • Hiểu sâu về quicksort nhiều đường (multi-way quicksort). Bài 75.
  • Sắp xếp danh sách liên kết: sắp xếp chèn (bài 147) và sắp xếp trộn (bài 148).
  • Sắp xếp theo thùng (bucket sort)sắp xếp theo cơ số (radix sort). Bài 164.
  • Sắp xếp lắc lư (Wiggle sort). Bài 324.
  • Sắp xếp sao cho các phần tử giống nhau không kề nhau. Bài 767, 1054.
  • Sắp xếp bánh kếp (Pancake sort). Bài 969.
STTTiêu đềLời giảiĐộ khóĐộ phức tạp thời gianĐộ phức tạp bộ nhớYêu thíchTỷ lệ AC (Acceptance)
0015Tổng 3 số (3Sum)GoMedium32.6%
0016Tổng 3 số gần nhất (3Sum Closest)GoMedium45.8%
0018Tổng 4 số (4Sum)GoMedium35.9%
0049Nhóm các từ đảo chữ (Group Anagrams)GoMedium66.7%
0056Gộp các đoạn (Merge Intervals)GoMediumO(n log n)O(log n)46.2%
0075Sắp xếp màu (Sort Colors)GoMediumO(n)O(1)❤️58.5%
0088Trộn hai mảng đã sắp xếp (Merge Sorted Array)GoEasy46.6%
0147Sắp xếp chèn danh sách liên kết (Insertion Sort List)GoMediumO(n^2)O(1)❤️51.0%
0148Sắp xếp danh sách (Sort List)GoMediumO(n log n)O(log n)❤️55.1%
0164Khoảng cách lớn nhất (Maximum Gap)GoHardO(n log n)O(log n)❤️43.3%
0169Phần tử chiếm đa số (Majority Element)GoEasy63.9%
0179Số lớn nhất (Largest Number)GoMediumO(n log n)O(log n)❤️34.5%
0215Phần tử lớn thứ K trong mảng (Kth Largest Element in an Array)GoMedium66.1%
0217Có phần tử trùng (Contains Duplicate)GoEasy61.4%
0220Có phần tử trùng III (Contains Duplicate III)GoHardO(n log n)O(1)❤️22.1%
0229Phần tử chiếm đa số II (Majority Element II)GoMedium45.0%
0242Anagram hợp lệ (Valid Anagram)GoEasyO(n)O(n)63.0%
0268Số bị thiếu (Missing Number)GoEasy62.5%
0274Chỉ số H (H-Index)GoMediumO(n)O(n)38.3%
0324Sắp xếp lắc lư II (Wiggle Sort II)GoMediumO(n)O(n)❤️33.3%
0347Top K phần tử xuất hiện nhiều nhất (Top K Frequent Elements)GoMedium64.2%
0349Giao của hai mảng (Intersection of Two Arrays)GoEasyO(n)O(n)70.9%
0350Giao của hai mảng II (Intersection of Two Arrays II)GoEasyO(n)O(n)56.0%
0354Phong bì búp bê Nga (Russian Doll Envelopes)GoHard38.0%
0368Tập con chia hết lớn nhất (Largest Divisible Subset)GoMedium41.5%
0378Phần tử nhỏ thứ K trong ma trận đã sắp xếp (Kth Smallest Element in a Sorted Matrix)GoMedium61.7%
0389Tìm ký tự khác biệt (Find the Difference)GoEasy59.9%
0414Số lớn thứ ba (Third Maximum Number)GoEasy33.2%
0435Các đoạn không chồng lấp (Non-overlapping Intervals)GoMedium50.3%
0436Tìm đoạn bên phải (Find Right Interval)GoMedium50.8%
0451Sắp xếp ký tự theo tần suất (Sort Characters By Frequency)GoMedium70.1%
0455Phân phát bánh quy (Assign Cookies)GoEasy49.9%
0462Số bước tối thiểu để làm các phần tử bằng nhau II (Minimum Moves to Equal Array Elements II)GoMedium60.0%
0475Máy sưởi (Heaters)GoMedium36.5%
0506Xếp hạng tương đối (Relative Ranks)GoEasy60.5%
0524Từ dài nhất trong từ điển bằng cách xóa (Longest Word in Dictionary through Deleting)GoMediumO(n)O(1)51.0%
0532Các cặp K-diff trong mảng (K-diff Pairs in an Array)GoMedium41.2%
0561Chia mảng (Array Partition)GoEasy77.2%
0581Mảng con liên tục chưa sắp xếp ngắn nhất (Shortest Unsorted Continuous Subarray)GoMedium36.4%
0594Dãy con hài hòa dài nhất (Longest Harmonious Subsequence)GoEasy53.5%
0611Số tam giác hợp lệ (Valid Triangle Number)GoMedium50.5%
0628Tích lớn nhất của ba số (Maximum Product of Three Numbers)GoEasy45.9%
0632Khoảng nhỏ nhất bao phủ phần tử từ K danh sách (Smallest Range Covering Elements from K Lists)GoHard61.0%
0645Sai lệch tập hợp (Set Mismatch)GoEasy42.7%
0658Tìm K phần tử gần nhất (Find K Closest Elements)GoMedium46.8%
0692Top K từ xuất hiện nhiều nhất (Top K Frequent Words)GoMedium57.2%
0710Chọn ngẫu nhiên với danh sách đen (Random Pick with Blacklist)GoHardO(n)O(n)33.5%
0719Tìm khoảng cách cặp nhỏ nhất thứ K (Find K-th Smallest Pair Distance)GoHard36.7%
0720Từ dài nhất trong từ điển (Longest Word in Dictionary)GoMedium52.0%
0726Số lượng nguyên tử (Number of Atoms)GoHard52.1%
0747Số lớn nhất ít nhất gấp đôi các số còn lại (Largest Number At Least Twice of Others)GoEasy47.1%
0767Sắp xếp lại chuỗi (Reorganize String)GoMediumO(n log n)O(log n)❤️52.9%
0786Phân số nguyên tố nhỏ thứ K (K-th Smallest Prime Fraction)GoMedium51.6%
0791Sắp xếp chuỗi tùy chỉnh (Custom Sort String)GoMedium69.1%
0792Số lượng dãy con khớp (Number of Matching Subsequences)GoMedium51.6%
0825Bạn bè có độ tuổi phù hợp (Friends Of Appropriate Ages)GoMedium46.3%
0826Phân công công việc có lợi nhuận cao nhất (Most Profit Assigning Work)GoMedium44.9%
0846Xếp bài liên tiếp (Hand of Straights)GoMedium56.2%
0853Đoàn xe (Car Fleet)GoMediumO(n log n)O(log n)50.3%
0869Sắp xếp lại lũy thừa của 2 (Reordered Power of 2)GoMedium63.5%
0870Xáo trộn để có lợi thế (Advantage Shuffle)GoMedium51.8%
0881Thuyền cứu người (Boats to Save People)GoMedium53.1%
0888Đổi kẹo công bằng (Fair Candy Swap)GoEasy60.7%
0891Tổng độ rộng dãy con (Sum of Subsequence Widths)GoHard36.6%
0910Khoảng nhỏ nhất II (Smallest Range II)GoMedium35.1%
0922Sắp xếp mảng theo tính chẵn/lẻ II (Sort Array By Parity II)GoEasyO(n)O(1)70.7%
0923Tổng 3 số với bội số (3Sum With Multiplicity)GoMedium45.3%
0969Sắp xếp pancake (Pancake Sorting)GoMediumO(n log n)O(log n)❤️70.1%
0973K điểm gần gốc tọa độ nhất (K Closest Points to Origin)GoMediumO(n log n)O(log n)65.7%
0976Chu vi tam giác lớn nhất (Largest Perimeter Triangle)GoEasyO(n log n)O(log n)54.6%
0977Bình phương của mảng đã sắp xếp (Squares of a Sorted Array)GoEasy71.9%
1005Tối đa hóa tổng mảng sau K lần đổi dấu (Maximize Sum Of Array After K Negations)GoEasy50.9%
1030Các ô ma trận theo thứ tự khoảng cách (Matrix Cells in Distance Order)GoEasyO(n^2)O(1)69.7%
1040Di chuyển đá đến khi liên tiếp II (Moving Stones Until Consecutive II)GoMedium55.9%
1051Kiểm tra chiều cao (Height Checker)GoEasy75.6%
1054Mã vạch cách xa nhau (Distant Barcodes)GoMediumO(n log n)O(log n)❤️45.8%
1122Sắp xếp tương đối mảng (Relative Sort Array)GoEasy68.6%
1170So sánh chuỗi theo tần suất của ký tự nhỏ nhất (Compare Strings by Frequency of the Smallest Character)GoMedium61.5%
1200Hiệu tuyệt đối nhỏ nhất (Minimum Absolute Difference)GoEasy69.6%
1235Lợi nhuận tối đa khi xếp lịch công việc (Maximum Profit in Job Scheduling)GoHard53.4%
1296Chia mảng thành các bộ K số liên tiếp (Divide Array in Sets of K Consecutive Numbers)GoMedium56.5%
1300Tổng mảng đã biến đổi gần mục tiêu nhất (Sum of Mutated Array Closest to Target)GoMedium43.6%
1305Tất cả phần tử trong hai cây nhị phân tìm kiếm (All Elements in Two Binary Search Trees)GoMedium79.8%
1329Sắp xếp ma trận theo đường chéo (Sort the Matrix Diagonally)GoMedium83.3%
1337K hàng yếu nhất trong ma trận (The K Weakest Rows in a Matrix)GoEasy72.1%
1353Số sự kiện tối đa có thể tham dự (Maximum Number of Events That Can Be Attended)GoMedium32.5%
1383Hiệu suất tối đa của một đội (Maximum Performance of a Team)GoHard48.5%
1385Tìm giá trị khoảng cách giữa hai mảng (Find the Distance Value Between Two Arrays)GoEasy66.5%
1464Tích lớn nhất của hai phần tử trong mảng (Maximum Product of Two Elements in an Array)GoEasy79.9%
1465Diện tích lớn nhất của miếng bánh sau khi cắt ngang và dọc (Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts)GoMedium40.9%
1608Mảng đặc biệt với X phần tử >= X (Special Array With X Elements Greater Than or Equal X)GoEasy60.5%
1619Trung bình mảng sau khi loại bỏ một số phần tử (Mean of Array After Removing Some Elements)GoEasy65.7%
1636Sắp xếp mảng theo tần suất tăng dần (Sort Array by Increasing Frequency)GoEasy69.5%
1647Số lần xóa tối thiểu để tần suất ký tự là duy nhất (Minimum Deletions to Make Character Frequencies Unique)GoMedium59.1%
1648Bán bóng màu giảm giá trị (Sell Diminishing-Valued Colored Balls)GoMedium30.5%
1657Xác định hai chuỗi có gần nhau không (Determine if Two Strings Are Close)GoMedium56.3%
1665Năng lượng ban đầu tối thiểu để hoàn thành công việc (Minimum Initial Energy to Finish Tasks)GoHard56.3%
1679Số lượng tối đa các cặp có tổng K (Max Number of K-Sum Pairs)GoMedium57.3%
1691Chiều cao tối đa bằng cách xếp khối hộp (Maximum Height by Stacking Cuboids)GoHard54.4%
1710Số đơn vị tối đa trên xe tải (Maximum Units on a Truck)GoEasy73.8%
1818Hiệu tổng tuyệt đối nhỏ nhất (Minimum Absolute Sum Difference)GoMedium30.4%
1846Phần tử lớn nhất sau khi giảm và sắp xếp lại (Maximum Element After Decreasing and Rearranging)GoMedium58.9%
1877Giảm thiểu tổng cặp lớn nhất trong mảng (Minimize Maximum Pair Sum in Array)GoMedium79.9%
1984Chênh lệch nhỏ nhất giữa điểm cao nhất và thấp nhất của K điểm (Minimum Difference Between Highest and Lowest of K Scores)GoEasy54.4%
2037Số bước tối thiểu để sắp chỗ cho mọi người (Minimum Number of Moves to Seat Everyone)GoEasy82.1%
2164Sắp xếp chỉ số chẵn và lẻ độc lập (Sort Even and Odd Indices Independently)GoEasy65.0%
2165Giá trị nhỏ nhất của số sau khi sắp xếp lại (Smallest Value of the Rearranged Number)GoMedium51.4%
2171Xóa tối thiểu số hạt đậu ma thuật (Removing Minimum Number of Magic Beans)GoMedium42.1%
------------------------------------------------------------------------------------------------------------------------------------------------