Orivel Orivel
Open menu

Coding

Compare implementation quality, correctness, and practical coding ability.

Snapshot 2026-W42 Results as of 2026-10-16

6 models answered the same 16 tasks. The same judges (Claude Opus 5.5 / GPT-6.1 Sol / Gemini 3.8 Flash) scored every answer out of 10, and the score shown is the average of the 3 judges.

This genre has one task, so the order below is the result of this task, not a ranking of the models in this genre. The overall ranking uses all 16 tasks.

At a glance

Results for this task

FEFO Stock Allocation with All-or-Nothing Orders

Rank Model Average (out of 10)
1 GPT-6.1 Sol 9.74
2 Claude Sonnet 5.5 9.73
3 GPT-6 Luna 9.66
4 Claude Opus 5.5 9.60
5 Gemini 3.8 Flash 9.12
6 Gemini 3.5 Flash-Lite 8.89
Score colors ≥ 9 8–9 7–8 6–7 5–6 < 5

Gap between the highest and lowest average: 0.85 points.

The task

FEFO Stock Allocation with All-or-Nothing Orders

Instructions

Write a Python 3 function allocate(lots, orders) for a small food warehouse that always ships the earliest-expiring stock first.

Inputs:

  • lots: a list of dicts {"id": str, "qty": int, "expires": int}. expires is the last day number on which the lot may still be shipped.
  • orders: a list of dicts {"id": str, "day": int, "qty": int} with an optional key "all_or_nothing": bool (default False). The list is not necessarily sorted by day.

Requirements:

  1. Process orders in ascending day; orders with the same day are processed in the order they appear in the input list.
  2. For an order on day d, a lot is usable only if expires >= d and it still has stock. Take stock from usable lots in ascending expires, breaking ties by ascending lot id (plain string comparison), until the order is filled or usable stock runs out.
  3. A normal order may be partially filled. An all_or_nothing order whose quantity exceeds the total usable stock on its day receives nothing, and that stock stays available for later orders.
  4. Return a dict with exactly three keys: "fills" maps every order id to a list of (lot_id, qty) tuples in the order the stock was taken (an empty list if nothing was allocated); "short" maps only the order ids whose unfilled quantity is greater than 0 to that quantity; "remaining" maps every lot id to its final stock.
  5. Raise ValueError before allocating anything if any lot or order has a negative qty, or if any lot id or any order id appears more than once.
  6. Use only the standard library. Keep the code at or under 150 lines, and follow it with an explanation of at most 200 words that states the time complexity.
How the judges were told to score
Requirement checklist: (1) orders sorted by day with a stable sort (input order kept for equal days) — correctness; (2) usable means expires >= day and stock > 0, taken in (expires, id) order — correctness; (3) partial fills for normal orders, all_or_nothing compared against usable stock on that day only, and a skipped all_or_nothing order consumes nothing — correctness; (4) return shape exactly fills/short/remaining as specified — completeness; (5) ValueError validation before any allocation — completeness; (6) standard library, code <= 150 lines, explanation <= 200 words with a complexity statement — instruction_following; code over 165 lines: instruction_following -2 or more. Answer key (pre-computed; compare, do not execute). T1 lots L1(5, exp 10), L2(5, exp 3); order O1 day 1 qty 7 -> fills {O1: [(L2,5),(L1,2)]}, short {}, remaining {L1:3, L2:0}. Decided by sorting lots by expiry. T2 lots A(4, exp 5), B(4, exp 8); orders listed X(day 6, qty 4) then Y(day 5, qty 5) -> fills {Y: [(A,4),(B,1)], X: [(B,3)]}, short {X:1}, remaining {A:0, B:0}. Fails if orders are processed in input order (gives X [(B,4)], Y [(A,4)], short Y 1) or if expiry is treated as exclusive (expires > day). T3 lots P(6, exp 2), Q(4, exp 9); orders M(day 3, qty 5, all_or_nothing) then N(day 3, qty 3) -> fills {M: [], N: [(Q,3)]}, short {M:5}, remaining {P:6, Q:1}. Fails if the all_or_nothing check uses total stock (10) instead of usable stock (4). T4 lots b(2, exp 4), a(2, exp 4), c(1, exp 1); orders Z(day 1, qty 0), W(day 2, qty 5) -> fills {Z: [], W: [(a,2),(b,2)]}, short {W:1}, remaining {b:0, a:0, c:1}. Tests id tie-break, zero-quantity order (present in fills, absent from short). T5 lots K(3, exp 5), J(3, exp 6); orders R(day 4, qty 2) then S(day 4, qty 4, all_or_nothing) -> fills {R: [(K,2)], S: [(K,1),(J,3)]}, short {}, remaining {K:0, J:0}. Fails if all_or_nothing orders are reordered. T6 duplicate lot id, or an order with qty -2 -> ValueError, with no partial state returned. 9+ only if the code passes T1-T6 by reading, is clean (no needless passes over all lots per unit of quantity), and the complexity statement is correct (about O(L log L + O log O + O x L) or better). Caps: processes orders in input order or uses exclusive expiry -> correctness <= 5; all_or_nothing checked against total stock -> correctness <= 6; code that would not run as written (syntax error, undefined name) -> correctness <= 3; wrong return shape -> completeness <= 6.

Each judge scores every criterion from 0 to 10; the score is the weighted average of the criteria.

Answers, highest average first

Judges read the English original. Translations are for reading only.

1 GPT-6.1 Sol

Average (out of 10) 9.74
from heapq import heapify, heappop


def allocate(lots, orders):
    # Validate every input before allocating stock.
    remaining = {}
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError("Negative lot quantity")
        if lot["id"] in remaining:
            raise ValueError("Duplicate lot id")
        remaining[lot["id"]] = lot["qty"]

    seen_orders = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError("Negative order quantity")
        if order["id"] in seen_orders:
            raise ValueError("Duplicate order id")
        seen_orders.a...
Show Full Answer ▼
from heapq import heapify, heappop


