Can Every Package Fit in a Box
Updated
Problem statement
You are given two integer arrays:
packages, wherepackages[i]is the size of thei-th package.boxes, whereboxes[j]is the capacity of thej-th box.
Each package must be placed into a distinct box, and each box can contain at most one package. A package of size p can fit into a box of capacity b when p <= b.
Return true if it is possible to assign every package to a different box so that all packages fit. Otherwise, return false.
Function
canFitPackages(packages: int[], boxes: int[]) → booleanExamples
Example 1
packages = [2, 3, 5]boxes = [3, 5, 6, 2]return = trueThe packages of sizes 2, 3, and 5 can be assigned to boxes with capacities 2, 3, and 5.
Example 2
packages = [2, 3, 5]boxes = [5, 3]return = falseThere are only two boxes but three packages, so at least one package cannot be assigned.
Constraints
1 <= packages.length, boxes.length <= 2 * 10^51 <= packages[i], boxes[j] <= 10^9
More IMC Trading Online Assessment questions
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
- Choose ContainersOA · Seen Aug 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Sub-matrix SumsOA · Seen Jul 2026
- Minimum Space Wasted From PackagingOA · Seen Sep 2025
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
- Get Maximum PairsAmazon · OA
- Find Maximum GreatnessTwilio · OATwilio interview questions
- Binge WatchingVanguard · OAVanguard interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Find Minimum Possible SizeMathWorks · OAMathWorks interview questions