Find Number of Ways to Group Parcels (Also for Amazon Japan)
Learn this problemProblem statement
In one of the warehouses of Amazon, a pan balance is used to weigh and load the parcels for delivery.
A pan balance has 2 pans, and each of the pans can contain one parcel. Due to some defect, one of the pans shows an extra erroneous weight wt. A pair of parcels is said to be balanced if they show the same weight on the pan balance. Since one of the pans is heavier by the amount wt, the absolute difference in weight of the parcels has to be wt.
Given the weights of n parcels, weight[n], and the erroneous weight wt, find the number of ways to group these parcels into pairs such that every pair of the group is balanced. Since the answer can be large, compute it modulo (109 + 7). Technically, the task is to find out the number of pairs that can be formed from the weight array which have an absolute difference equal to wt.
If there are no such pairs, you have to return 0.
Note:
- A parcel cannot be present in more than one pair in a group.
- Two groups are different if at least one of their pairs contains a different pair of parcels. The pairs at indices (i, j) and (j, i) are considered the same.
- If there are no such pair, you have to return 0.
Function
numberOfWaysToGroupParcels(weight: int[], wt: int) → int
Complete the function numberOfWaysToGroupParcels in the editor.
numberOfWaysToGroupParcels has the following parameters:
int weight[n]: an array of integers representing the weights of the parcelsint wt: the erroneous weight shown by one of the pans
Returns
int: the number of ways to group the parcels into balanced pairs modulo (109 + 7)
Examples
Example 1
weight = [4, 5, 5, 4, 4, 5, 2, 3]wt = 1return = 6wt = 1. For example, consider the group {(1, 6), (4, 2), (5, 3), (7, 8)}.
Constraints
Unknown for now 🙉More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026