697. Degree of an Array

  Рет қаралды 112

CodeVia

CodeVia

Күн бұрын

697. Degree of an Array #leetcodequestionandanswers #java #coding #array #greedyalgorithm #javainterviewquestions #interview #amazoninterviewpreparation #googleinterview #leetcode #javaprogramming #dsa #dsalgo #programming #hashmap java #coding #array #strings #dsa #coding #2darray
leetcode.com/p...
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.
Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.
Example 1:
Input: nums = [1,2,2,3,1]
Output: 2
Explanation:
The input array has a degree of 2 because both elements 1 and 2 appear twice.
Of the subarrays that have the same degree:
[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]
The shortest length is 2. So return 2.
Example 2:
Input: nums = [1,2,2,3,1,4,2]
Output: 6
Explanation:
The degree is 3 because the element 2 is repeated 3 times.
So [2,2,3,1,4,2] is the shortest subarray, therefore returning 6.
Constraints:
nums.length will be between 1 and 50,000.
nums[i] will be an integer between 0 and 49,999.

Пікірлер
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 532 М.
697. Degree of an Array | LEETCODE EASY | HASH MAP | ARRAY
8:19
code Explainer
Рет қаралды 6 М.
Every parent is like this ❤️💚💚💜💙
00:10
Like Asiya
Рет қаралды 19 МЛН
iPhone or Chocolate??
00:16
Hungry FAM
Рет қаралды 47 МЛН
Офицер, я всё объясню
01:00
История одного вокалиста
Рет қаралды 5 МЛН
Longest Harmonious Subsequence | LeetCode 594 | Coders Camp
10:23
Coders Camp
Рет қаралды 2,3 М.
LeetCode 697. Degree of an Array (Algorithm Explained)
12:06
Nick White
Рет қаралды 21 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 396 М.
Understanding and implementing a Hash Table (in C)
24:54
Jacob Sorber
Рет қаралды 356 М.
7 Years of Software Engineering Advice in 18 Minutes
18:32
Design HashMap | Live Coding with Explanation | Leetcode - 706
12:17
Algorithms Made Easy
Рет қаралды 23 М.
LeetCode - 665. Non-decreasing Array | Day 4 May Challenge
11:51
Aditya Mahajan
Рет қаралды 4,3 М.
Every parent is like this ❤️💚💚💜💙
00:10
Like Asiya
Рет қаралды 19 МЛН