A problem that combines frequency counting with conditional summation of distinct elements.
Given an array of integers and an integer k, find the sum of all distinct elements that appear exactly k times in the array. Each such element should be included only once in the sum.
Your task: Find the sum of all distinct elements that appear exactly k times in the array.
Input:
nums = [2, 3, 9, 9], k = 1
Output:
5
Input:
nums = [1, 8, 8, 8, 5, 6, 2], k = 3
Output:
8
A problem that introduces duplicate detection algorithms and set-based thinking.
Given an array nums of size n, return true if any value appears more than once, otherwise return false.
This problem introduces you to duplicate detection algorithms and teaches you about set-based thinking and comparison operations within arrays.
Your task: Return true if any value appears more than once, otherwise return false.
Input:
nums = [1, 2, 3, 4]
Output:
false
Input:
nums = [1, 2, 3, 2]
Output:
true
Input:
nums = [5, 5, 5]
Output:
true
A problem that teaches about finding extremes in data and handling edge cases.
Given an array nums of size n, find the second largest unique element in the array. If it doesn't exist (e.g., all elements are the same), return -1.
This problem teaches you about finding extremes in data and handling edge cases where the desired element might not exist.
Your task: Find the second largest unique element in the array, or return -1 if it doesn't exist.
Input:
nums = [10, 20, 30, 40]
Output:
30
Input:
nums = [5, 5, 5]
Output:
-1
Input:
nums = [3, 2, 1]
Output:
2