Profitable Project Pairs
In a tech company, there are n projects available for the team to work on. Due to resource constraints, they can only work on any two of the projects. The expected profits for each project are provided in the array profit
, while the implementation costs are given in the array implementationCost
.
Task
The task is to determine the number of pairs of projects that can be chosen from the available options such that the company earns a profit after implementing both projects. That is, projects indexed i and j are chosen if:
(profit[i] - implementationCost[i]) + (profit[j] - implementationCost[j]) > 0
Example
n = 5
profit = [2, 3, 4, 5, 1]
implementationCost = [3, 4, 5, 1, 2]
Profitable Pairs
Pair of Projects (0-based) Net Profit from the first Project Net Profit from the second project
[0, 2] 2 - 3 = -1 7 - 5 = 2
[1, 2] 3 - 4 = -1 7 - 5 = 2
[2, 3] 7 - 5 = 2 1 - 1 = 0
[3, 4] 1 - 1 = 0 2 - 2 = 0
Divisible Range
A quiz on Mathematics and Number Theory contains the following problem.
Task
Given an integer array arr
that consists of n elements, and 2 integers k and x, find the number of pairs of indices i, j (0 ≤ i, j < n, j < n) such that:
arr[i] ≤ arr[j]
- There are exactly k elements in the range
[arr[i], arr[j]]
that are divisible by x
Example
n = 4
arr = [1, 3, 5, 7]
k = 2
x = 2
Valid pairs of indices:
(0, 2): arr[0] = 1, arr[2] = 5
Number of elements in [1, 5] divisible by 2 are 2: i.e. 2 and 4
(1, 3): arr[1] = 3, arr[3] = 7
Number of elements in [3, 7] divisible by 2 are 2: i.e. 4 and 6
There is no other pair of indices for which the given condition is true so the answer is 2.
Function Description
Complete the function countDivisiblePairs
in the editor below.
countDivisiblePairs has the following parameters:
int arr[n]: the given elements
int k: the count of elements to be divisible by x
int x: the divisor
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
