- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
LeetCode 2958 Length of Longest Subarray With at Most K Frequency ||Day 36|| C++ ||Medium || Arrays
In this problem, we are given an array nums and an integer k. We need to find the length of the longest subarray in nums such that the frequency of each element in the subarray is less than or equal to k. This type of subarray is called a "good" subarray.
Steps to Solve:
🚀 Initialize two pointers i and j to 0.
📝 Initialize an empty map to store the frequency of elements in the current window.
📏 Initialize a variable ans to 0 to store the length of the longest good subarray.
🔄 Iterate over the array using pointer j until it reaches the end of the array.
📈 Increment the frequency of nums[j] in the map.
🔄 If the frequency of nums[j] becomes greater than k, increment i and reduce the frequency of nums[i] until the frequency becomes less than or equal to k.
🔄 Update ans to be the maximum of ans and the current window size j - i + 1.
🔙 Return ans as the length of the longest good subarray.
#leetcode #codinginterview #like #geeksforgeeks #support #subscribe #comment #subscribe
Видео LeetCode 2958 Length of Longest Subarray With at Most K Frequency ||Day 36|| C++ ||Medium || Arrays канала Code With Deepa
Steps to Solve:
🚀 Initialize two pointers i and j to 0.
📝 Initialize an empty map to store the frequency of elements in the current window.
📏 Initialize a variable ans to 0 to store the length of the longest good subarray.
🔄 Iterate over the array using pointer j until it reaches the end of the array.
📈 Increment the frequency of nums[j] in the map.
🔄 If the frequency of nums[j] becomes greater than k, increment i and reduce the frequency of nums[i] until the frequency becomes less than or equal to k.
🔄 Update ans to be the maximum of ans and the current window size j - i + 1.
🔙 Return ans as the length of the longest good subarray.
#leetcode #codinginterview #like #geeksforgeeks #support #subscribe #comment #subscribe
Видео LeetCode 2958 Length of Longest Subarray With at Most K Frequency ||Day 36|| C++ ||Medium || Arrays канала Code With Deepa
Комментарии отсутствуют
Информация о видео
28 марта 2024 г. 7:27:54
00:13:23
Другие видео канала




