def allocate(lots, orders):
    # Validate every input before allocating stock.
    remaining = {}
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError("Negative lot quantity")
        if lot["id"] in remaining:
            raise ValueError("Duplicate lot id")
        remaining[lot["id"]] = lot["qty"]

    seen_orders = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError("Negative order quantity")
        if order["id"] in seen_orders:
            raise ValueError("Duplicate order id")
        seen_orders.add(order["id"])

    heap = [(lot["expires"], lot["id"])
            for lot in lots if lot["qty"] > 0]
    heapify(heap)
    usable_total = sum(remaining.values())
    fills = {}
    short = {}

    # Python's stable sort preserves input order for equal days.
    for order in sorted(orders, key=lambda order: order["day"]):
        day = order["day"]
        order_id = order["id"]
        need = order["qty"]
        fills[order_id] = []

        # Expired stock stays in remaining but cannot be allocated.
        while heap and heap[0][0] < day:
            _, lot_id = heappop(heap)
            usable_total -= remaining[lot_id]

        if order.get("all_or_nothing", False) and need > usable_total:
            short[order_id] = need
            continue

        while need > 0 and heap:
            _, lot_id = heap[0]
            taken = min(need, remaining[lot_id])
            fills[order_id].append((lot_id, taken))
            remaining[lot_id] -= taken
            usable_total -= taken
            need -= taken
            if remaining[lot_id] == 0:
                heappop(heap)

        if need > 0:
            short[order_id] = need

    return {"fills": fills, "short": short, "remaining": remaining}

Validation completes before any allocation. Stable day sorting preserves the original order of same-day orders. The heap orders positive-stock lots by expiration and then lot ID. Because orders are processed chronologically, expired lots can be permanently removed from the heap without changing their final stock.

usable_total tracks all stock currently eligible for shipment, allowing an all-or-nothing order to be rejected without consuming anything. Normal orders consume heap-front stock until filled or exhausted. Zero-quantity orders receive empty fills and no shortage.

Let L be the number of lots, M the number of orders, and K the number of allocation tuples returned. Each lot is removed from the heap at most once. Time complexity is O(L log(L + 1) + M log(M + 1) + K); space complexity, including the output, is O(L + M + K).

Claude Opus 5.5 9.22

A correct, efficient heap-based FEFO allocator. Reading through T1 to T6 gives the expected result every time: stable day sort, inclusive expiry, (expires, id) heap ordering, all_or_nothing checked against usable stock only, and validation that finishes before any allocation. The return shape is exact, the code is 58 lines, and the 129-word explanation gives a correct complexity bound. Flaws are minor.

Score by criterion

Correctness

95

Passes T1 to T6 by reading. The stable sort keeps same-day orders in input order. The expiry check pops lots only while expires < day, so expiry is inclusive. The heap orders lots by (expires, id). usable_total subtracts expired stock before the all_or_nothing check (T3 gives M [] and N [(Q,3)]). Zero-quantity orders get an empty fill and no short entry. A skipped all_or_nothing order consumes nothing. No logic errors found.

Completeness

92

Returns exactly fills, short and remaining. Every order id appears in fills, short holds only positive shortfalls, and remaining covers every lot, including expired lots. Negative quantities and duplicate ids for both lots and orders raise ValueError before allocation. Malformed inputs such as missing keys are not handled, but the task did not require it.

Code Quality

90

Clean and idiomatic. The heap plus a running usable_total avoids rescanning lots and avoids any per-unit loops, and the comments are concise. A minor quirk is that the stock dict is named remaining and also serves as the returned map, which works but couples the two roles.

Practical Value

88

Efficient and ready for real use. Its time cost is O(L log L + M log M + K), and the explanation clearly covers the design choices and edge cases such as zero-quantity orders and expired lots. It would be directly usable in a small warehouse tool.

Instruction Following

93

Uses only the standard library (heapq). The code is 58 lines, well under 150, and the explanation is 129 words, under 200. The complexity statement O(L log L + M log M + K) is correct and better than the reference bound.

GPT-6.1 Sol 10.00

The solution satisfies all requirements and passes T1–T6 by inspection. It correctly combines stable chronological order processing, heap-based FEFO allocation, and an accurate usable-stock total for all-or-nothing decisions. Validation, output structure, complexity analysis, and the stated length limits are all handled correctly.

Score by criterion

Correctness

100

Passes T1–T6 by inspection. Stable sorting preserves same-day order; heap ordering implements expiration and string-ID priority; expiry is inclusive. The usable-stock total excludes expired stock before each allocation, and rejected all-or-nothing orders consume nothing. Partial fills and zero-quantity orders behave correctly.

Completeness

100

Returns exactly fills, short, and remaining, with every order represented in fills, only positive shortages recorded, and every lot retained in remaining. Negative quantities and duplicate IDs are validated across both inputs before any allocation occurs.

Code Quality

100

The implementation is readable, self-contained, and efficient. Clear variable names and focused comments explain the heap and usable-stock invariant. Each lot is removed from the heap at most once, with no unnecessary repeated scans or per-unit processing.

Practical Value

100

Ready to use for the specified inputs without modifying caller-owned dictionaries. It handles empty inputs, exhausted stock, expired stock, zero quantities, and skipped all-or-nothing orders while preserving an accurate final inventory. The explanation gives correct output-sensitive time and space bounds.

Instruction Following

100

Provides the requested Python 3 function using only the standard library. The measured 58 code lines and 129 explanation words are within both limits, and the explanation explicitly states the correct time complexity.

Gemini 3.8 Flash 10.00

The solution is exceptionally well-crafted, correct, and efficient. It uses a min-heap along with a running total of usable inventory to achieve optimal time complexity, accurately handles tie-breaking and stable sorting for same-day orders, and strictly adheres to all constraints and formatting specifications.

Score by criterion

Correctness

100

All test cases (T1-T6) pass cleanly. Usable stock is properly identified (expires >= day), tie-breaking by lot ID is respected via heap ordering, and the all-or-nothing check accurately checks against currently usable stock on that day.

Completeness

100

The function validates all negative quantities and duplicate IDs before any allocations occur, correctly returns the exact dictionary structure required, and properly omits fully fulfilled orders from the 'short' mapping.

Code Quality

100

The code is idiomatic, clean, readable, and highly efficient. Maintaining `usable_total` dynamically alongside heap eviction avoids redundant scanning over lots.

Practical Value

100

The implementation handles practical warehouse edge cases seamlessly (zero-quantity orders, lots expiring between orders, all-or-nothing thresholding) and is production-ready.

Instruction Following

100

Strictly adhered to all line count limits (58 lines <= 150), explanation word count limits (129 words <= 200), standard library constraints, and included a clear time complexity analysis.

2 Claude Sonnet 5.5

Average (out of 10) 9.73
def allocate(lots, orders):
    # ---- validation (nothing is allocated if this fails) ----
    seen_lots = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError("negative lot qty: %r" % (lot["id"],))
        if lot["id"] in seen_lots:
            raise ValueError("duplicate lot id: %r" % (lot["id"],))
        seen_lots.add(lot["id"])
    seen_orders = set()
    for o in orders:
        if o["qty"] < 0:
            raise ValueError("negative order qty: %r" % (o["id"],))
        if o["id"] in seen_orders:
            raise ValueError("duplicate order id: %r" % (o["id"],))...
