# [1913. Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs/description/) # 1. Tóm tắt đề bài Chọn ra 4 chỉ số `a, b, c, d` trong dãy `nums`, sao cho `nums[a] * nums[b] - nums[c] * nums[d]` có giá trị lớn nhất. ### Giới hạn $4 \le |nums| \le 10^4$ $1 \le nums[i] \le 10^4$ # 2. Tóm tắt lời giải **Độ phức tạp dự tính: $O(n * log(n))$**, với $n == |nums|$ Ta cần tối đa hóa số bị trừ (`nums[a] * nums[b]`), và tối thiểu hóa số trừ (`nums[c] * nums[d]`) để tối đa hóa kết quả. Điều kiện `|num| >= 4` cũng khiến cho việc xử lý dễ hơn. # 3. Lời giải chi tiết - Sắp xếp mảng. - Lấy tích hai số lớn nhất, trừ tích hai số nhỏ nhất. Các bạn tham khảo code ở đây: https://leetcode.com/problems/maximum-product-difference-between-two-pairs/submissions/1122161105/ ### Độ phức tạp thuật toán Thời gian: $O(n * log(n))$ Bộ nhớ mở rộng: $O(1)$ # 4. Kết luận & Gợi ý mở rộng Bài này là một bài dễ, mở đầu cho một tuần nhẹ nhàng. Các bạn có thể tham khảo những bài gợi ý dưới đây: [75. Sort Colors ](https://leetcode.com/problems/sort-colors/) [2790. Maximum Number of Groups With Increasing Length](https://leetcode.com/problems/maximum-number-of-groups-with-increasing-length/description/)