java.lang.Object
g2501_2600.s2537_count_the_number_of_good_subarrays.Solution

public class Solution extends Object
2537 - Count the Number of Good Subarrays.<p>Medium</p> <p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of <strong>good</strong> subarrays of</em> <code>nums</code>.</p> <p>A subarray <code>arr</code> is <strong>good</strong> if it there are <strong>at least</strong> <code>k</code> pairs of indices <code>(i, j)</code> such that <code>i < j</code> and <code>arr[i] == arr[j]</code>.</p> <p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,1,1,1,1], k = 10</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The only good subarray is the array nums itself.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [3,1,4,3,2,2,4], k = 2</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> There are 4 different good subarrays:</p> <ul> <li> <p>[3,1,4,3,2,2] that has 2 pairs.</p> </li> <li> <p>[3,1,4,3,2,2,4] that has 3 pairs.</p> </li> <li> <p>[1,4,3,2,2,4] that has 2 pairs.</p> </li> <li> <p>[4,3,2,2,4] that has 2 pairs.</p> </li> </ul> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i], k <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countGood

      public long countGood(int[] nums, int k)