1)Hotspot Connection - Very very leetcode hard
There are employee_nodes employees in a company, out of which there are k special employees who have data network and share their mobile hotspots with other employees. There are employee_edges connections already made between the employees, where the ith connection connects the employees employee_fromfil and employee_tolif, such that either of the employees employee_from[il and employee_tolil can share a mobile hotspot.
Two employees x and y are connected if there is a path between them. All the employees connected to a special employee x will use the mobile hotspot of the special employee X.
Up to now, to restrict data usage, any employee was connected to at most one special employee. As data consumption has increased, any employee can be connected to at most max _connections number of special employees.
Find the maximum number of edges that can be added to the graph such that any employee is connected to at most max_connections special employees.
Note:
The given graph does not contain self-loops or multiple edges between nodes.
The graph formed after adding edges should not contain self-loops or multiple edges.
It is guaranteed that in the given graph, no two special employees are connected to each other.
Example
It is given that employee_nodes = 4, employee_edges = 1, k= 2,
max_connections = 1, special_employees = [1, 3], employee_from = [1], and
employee_to = 12.
Employees 1 and 3 are special, and max_connections = 1, so they cannot be
connected. Hence, employee 4 can be connected to 1 and 2, making two total edges.
Hence, the answer is 2.
Function Description
Complete the function getMaximumEdges in the editor below.
getMaximumEdges has the following parameters: int employee_nodes: the number of employees
int employee_from/employee_edges): the one end of the connection int employee_to[employee_edges]: the other end of the connection int special_employees[k]: the special employees
int max_connections: the maximum number of special employees to which an employee can be connected
Returns
long: the maximum number of edges that can be added to the graph such that any employee is connected to at most max_connections number of special employees
Constraints
1 ≤ employee_nodes ≤2 * 105
0 ≤ employee_edges ≤ min(2 * 105, employee_nodes * (employee_nodes - 1) / 2)
1 ≤ max_ connections ≤ k ≤ employee_nodes
1 ≤ employee_from[i], employee_toli] ≤ employee_nodes
1 ≤ special_employees[i] ≤ employee_nodes
long getMaximumEdges(int employee_nodes, vector employee_from, vector employee_to, vector special_employees, int max_connections) {
}
Longest increasing subsequence
A sequence of numbers is said to be good if it satisfies the following two conditions:
All elements in the sequence are unique.
If the minimum element in the sequence is a, and the maximum element in the sequence is b, then all numbers in the range [a, b] are present in the sequence.
For example, (4, 2, 5, 1, 3) is a good sequence, while (2, 2, 1) or (3, 7) are not.
A subsequence of an array arris a sequence that can be derived from the array arr by deleting some or no elements without changing the order of the remaining elements. Given an array of n integers, find the number of different good subsequences. Two subsequences are considered different if they include at least one different index. For example, for the sequence (2, 2,
1), both (2, 1) formed by indices 1 and 2 and (2, 1) formed by indices 0 and 2 are considered different subsequences.
Example
Consider the array arr = [13, 11, 4, 12, 5, 41. We can form the following good
subsequences:
• Subsequences of length 1: [13], [1 1], [4], [12], [5], [4]
• Subsequences of length 2: [13, 12], [11, 12], [4, 5], [5, 4]
• Subsequences of length 3: [13, 11, 12]
Thus, the answer is 6 + 4 + 1 = 11.
Function Description
Complete the function countGoodSubsequences in the editor below. countGoodSubsequences has the following parameter:
int arr[n]: the given array of integers
Returns
array.
long_int: the number of good subsequences which can be derived from the
Constraints
• 1≤n≤ 105
• 1 ≤ arrfi ≤ 105, for all i
Sample Input For Custom Testing
STDIN
lIlll
5
3
1
1
2
8
->
->
FUNCTION
IllllllI
arr[] size n = 5
arr1 = 13, 1, 1, 2, 8 1
Sample Output
10
Explanation
Given n = 5, arr = [3, 1, 1, 2, 83. We can form the following good
subsequences.
• Subsequences of length 1: [31, [1], [11, [21, [8]
• Subsequences of length 2: [3, 21, [1, 21, [1, 2]
• Subsequences of length 3: [3, 1, 2], [3, 1, 2]
Thus, the answer is 5 + 3 + 2 = 10.
Sample Input For Custom Testing
STDIN
FUNCTION
5
7
5
6
8
4
arr[] size = 5
→ arrl= I7, 5, 6, 8, 4 1
Sample Output
15
Explanation
Given n = 5, arr = [7, 5, 6, 8, 4]. We can form the following good
subsequences:
• Subsequences of length 1: [7], [5], [6], [8], [4]
• Subsequences of length 2: [7, 6], [5, 6], [7, 81, [4, 5]
• Subsequences of length 3: [7, 5, 61, [7, 6, 81, [5, 6, 4]
• Subsequences of length 4: [7, 5, 6, 4], [7, 5, 6, 8]
• Subsequences of length 5: [7, 5, 6, 8, 4]
Thus, the answer is 5 + 4 + 3 + 2 + 1 = 15.
long countGoodSubsequences(vector arr) {
}