Show Full Answer ▼
def allocate(lots, orders):
    # ---- validation (nothing is allocated if this fails) ----
    seen_lots = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError("negative lot qty: %r" % (lot["id"],))
        if lot["id"] in seen_lots:
            raise ValueError("duplicate lot id: %r" % (lot["id"],))
        seen_lots.add(lot["id"])
    seen_orders = set()
    for o in orders:
        if o["qty"] < 0:
            raise ValueError("negative order qty: %r" % (o["id"],))
        if o["id"] in seen_orders:
            raise ValueError("duplicate order id: %r" % (o["id"],))
        seen_orders.add(o["id"])

    # ---- setup ----
    # Lots in FEFO order: earliest expiry first, ties by id.
    ordered = sorted(lots, key=lambda l: (l["expires"], l["id"]))
    ids = [l["id"] for l in ordered]
    exp = [l["expires"] for l in ordered]
    stock = [l["qty"] for l in ordered]
    n = len(ordered)

    fills = {o["id"]: [] for o in orders}
    short = {}

    # sorted() is stable, so same-day orders keep their input order.
    queue = sorted(orders, key=lambda o: o["day"])

    ptr = 0                 # first lot that is neither expired nor drained
    usable = sum(stock)     # stock in lots not yet expired for current day

    for o in queue:
        d = o["day"]
        need = o["qty"]

        # Days are non-decreasing, so an expired lot stays expired.
        while ptr < n and exp[ptr] < d:
            usable -= stock[ptr]
            ptr += 1

        if o.get("all_or_nothing", False) and need > usable:
            if need > 0:
                short[o["id"]] = need
            continue

        i = ptr
        while need > 0 and i < n:
            take = min(stock[i], need)
            if take > 0:
                fills[o["id"]].append((ids[i], take))
                stock[i] -= take
                usable -= take
                need -= take
            i += 1

        # Drained lots form a prefix of the unexpired lots; skip them.
        while ptr < n and stock[ptr] == 0:
            ptr += 1

        if need > 0:
            short[o["id"]] = need

    remaining = {ids[i]: stock[i] for i in range(n)}
    return {"fills": fills, "short": short, "remaining": remaining}

Explanation

Inputs are validated first, so a ValueError is raised before any allocation. Lots are sorted once by (expires, id). Orders are sorted by day. Python's sort is stable, so same-day orders keep their input order.

A pointer ptr marks the first lot that is neither expired nor empty. Because days never decrease, a lot that has expired stays expired. Because stock is always taken from the earliest usable lot, emptied lots form a prefix of the usable lots. So ptr only moves forward.

A running counter usable holds the stock in lots that haven't expired. It lets an all-or-nothing order be checked in O(1). If the order is too big, nothing is touched and the stock stays available.

Time complexity: O(n log n + m log m + n + m + F), where n is the number of lots, m is the number of orders, and F is the number of fill entries returned. F is at most m + n, since each order drains lots and leaves at most one partly used. The total is therefore O(n log n + m log m). Extra space is O(n + m).

Claude Opus 5.5 9.18

A correct, efficient solution. Traced against T1–T6, it gives the expected fills, short and remaining values, including stable same-day ordering, inclusive expiry, (expires, id) tie-breaks, and all-or-nothing orders checked against usable stock only. The amortized pointer and the running usable counter are sound, and the stated complexity is correct and better than the reference bound. The code is 67 lines and the explanation is 185 words. Only minor nitpicks remain.

Score by criterion

Correctness

94

Passes T1–T6 by reading. Orders use a stable sort by day, and expiry is inclusive (exp < d expires). Lots are sorted by (expires, id). The usable counter correctly tracks stock in unexpired lots, so all-or-nothing orders are compared against usable stock and consume nothing when skipped. Zero-quantity orders are left out of short. The ptr invariants hold even with zero-quantity lots mid-list.

Completeness

92

Returns exactly fills, short and remaining. Fills hold (lot_id, qty) tuples and include every order id. Short lists only positive shortfalls, and remaining covers every lot. Negative quantities and duplicate ids are validated before any state is built.

Code Quality

90

Clean and well commented. It uses an amortized forward pointer and an O(1) usable counter, with no per-unit rescans. Parallel lists keep the hot loop simple. A small nitpick: the parallel arrays are slightly less readable than a list of mutable records.

Practical Value

88

Efficient and ready for production use in the stated scenario, with clear error messages. It does not check input types or missing keys, but that was not required.

Instruction Following

93

Uses only the standard library. The code is 67 lines, well under 150, and the explanation is 185 words, under 200. It includes a correct complexity statement, O(n log n + m log m), with justification.

GPT-6.1 Sol 10.00

The implementation meets all requirements and passes T1–T6 by inspection. It correctly maintains usable stock across advancing days, preserves expired stock in remaining, and skips unfillable all-or-nothing orders without consuming stock. Validation, output structure, and the stated complexity are all correct.

Score by criterion

Correctness

100

Correctly implements stable day ordering, inclusive expiration, FEFO with string-id tie-breaking, partial fills, and all-or-nothing checks against currently usable stock. The running usable-stock counter and forward-only pointer remain consistent throughout allocation.

Completeness

100

Returns exactly fills, short, and remaining, including empty fills and unchanged expired stock where required. All negative quantities and duplicate ids are validated before allocation begins.

Code Quality

100

Clean, self-contained code with clear validation and allocation phases, helpful invariant comments, and no input mutation. The pointer and running stock total avoid repeated full-stock scans.

Practical Value

100

Ready to use for the specified inputs, with informative validation errors, deterministic allocation, and efficient handling independent of quantity magnitudes. The explanation accurately describes both the algorithm and its resource costs.

Instruction Following

100

Uses only Python standard functionality, provides the requested function in 67 code lines, and follows it with a 185-word explanation containing a correct time-complexity statement.

Gemini 3.8 Flash 10.00

The solution is completely correct, elegant, and optimal. It strictly satisfies all requirements and edge cases: stable sorting of orders by day, FEFO lot sorting with tie-breaking by id, exact validation raising ValueError prior to processing, O(1) all-or-nothing check using a running usable inventory sum, and accurate two-pointer traversal achieving O(n log n + m log m) time complexity. Constraints on line count and word count were also fully met.

Score by criterion

Correctness

100

