1. Question 1
There is an integer array arr[n]
and an integer value d
. The array is indexed from 1 to n
.
Count the number of distinct triplets (i, j, k)
such that 0 < i < j < k ≤ n
and the sum a[i] + a[j] + a[k]
is divisible by d
.
Example:
a = [3, 3, 4, 7, 8]
d = 5
The following triplets are divisible by d = 5
. Following are the triplets whose sum is divisible by d
(1-based indexing):
- indices (1, 2, 3), sum = 3+3+4 = 10
- indices (1, 3, 5), sum = 3+4+8 = 15
- indices (2, 3, 4), sum = 3+4+8 = 15
Since there is no other triplet divisible by d = 5
, return 3.
Function Description: Complete the function getTripletCount
in the editor below.
getTripletCount
has the following parameters:
int arr[n]
: an array of integersint d
: an integer
Returns:
int
: the number of distinct triplets
Constraints:
3 ≤ n ≤ 10^3
1 ≤ a[i] ≤ 10^9
2 ≤ d ≤ 10^6
2. Question 2
An ecommerce website admin panel needs to generate a report to display product stock status in their warehouse. The report should display a list of all product categories and the total number of products available in each category. It should be limited to products with more than 10 units available.
The result should have the following columns: category | title | total_stock
.
category
- the name of the product category (e.g., Electronics, Clothing)title
- the title of the producttotal_stock
- total number of items available in stock for that product
The result should be sorted in ascending order by category
, then in ascending order by title
, and finally in descending order by total_stock
.
Note:
- Only products with a total stock of more than 10 items should be included in the report.
联系我来获取完整的题目信息和解题思路,我们可以协助您解决任何OA VO