Hash set · Easy
A client and API compare record IDs to identify shared records. Duplicate IDs on either side must not duplicate the result.
Return the set intersection in ascending numeric order.
Input
Call
- Implement
solve(input)and return its result. Do not print fromsolve.
Input object
{ client:integer[], server:integer[] }
What each field means
clientandserver— integer record IDs from the two sides; duplicates are allowed.
Output
Return value and rules
- Return IDs present in both arrays, with each ID appearing once.
- Sort numerically in ascending order.
- No shared IDs produce
[].
Constraints
- Each input has at most 100000 elements
- IDs in [0,1000000000]; do not mutate the arrays.
Examples
Example 1
{
"client": [
3,
1,
1
],
"server": [
1,
3,
3,
4
]
}Returns
[
1,
3
]Example 2
{
"client": [],
"server": []
}Returns
[]Required complexity
O(n + m + k log k) time and O(n + m) space