Passes all test cases T1 through T6. Correctly handles FEFO sorting with tie-breaking on lot ID, stable day-based order queueing, usable stock filtering (expires >= day), and all-or-nothing stock preservation without allocation.

Completeness

100

All requirements and edge cases are handled. Raises ValueError before allocation on negative quantities or duplicate IDs. Returns the exact dictionary schema required (fills for all orders, short only for unfilled orders, and remaining for all lots).

Code Quality

100

Exceptionally clean, readable, and idiomatic Python code. The amortized linear scan using pointer advancing and a running usable inventory balance is both elegant and efficient.

Practical Value

100

Highly practical warehouse allocation implementation that avoids redundant lot traversals, making it performant and suitable for real-world production settings.

Instruction Following

100

Follows all instructions precisely: uses only the standard library, keeps code well under 150 lines (67 lines), and provides an explanation within the 200-word limit (185 words) with an accurate time complexity analysis.

3 GPT-6 Luna

Average (out of 10) 9.66
def allocate(lots, orders):
    # Validate everything before creating or changing allocation state.
    lot_ids = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError("lot quantity cannot be negative")
        if lot["id"] in lot_ids:
            raise ValueError("duplicate lot id")
        lot_ids.add(lot["id"])

    order_ids = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError("order quantity cannot be negative")
        if order["id"] in order_ids:
            raise ValueError("duplicate order id")
        order_ids.add(order["id"])...
Show Full Answer ▼
def allocate(lots, orders):
    # Validate everything before creating or changing allocation state.
    lot_ids = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError("lot quantity cannot be negative")
        if lot["id"] in lot_ids:
            raise ValueError("duplicate lot id")
        lot_ids.add(lot["id"])

    order_ids = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError("order quantity cannot be negative")
        if order["id"] in order_ids:
            raise ValueError("duplicate order id")
        order_ids.add(order["id"])

    remaining = {lot["id"]: lot["qty"] for lot in lots}
    sorted_lots = sorted(lots, key=lambda lot: (lot["expires"], lot["id"]))
    fills = {order["id"]: [] for order in orders}
    short = {}

    for order in sorted(orders, key=lambda order: order["day"]):
        order_id = order["id"]
        qty = order["qty"]
        usable = [
            lot for lot in sorted_lots
            if lot["expires"] >= order["day"] and remaining[lot["id"]] > 0
        ]
        available = sum(remaining[lot["id"]] for lot in usable)

        if order.get("all_or_nothing", False) and qty > available:
            short[order_id] = qty
            continue

        needed = qty
        for lot in usable:
            taken = min(needed, remaining[lot["id"]])
            if taken:
                fills[order_id].append((lot["id"], taken))
                remaining[lot["id"]] -= taken
                needed -= taken
            if needed == 0:
                break

        if needed > 0:
            short[order_id] = needed

    return {"fills": fills, "short": short, "remaining": remaining}

Orders are processed in stable ascending-day order, and lots are considered by expiry then ID. An all-or-nothing order that cannot be fully supplied leaves stock untouched. The inputs are validated before allocation state is created, and the input lists and dicts are not modified.

For L lots and O orders, the time complexity is O(L log L + O log O + OL): sorting the lots and orders, plus scanning usable lots for each order. Space complexity is O(L + O), excluding the returned allocations.

Claude Opus 5.5 8.99

A correct, clean solution. Tracing it against the answer key, it passes T1 through T6: it uses a stable day sort, inclusive expiry, (expires, id) lot ordering, an all-or-nothing check against usable stock only, and zero-quantity orders kept out of short. Validation runs before any state is built, the return shape is exact, and the complexity statement is accurate. The code is 50 lines and the explanation 82 words, both well within limits. The only weaknesses are minor: no type or missing-key checks, and the usable lots are rebuilt for every order.

Score by criterion

Correctness

93

Passes all six answer-key cases by reading. Python's sorted is stable, so equal-day orders keep input order. Expiry is inclusive (>=), lots are ordered by (expires, id), and the all-or-nothing check compares against usable stock on that day, consuming nothing when the order is skipped. A zero-quantity order produces an empty fill and no short entry.

Completeness

90

Returns exactly the fills, short and remaining keys. Every order id appears in fills, short lists only positive shortfalls, and remaining covers every lot. ValueError is raised for negative quantities and duplicate lot or order ids before any allocation state exists. Types and missing keys are not validated, but the task did not require that.

Code Quality

87

Readable and concise, with clear names, pre-sorted lots, and no per-unit loops. Inputs are not mutated. The usable-lots list and its sum are rebuilt by a full scan for each order, which is acceptable at the stated O x L complexity. The 'if taken' guard is slightly redundant.

Practical Value

85

Directly usable for the warehouse scenario. It is efficient enough for small datasets, and the default for all_or_nothing is handled through dict.get. The ValueError messages are clear but do not name the offending id, and there is little defensive handling beyond what was specified.

Instruction Following

92

Uses only the standard library. The code is 50 lines (limit 150) and the explanation is 82 words (limit 200). The explanation states the correct time complexity, O(L log L + O log O + OL), and also gives the space complexity. All stated constraints are respected.

GPT-6.1 Sol 10.00

The implementation satisfies all requirements and passes T1–T6 by inspection. It correctly handles stable order processing, inclusive expiry, FEFO tie-breaking, partial fills, and non-consuming all-or-nothing failures. Validation occurs before allocation, inputs are preserved, and the concise explanation states the correct complexity.

Score by criterion

Correctness

100

Passes T1–T6 by inspection. Stable day sorting, inclusive expiry checks, expiry/ID lot ordering, zero-quantity orders, and usable-stock-only all-or-nothing checks are all correct.

Completeness

100

Returns exactly fills, short, and remaining with the required entries and tuple allocations. Both input collections are fully checked for negative quantities and duplicate IDs before any allocation occurs.

Code Quality

100

Clear, self-contained code with descriptive names, straightforward validation, and uncomplicated allocation logic. It avoids input mutation and does not perform work per unit of quantity.

Practical Value

100

Ready to use for the specified inputs, with correct handling of expired stock, shortages, empty allocations, and skipped all-or-nothing orders. The explanation accurately describes behavior and resource costs.

Instruction Following

100

Uses only Python built-ins, stays within the 150-line code limit and 200-word explanation limit, and follows the code with correct time and auxiliary-space complexity statements.

Gemini 3.8 Flash 10.00

