These two problems evaluate competency in frequency counting and selection algorithms for identifying top-k elements and in binary tree structure analysis and traversal for checking completeness, belonging to the Coding & Algorithms domain and the broader data structures and algorithms category.
You are given an integer array nums and an integer k.
Task: Return the k distinct values that occur most frequently in nums.
Input
nums
: list of integers (length
n
)
k
: integer,
1 <= k <= (# of distinct values in nums)
Output
k
integers: the values with highest frequency.
Notes / Constraints
O(n log n)
if possible.
You are given the root of a binary tree.
A binary tree is complete if:
Task: Return true if the tree is complete; otherwise return false.
Input
root
: root node of a binary tree (each node has
val
,
left
,
right
)
Output
Constraints
10^5
nodes.