The first part evaluates understanding of linked data structures and deep-copy semantics, focusing on preserving node values and both next and arbitrary random pointer relationships while reasoning about node identity and cycles, and is commonly asked to assess correctness in memory/reference handling and structural preservation.

You are given two separate coding tasks.
You are given the head of a singly linked list. Each node has three fields:
val
: an integer value
next
: a pointer (or reference) to the next node in the list, or
null
if it is the last node
random
: a pointer (or reference) to
any
node in the list (including possibly itself) or
null
The list may contain zero or more nodes.
Task: Implement a function that creates a deep copy of this list. The new list must:
val
values.
next
and
random
pointers: for every original node, its copy's
next
and
random
should point to the copies of the corresponding original targets.
Return the head of the copied list.
You may assume:
random
pointer configurations, including cycles formed via
random
pointers.
You should aim for time complexity and additional space.
You are given an integer array nums and an integer k where .
Task:
Return any order of the k distinct integers that appear most frequently in nums.
k
by frequency, any order among them is acceptable.
k
distinct integers.
Examples
Example 1:
nums = [1, 1, 1, 2, 2, 3]
,
k = 2
[1, 2]
(because
1
appears 3 times,
2
appears 2 times,
3
appears 1 time)
Example 2:
nums = [4, 4, 4, 5, 5, 6]
,
k = 1
[4]
(since it is the most frequent element)
You may assume:
nums
is at least
k
.
Aim for an algorithm that runs in better than time, where is the length of nums.