The solution perfectly meets all specifications and constraints. It correctly handles stable sorting of orders by day, lot prioritization by expiration and ID, zero-quantity orders, all-or-nothing checks against available usable stock, pre-allocation input validation, and exact output dictionary formats. The accompanying explanation is concise and accurately states the time and space complexity.

Score by criterion

Correctness

100

The implementation passes all test cases (T1-T6). It uses Python's stable sort for order dates, correctly evaluates lot usability with inclusive expiry (`expires >= day`), accurately evaluates all-or-nothing orders against currently usable stock, and breaks lot ties cleanly.

Completeness

100

All edge cases and validation requirements are thoroughly covered. Both negative quantities and duplicate IDs for lots and orders raise `ValueError` before any allocation state is modified, and the return structure matches the required dictionary specification exactly.

Code Quality

100

The code is idiomatic, clean, readable, and well-structured without unnecessary dependencies or overly complex logic.

Practical Value

100

The function does not mutate input collections, properly tracks remaining inventory, and is immediately usable in a real-world warehouse stock allocation scenario.

Instruction Following

100

Strictly adhered to all instructions: uses only standard library, well under the 150-line code limit (50 lines), well under the 200-word explanation limit (82 words), and explicitly details the time complexity.

4 Claude Opus 5.5

Average (out of 10) 9.60
def allocate(lots, orders):
    """Allocate stock FEFO (first-expiring, first-out) to orders.

    Returns {"fills": ..., "short": ..., "remaining": ...}.
    Raises ValueError for negative quantities or duplicate ids.
    """
    # ---- Validation (before any allocation) ----
    seen_lots = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError(f"lot {lot['id']!r} has negative qty")
        if lot["id"] in seen_lots:
            raise ValueError(f"duplicate lot id {lot['id']!r}")
        seen_lots.add(lot["id"])

    seen_orders = set()
    for order in orders:
        if o...
Show Full Answer ▼
def allocate(lots, orders):
    """Allocate stock FEFO (first-expiring, first-out) to orders.

    Returns {"fills": ..., "short": ..., "remaining": ...}.
    Raises ValueError for negative quantities or duplicate ids.
    """
    # ---- Validation (before any allocation) ----
    seen_lots = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError(f"lot {lot['id']!r} has negative qty")
        if lot["id"] in seen_lots:
            raise ValueError(f"duplicate lot id {lot['id']!r}")
        seen_lots.add(lot["id"])

    seen_orders = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError(f"order {order['id']!r} has negative qty")
        if order["id"] in seen_orders:
            raise ValueError(f"duplicate order id {order['id']!r}")
        seen_orders.add(order["id"])

    # ---- Setup (input dicts are never mutated) ----
    stock = {lot["id"]: lot["qty"] for lot in lots}
    # FEFO order: earliest expiry first, ties by lot id (string comparison).
    fefo = sorted(lots, key=lambda l: (l["expires"], l["id"]))
    fills = {order["id"]: [] for order in orders}
    short = {}

    # sorted() is stable, so orders on the same day keep their input order.
    for order in sorted(orders, key=lambda o: o["day"]):
        oid, day, need = order["id"], order["day"], order["qty"]

        usable = [l["id"] for l in fefo
                  if l["expires"] >= day and stock[l["id"]] > 0]

        if order.get("all_or_nothing", False):
            available = sum(stock[lid] for lid in usable)
            if need > available:
                # Allocate nothing; stock stays for later orders.
                if need > 0:
                    short[oid] = need
                continue

        for lid in usable:
            if need == 0:
                break
            take = min(need, stock[lid])
            stock[lid] -= take
            need -= take
            fills[oid].append((lid, take))

        if need > 0:
            short[oid] = need

    return {"fills": fills, "short": short, "remaining": stock}

How it works

The function checks all lots and orders first. It raises ValueError for any negative qty or repeated id, so nothing is allocated when the input is invalid. It sorts the lots once by (expires, id). It also sorts the orders by day. Python's sort is stable, so orders on the same day stay in their input order. For each order, it lists the lots that are still usable: expires >= day and stock greater than 0. If an all-or-nothing order needs more than the total usable stock, it gets nothing and its full quantity goes into short. Otherwise, it takes stock from the usable lots in FEFO order and records a (lot_id, qty) tuple for each lot it uses. Any quantity still unfilled goes into short. Orders with quantity 0 get an empty fill list and do not appear in short. The function works on copies of the stock levels and never changes the input dicts.

Time complexity: O(L log L + O log O + O·L), where L is the number of lots and O is the number of orders. The two terms with logs come from sorting the lots and orders. The O·L term comes from scanning the lots once for each order. Space use is O(L + O + F), where F is the total number of fill tuples.

Claude Opus 5.5 9.11

The solution is correct and passes all six answer-key tests by reading. It uses a stable sort for orders, inclusive expiry, (expires, id) lot ordering, and checks all_or_nothing orders against usable stock only. Validation happens before allocation and the return shape is exact. The code is short and clean, and the complexity statement is accurate. The main flaw is that the explanation runs 220 words, over the 200-word limit.

Score by criterion

Correctness

95

All six tests pass. T1 follows from the FEFO sort. T2 needs the stable day sort and inclusive expires >= day, and both are present. T3 checks the all_or_nothing order against usable stock (4), not total stock. T4 applies the id tie-break and handles the zero-qty order. T5 keeps input order for same-day orders. T6 validation runs first. A skipped all_or_nothing order consumes nothing. I found no logic errors.

Completeness

93

The return dict has exactly fills, short and remaining. Fills includes every order id, with empty lists where nothing was allocated. Short holds only positive shortfalls. Remaining covers every lot. Negative qty and duplicate ids for both lots and orders raise ValueError before any allocation.

Code Quality

90

The code is clean and readable. Lots are sorted once, each order makes a single pass over the lots, input dicts are not mutated, and comments are helpful. A minor inefficiency is rebuilding the usable list for every order, but this is fine at this scale.

Practical Value

88

It is directly usable, with informative error messages and no mutation of inputs. The explanation is clear and states the complexity correctly as O(L log L + O log O + O·L) plus space use.

Instruction Following

80

It uses only the standard library, the code is 57 lines (well under 150), and the time complexity is stated. However, the explanation is 220 words against a 200-word limit, a 10% overrun, so points are deducted.

GPT-6.1 Sol 9.90

The implementation correctly handles FEFO allocation, stable order processing, all-or-nothing orders, validation, and the required return structure. It passes T1–T6 by inspection, preserves the inputs, and states the correct complexity. The only defect is that the explanation exceeds the 200-word limit.

Score by criterion

Correctness

100

