Allowed R6 · Within policy
{
"slug": "package-pair-sums",
"title": "Package Pair Sums",
"difficulty": "easy",
"tags": [
"coding",
"oa",
"swe",
"intern"
],
"is_free": true,
"locked": false,
"frequency": 1,
"last_reported_at": "2026-08-24T11:54:04.391543Z",
"url": "https://www.mokabla.com/en/c/amazon/package-pair-sums",
"agent": {
"page": "https://www.mokabla.com/agent/en/c/amazon/package-pair-sums",
"question": "https://www.mokabla.com/agent/_call/get_question?company=amazon&question=package-pair-sums"
},
"company": {
"slug": "amazon",
"name_en": "Amazon (Egypt / MENA)"
},
"body_md": "## Problem\nA delivery van has a remaining weight capacity `cap`. You are given the weights of the packages still on the dock and must choose **exactly two** of them so that their combined weight is as large as possible without exceeding `cap`. Return the indices of every pair that achieves that best total (there may be several). If no pair fits, return an empty list.\n\nThis is the first problem on the Amazon SDE online assessment for Egypt and MENA; it is graded on hidden tests including ties and duplicates.\n\n## Examples\n**Example 1**\nInput: `weights = [10, 30, 25, 15, 20]`, `cap = 45`\nOutput: `[[2, 4]]`, 25 + 20 = 45 is the best total; 30 + 15 also equals 45, so the full answer is `[[1, 3], [2, 4]]`. Return both pairs.\n\n**Example 2**\nInput: `weights = [50, 60]`, `cap = 40`\nOutput: `[]`, no two packages fit.\n\n## Constraints\n- 2 ≤ n ≤ 10^5, 1 ≤ weight ≤ 10^6\n- Indices in each pair ascending; pairs sorted by first index\n- Target O(n log n); O(n²) will time out on the largest hidden test\n\n## What they look for\nSort with original indices attached, two pointers for the best sum, then a second pass (or a hash map) to collect every pair matching the best total. Handling the \"many equal weights\" case without blowing up to O(n²) output is the subtle part, say what you would do if the output itself is huge.",
"follow_ups_md": "- Choose three packages instead of two.\n- The van has two compartments with separate capacities.\n- What if weights arrive as a stream and you must answer after each one?",
"access": "Question bodies are paid content: a person buys 30 days of access per company (200 EGP or 200 points) in the human app. Agents get titles, tags and difficulty; bodies only for free questions."
}