- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
leetcode problem 2966 | Divide Array into Arrays with maximum Difference| java | c++ | Hindi
You are given an integer array nums of length n, where n is a multiple of 3, and a positive integer k. Your task is to divide this array into n/3 groups, where each group contains exactly 3 elements.
✅ Condition to satisfy:
In every group, the difference between any two elements must be less than or equal to k.
Return the resulting 2D array of these groups. If it’s not possible to divide the array this way, return an empty array. If there are multiple valid answers, return any one of them.
📌 Example 1:
Input: nums = [1, 3, 4, 8, 7, 9, 3, 5, 1], k = 2
Output: [[1, 1, 3], [3, 4, 5], [7, 8, 9]]
Explanation: Every group has elements with pairwise differences ≤ 2.
📌 Example 2:
Input: nums = [2, 4, 2, 2, 5, 2], k = 2
Output: []
Explanation: No valid way to group all numbers such that every group of 3 has pairwise differences ≤ 2.
📌 Example 3:
Input: nums = [4, 2, 9, 8, 2, 12, 7, 12, 10, 5, 8, 5, 5, 7, 9, 2, 5, 11], k = 14
Output: [[2, 2, 12], [4, 8, 5], [5, 9, 7], [7, 8, 5], [5, 9, 10], [11, 12, 2]]
Explanation: All group differences satisfy the given condition.
🧠 Constraints:
Length of nums: 1 to 100,000
All elements in nums and k: Between 1 and 100,000
Length of nums is always a multiple of 3
Видео leetcode problem 2966 | Divide Array into Arrays with maximum Difference| java | c++ | Hindi канала MissLogic - "Where code meets Clarity."
✅ Condition to satisfy:
In every group, the difference between any two elements must be less than or equal to k.
Return the resulting 2D array of these groups. If it’s not possible to divide the array this way, return an empty array. If there are multiple valid answers, return any one of them.
📌 Example 1:
Input: nums = [1, 3, 4, 8, 7, 9, 3, 5, 1], k = 2
Output: [[1, 1, 3], [3, 4, 5], [7, 8, 9]]
Explanation: Every group has elements with pairwise differences ≤ 2.
📌 Example 2:
Input: nums = [2, 4, 2, 2, 5, 2], k = 2
Output: []
Explanation: No valid way to group all numbers such that every group of 3 has pairwise differences ≤ 2.
📌 Example 3:
Input: nums = [4, 2, 9, 8, 2, 12, 7, 12, 10, 5, 8, 5, 5, 7, 9, 2, 5, 11], k = 14
Output: [[2, 2, 12], [4, 8, 5], [5, 9, 7], [7, 8, 5], [5, 9, 10], [11, 12, 2]]
Explanation: All group differences satisfy the given condition.
🧠 Constraints:
Length of nums: 1 to 100,000
All elements in nums and k: Between 1 and 100,000
Length of nums is always a multiple of 3
Видео leetcode problem 2966 | Divide Array into Arrays with maximum Difference| java | c++ | Hindi канала MissLogic - "Where code meets Clarity."
Комментарии отсутствуют
Информация о видео
18 июня 2025 г. 12:20:51
00:21:54
Другие видео канала




