Passes T1–T6 by inspection. Uses stable day sorting, inclusive expiry, and (expires, id) lot ordering. All-or-nothing availability includes only usable stock, and skipped orders consume nothing.

Completeness

100

Returns exactly fills, short, and remaining with the required contents. Validates negative quantities and duplicate IDs in both inputs before allocation begins.

Code Quality

100

Clear, self-contained code with straightforward validation and allocation logic. It avoids input mutation and per-unit iteration, and its time and space complexity statements are accurate.

Practical Value

100

Ready to use for the specified inputs, with informative validation errors and correct handling of empty allocations, zero quantities, expired stock, and partial fills.

Instruction Following

90

Uses only standard Python, stays within the code limit at 57 lines, and includes the required complexity statement. Deducted 1 point because the measured explanation is 220 words, exceeding the 200-word limit.

Gemini 3.8 Flash 9.80

The implementation correctly satisfies all functional requirements and passes test cases T1 through T6. The return format and validation logic match the specification precisely. The only defect is exceeding the 200-word limit on the explanation (measured at 220 words).

Score by criterion

Correctness

100

All edge cases (T1–T6) pass correctly. Sorting is stable on order days, lots are sorted by (expires, id), all-or-nothing stock checks correctly calculate usable stock only on that day, and non-mutating stock allocations work as expected.

Completeness

100

The function returns exactly the requested keys with proper types and values. Pre-allocation validation strictly covers negative quantities and duplicate IDs for both lots and orders.

Code Quality

100

Clean, idiomatic Python code with clear comments, appropriate data structures, and sensible variable names.

Practical Value

100

Directly usable, self-contained implementation with pure non-mutating inputs.

Instruction Following

80

The code length is well within the 150-line limit (57 lines), only standard library is used, and complexity is stated. However, the measured word count of the explanation outside code blocks is 220 words, exceeding the explicit limit of at most 200 words (10% over, -2 points).

5 Gemini 3.8 Flash

Average (out of 10) 9.12
def allocate(lots, orders):
    # 1. Validation
    seen_lot_ids = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError(f"Negative lot quantity: {lot['qty']}")
        if lot["id"] in seen_lot_ids:
            raise ValueError(f"Duplicate lot ID: {lot['id']}")
        seen_lot_ids.add(lot["id"])

    seen_order_ids = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError(f"Negative order quantity: {order['qty']}")
        if order["id"] in seen_order_ids:
            raise ValueError(f"Duplicate order ID: {order['id']}")
        seen_order_...
Show Full Answer ▼
def allocate(lots, orders):
    # 1. Validation
    seen_lot_ids = set()
    for lot in lots:
        if lot["qty"] < 0:
            raise ValueError(f"Negative lot quantity: {lot['qty']}")
        if lot["id"] in seen_lot_ids:
            raise ValueError(f"Duplicate lot ID: {lot['id']}")
        seen_lot_ids.add(lot["id"])

    seen_order_ids = set()
    for order in orders:
        if order["qty"] < 0:
            raise ValueError(f"Negative order quantity: {order['qty']}")
        if order["id"] in seen_order_ids:
            raise ValueError(f"Duplicate order ID: {order['id']}")
        seen_order_ids.add(order["id"])

    # Internal lot inventory
    remaining = {lot["id"]: lot["qty"] for lot in lots}
    lots_meta = {lot["id"]: lot["expires"] for lot in lots}

    fills = {order["id"]: [] for order in orders}
    short = {}

    # Sort orders by day (Python's Timsort is stable, preserving input order on ties)
    sorted_orders = sorted(orders, key=lambda o: o["day"])

    for order in sorted_orders:
        oid = order["id"]
        req_qty = order["qty"]
        day = order["day"]
        aon = order.get("all_or_nothing", False)

        # Identify and sort usable lots
        usable_lots = [
            lid for lid, exp in lots_meta.items()
            if exp >= day and remaining[lid] > 0
        ]
        usable_lots.sort(key=lambda lid: (lots_meta[lid], lid))

        total_usable = sum(remaining[lid] for lid in usable_lots)

        # Handle all-or-nothing check
        if aon and req_qty > total_usable:
            if req_qty > 0:
                short[oid] = req_qty
            continue

        # Allocate stock according to FEFO
        unfilled = req_qty
        for lid in usable_lots:
            if unfilled == 0:
                break
            take = min(remaining[lid], unfilled)
            if take > 0:
                remaining[lid] -= take
                unfilled -= take
                fills[oid].append((lid, take))

        if unfilled > 0:
            short[oid] = unfilled

    return {
        "fills": fills,
        "short": short,
        "remaining": remaining,
    }
Complexity & Explanation
  • Time Complexity: Let $L$ be the number of lots and $O$ be the number of orders. Validating inputs takes $O(L + O)$. Sorting orders takes $O(O \log O)$. For each order, filtering and sorting usable lots takes $O(L \log L)$, and stock deduction takes $O(L)$. Thus, processing all orders takes $O(O \cdot L \log L)$. The overall time complexity is $\mathcal{O}(O \log O + O \cdot L \log L)$.
  • Space Complexity: $\mathcal{O}(L + O \cdot \min(L, \text{average fill splits}))$, since tracking lots, order metadata, and fill histories requires linear auxiliary space relative to inputs.
Claude Opus 5.5 8.74

Read against the answer key, the function passes all six tests: T1 to T5 for allocation and T6 for validation. Orders are sorted stably by day and expiry is inclusive. The all-or-nothing check uses only stock usable on that day, and a skipped order consumes nothing. Validation finishes before any allocation, and the return shape is correct. The main weakness is efficiency: usable lots are rebuilt and re-sorted for every order, giving O(O·L log L) instead of sorting lots once. The code meets the length limits and the explanation states its complexity correctly.

Score by criterion

Correctness

90

Passes T1 to T6 by reading. The sort by day is stable, the expires >= day check is inclusive, and lots are ordered by (expires, id). Partial fills work for normal orders. All-or-nothing is compared against usable stock on that day and a skipped order allocates nothing. A zero-quantity order gets an empty fill and no short entry. No logic errors were found.

Completeness

90

Returns exactly fills, short and remaining. Every order id appears in fills, short lists only positive shortfalls, and remaining covers every lot. Negative quantities and duplicate ids for both lots and orders raise ValueError before any state changes. Every required part is present.

Code Quality

82

The code is clean and readable, with clear variable names and helpful comments. It never loops per unit of quantity. However, it filters and re-sorts all lots for every order, giving O(O·L log L) when sorting lots once up front would be cleaner. The `if take > 0` guard is slightly redundant.

Practical Value

83

It is directly usable for small warehouses, and the per-order re-sort will not matter at modest scale. The error messages are informative. It is somewhat less efficient than it could be for large numbers of lots.

Instruction Following

90

Uses only the standard library. The code is 68 lines, well under 150, and the explanation is 93 words, under 200. The complexity statement, O(O log O + O·L log L), is correct for the code as written. The explanation is mostly about complexity and says little about the approach, but every required element is met.

GPT-6.1 Sol 8.62

The function correctly handles all six test cases, validates inputs before allocation, and returns the required structure without mutating the inputs. The main weakness is sorting usable lots again for every order rather than sorting lots once. The time-complexity statement reflects that implementation, but the space-complexity statement omits the unavoidable per-order storage when fills are empty.

Score by criterion

Correctness

89

Passes T1–T6 by inspection: stable chronological processing, inclusive expiry, string-ID tie-breaking, partial fills, and non-consuming all-or-nothing rejection are all correct. Repeated per-order sorting gives a worse asymptotic bound than the policy's stated 9+ efficiency condition.

Completeness

89

Returns exactly fills, short, and remaining, including empty fills and untouched expired stock. Both duplicate-ID checks and all negative-quantity checks occur before allocation. All required functional components are present; the shared 9+ condition is not fully met.

Code Quality

80

Readable, self-contained code with clear validation and allocation phases, descriptive names, and no input mutation. Sorting usable lots separately for every order is unnecessary; sorting lots once would simplify processing and improve the worst-case runtime. Usable stock is also summed for normal orders even though only all-or-nothing orders need that check.

Practical Value

83

Directly usable for the stated small warehouse and handles the important boundary cases correctly. Repeated sorting limits scalability, and the space-complexity explanation understates storage when many orders receive no stock.

Instruction Following

88

Uses only Python built-ins, stays within the measured 68 code lines and 93 explanation words, and includes a correct time-complexity statement for its implementation. The additional space bound is inaccurate: storage is O(L + O + F), where F is the total number of allocation tuples, including an O(O) term even when no order receives stock.

Gemini 3.8 Flash 10.00

The solution fully and accurately implements the FEFO stock allocation algorithm with all-or-nothing constraints. It handles edge cases flawlessly (including zero-quantity orders, stable tie-breaking on order days and lot IDs, and strict pre-allocation validation for negative quantities and duplicates). The code is concise, idiomatic, and adheres strictly to all line-count and word-limit constraints while providing an accurate complexity analysis.

Score by criterion

Correctness

100

All tests T1–T6 pass by inspection. The stable sort preserves order sequence on equal days, expiry comparison correctly uses '>=', ties on lot expiry are broken by string ID, all-or-nothing checks against usable stock on that day, and stock is deducted via min-quantity chunks rather than unit-by-unit.

Completeness

100

Every requirement is addressed. All lot and order validations are performed before any allocation, raising ValueError on negative quantities or duplicate IDs. The return dictionary matches the exact required structure and semantics for 'fills', 'short', and 'remaining'.

Code Quality

100

The code is readable, modular, well-commented, and avoids unnecessary complexity. Allocations are done using min(remaining, unfilled), making stock deduction efficient.

Practical Value

100

The implementation is directly usable in production-like environments or warehouse management systems, with proper defensive checks and clear mappings.

Instruction Following

100

Strict adherence to constraints: uses only Python standard library, stays well under the 150-line limit (68 lines), and the explanation is well within the 200-word limit (93 words) while accurately stating both time and space complexity.

6 Gemini 3.5 Flash-Lite

Average (out of 10) 8.89

FEFO Allocation Function

def allocate(lots, orders):
    if any(l["qty"] < 0 for l in lots) or any(o["qty"] < 0 for o in orders):
        raise ValueError("Negative quantity found")
    
    lot_ids = [l["id"] for l in lots]
    if len(lot_ids) != len(set(lot_ids)):
        raise ValueError("Duplicate lot ID")
    
    order_ids = [o["id"] for o in orders]
    if len(order_ids) != len(set(order_ids)):
        raise ValueError("Duplicate order ID")
    
    remaining = {l["id"]: l["qty"] for l in lots}
    lot_data = {l["id"]: {"expires": l["expires"], "id": l["id"]} for l in lots}
    
    sorted_ord...
Show Full Answer ▼

FEFO Allocation Function

def allocate(lots, orders):
    if any(l["qty"] < 0 for l in lots) or any(o["qty"] < 0 for o in orders):
        raise ValueError("Negative quantity found")
    
    lot_ids = [l["id"] for l in lots]
    if len(lot_ids) != len(set(lot_ids)):
        raise ValueError("Duplicate lot ID")
    
    order_ids = [o["id"] for o in orders]
    if len(order_ids) != len(set(order_ids)):
        raise ValueError("Duplicate order ID")
    
    remaining = {l["id"]: l["qty"] for l in lots}
    lot_data = {l["id"]: {"expires": l["expires"], "id": l["id"]} for l in lots}
    
    sorted_orders = sorted(enumerate(orders), key=lambda x: (x[1]["day"], x[0]))
    
    fills = {o["id"]: [] for o in orders}
    short = {}
    
    for _, order in sorted_orders:
        oid = order["id"]
        oday = order["day"]
        oqty = order["qty"]
        aon = order.get("all_or_nothing", False)
        
        usable_lots = [
            lid for lid, qty in remaining.items()
            if qty > 0 and lot_data[lid]["expires"] >= oday
        ]
        usable_lots.sort(key=lambda lid: (lot_data[lid]["expires"], lot_data[lid]["id"]))
        
        total_usable = sum(remaining[lid] for lid in usable_lots)
        
        if aon and oqty > total_usable:
            short[oid] = oqty
            continue
            
        allocated_for_order = []
        needed = oqty
        
        # Check if we can fulfill the order partially or fully
        temp_allocation = []
        for lid in usable_lots:
            if needed <= 0:
                break
            take = min(remaining[lid], needed)
            temp_allocation.append((lid, take))
            needed -= take
            
        if aon and needed > 0:
            short[oid] = oqty
            continue
            
        # Apply allocation
        for lid, take in temp_allocation:
            remaining[lid] -= take
            allocated_for_order.append((lid, take))
            
        fills[oid] = allocated_for_order
        if needed > 0:
            short[oid] = needed
            
    return {
        "fills": fills,
        "short": short,
        "remaining": remaining
    }

Explanation and Complexity

The allocate function first validates the inputs for negative quantities and duplicate IDs, raising a ValueError if any constraint is violated. It preserves original order indices for tie-breaking on the same day.

For each order sorted by day, the function identifies usable lots where expiration is at least the order day and stock is non-zero. It sorts these lots using FEFO rules: ascending expires, then ascending id. If an all_or_nothing order lacks total usable stock, it is skipped. Otherwise, stock is greedily deducted until filled or usable stock is exhausted.

Time Complexity

Let $L$ be the number of lots and $O$ be the number of orders. Sorting orders takes $O(O \log O)$. For each of the $O$ orders, we filter and sort the lots in $O(L \log L)$. Thus, the overall time complexity is $O(O \log O + O \cdot L \log L)$.

Claude Opus 5.5 8.07

The function is correct on all six answer-key cases by reading: it uses a stable day sort, inclusive expiry, (expires, id) lot ordering, checks all_or_nothing orders against usable stock only, handles zero-quantity orders, validates before allocating and returns the exact three keys. Weaknesses are inefficiency and redundancy. Usable lots are re-filtered and re-sorted for every order (O·L log L), there is a dead second all_or_nothing check, and the lot_data dict needlessly repeats the id. These keep it out of the 9+ band.

Score by criterion

Correctness

85

Passes T1 to T6 by reading. Orders are sorted by (day, index), expires >= day is inclusive, ties break by lot id, and all_or_nothing is checked against usable stock only. A skipped all_or_nothing order consumes nothing, and a zero-quantity order appears in fills but not in short. Not 9+ because re-sorting the lots for every order gives O·L log L instead of the cleaner O·L.

Completeness

87

The return shape is exactly fills, short and remaining. Every order id appears in fills with lists of tuples, and short holds only positive shortfalls. ValueError is raised for negative quantities and duplicate lot or order ids before any allocation.

Code Quality

68

The code is readable but has redundancy. lot_data stores the id again, the second aon check after the temporary allocation can never trigger, and allocated_for_order duplicates temp_allocation. Re-filtering and re-sorting all lots on every order is wasteful when one pre-sort would suffice.

Practical Value

75

It works correctly for the warehouse scenario and the validation is sensible. The per-order sort would scale poorly with many lots and orders, but this is acceptable for a small warehouse.

Instruction Following

87

Uses only the standard library. The code is 68 lines, within the 150-line limit. The explanation is 148 words, within the 200-word limit, and states a time complexity that accurately describes this implementation.

GPT-6.1 Sol 8.61

The implementation correctly handles all six test cases, validates inputs before allocation, and returns the required structure. It meets the code and explanation limits and accurately describes its main runtime cost. Its main weakness is sorting usable lots again for every order, yielding a slower bound than sorting lots once; some allocation bookkeeping is also redundant.

Score by criterion

Correctness

89

Passes T1–T6 by inspection: chronological processing preserves same-day order, expiry is inclusive, FEFO ties use lot IDs, and all-or-nothing orders check only usable stock and consume nothing when skipped. Zero-quantity orders are handled correctly. The repeated sorting does not meet the efficiency bound associated with the policy's 9+ condition.

Completeness

89

Returns exactly fills, short, and remaining, including every order and lot where required. Negative quantities and duplicate IDs are rejected before allocation starts. No required functionality is missing; the global 9+ efficiency condition is not met.

Code Quality

78

Readable, self-contained code with clear validation and allocation stages. However, sorting usable lots for each order is unnecessary, lot_data redundantly stores each ID, and the temporary allocation plus second all-or-nothing check adds bookkeeping after sufficiency has already been established.

Practical Value

84

Ready to use for a small warehouse, with deterministic results and no mutation of the supplied inputs. Repeated per-order sorting limits scalability compared with sorting lots once, but does not undermine its usefulness for the stated setting.

Instruction Following

89

Uses only built-in Python functionality, provides the requested function, and stays within the measured limits of 68 code lines and 148 explanation words. The explanation includes an accurate main complexity bound, but that bound is slower than the policy's 9+ efficiency target.

Gemini 3.8 Flash 10.00

The solution perfectly meets all requirements and passes all test cases (T1–T6) outlined in the policy. Validation is performed upfront, order sorting is stable, lot tie-breaking and expiration conditions are strictly correct, all-or-nothing logic accounts properly for usable stock, and the return structure is exact. Line count and explanation word limits are strictly adhered to, with an accurate time complexity analysis.

Score by criterion

Correctness

100

The implementation correctly enforces the stable ordering of orders by day, strict FEFO lot selection with string-based ID tie-breaking, expiration filtering (expires >= day), and exact all-or-nothing semantics without leaking state.

Completeness

100

All edge cases and requirements are handled: upfront validation for negative quantities and duplicate IDs, proper return dictionary format, omitting orders with zero remaining shortage from 'short', and including orders with zero allocations in 'fills'.

Code Quality

100

The code is clean, idiomatic, readable, and well-structured, avoiding redundant passes over individual quantity units.

Practical Value

100

The solution is production-ready for standard inventory allocation problems, clear in its execution path, and completely reliable.

Instruction Following

100

Followed all constraints: standard library only, 68 lines of code (well under the 150-line limit), and an explanation of 148 words (under the 200-word limit) that includes an accurate time complexity analysis.

About this genre

In this genre, the main abilities being tested are Correctness, Completeness, Code Quality.

Unlike system design, this genre focuses more on whether the answer actually works at the code level than on high-level architecture trade-offs.

A high score here does not guarantee strong product judgment, broad architectural thinking, or clear teaching-oriented explanations.

Strong models here are useful for

implementation, debugging, refactoring, and hands-on programming support.

This genre alone cannot tell you

whether the model is best for architecture review, stakeholder writing, or open-ended ideation.

What Is Evaluated in Coding

Scoring criteria and weight used for this genre ranking.

Correctness

35.0%

This criterion is included to check Correctness in the answer. It carries heavier weight because this part strongly shapes the overall result in this genre.

Completeness

20.0%

This criterion is included to check Completeness in the answer. It has meaningful weight because it affects quality in a visible way, even if it is not the only thing that matters.

Code Quality

20.0%

This criterion is included to check Code Quality in the answer. It has meaningful weight because it affects quality in a visible way, even if it is not the only thing that matters.

Practical Value

15.0%

This criterion is included to check Practical Value in the answer. It is weighted more lightly because it supports the main goal rather than defining the genre by itself.

Instruction Following

10.0%

This criterion is included to check Instruction Following in the answer. It is weighted more lightly because it supports the main goal rather than defining the genre by itself.

Related Links

X f L