LLM Complex Coding Evaluation: Two Problems That Reveal Real Engineering Capability

    This article uses two coding problems—time-dependent shortest paths with periodic phase constraints and out-of-order log replay with idempotent state convergence—to show how hidden edge cases, multi-objective comparison, idempotency scope, and snapshot timing separate code that merely runs from code that is correct. It also outlines six evaluation dimensions and an engineering pipeline for reproducible LLM coding assessment, including hidden tests, brute-force cross-checks, complexity review, and failure-mode analysis.

    LLM Complex Coding Evaluation: Two Problems That Reveal Real Engineering Capability

    1. Why Two Problems Can Expose the Gap

    Evaluating a general-purpose LLM’s coding ability cannot rely only on whether it can write code that “runs.” Real engineering tasks often combine formal specification understanding, boundary conditions, complexity constraints, state consistency, and verifiability. Two seemingly ordinary problems happen to cover two typical capabilities. The first is graph optimization with time constraints, which tests whether a model can turn natural-language rules into an exact waiting function and a multi-objective comparator. The second is out-of-order log replay, which tests whether a model can maintain idempotency keys, ownership, and snapshot state. The first leans toward algorithm design; the second leans toward state machines and engineering details. If a model writes only the main flow and ignores hidden pitfalls, hidden test cases will expose the problem quickly.

    2. Problem Type 1: Time-Dependent Shortest Path Under Periodic Phase Constraints

    The problem asks for the earliest arrival time from a source to a destination in a directed graph. When earliest arrival times are equal, the total cost must be minimized. When costs are also equal, the lexicographically smallest vertex path must be returned. Each edge has a phase, period, duration, and cost. If the current arrival time at a node is T, departure is allowed only when (depart + phase) % period == 0. If the current time is invalid, the path can wait until the nearest valid time. Arrival at the next node is depart + duration, and cost is accumulated.

    1. The Waiting Function Must Be Exact

    The waiting function is the first barrier in the problem. Given current time T, the nearest valid departure time can be written as follows: if (T + phase) % period == 0, then depart = T; otherwise depart = T + period - ((T + phase) % period). Integer modulo must be used here, not floating point, because time can reach the order of 10^18 and floating point will lose precision. The waiting function is illustrated below:

    1. function earliest_depart(T, phase, period):
    2. remainder = (T + phase) % period
    3. if remainder == 0:
    4. return T
    5. return T + period - remainder

    2. The Triple Comparator Must Not Be Wrong

    The problem requires returning (earliest_arrival_time, min_cost_among_earliest, path). The comparison order must be: arrival time first, then cost, then path lexicographic order. Many implementations compare only time in the priority queue, causing cost not to be minimal; or they arbitrarily keep one path when costs are equal, causing incorrect lexicographic order. Path lexicographic order should compare the vertex sequence item by item, not string concatenation. The comparator can be abstracted as:

    1. compare(a, b):
    2. if a.time != b.time: return a.time < b.time
    3. if a.cost != b.cost: return a.cost < b.cost
    4. return a.path lexicographically < b.path

    3. Hidden Pitfalls

    First, when period = 1 and cost = 0, many equivalent paths appear. At this point arrival time and cost may both be identical, and the only distinguishing criterion is path lexicographic order, so an arbitrary path cannot be kept. Second, when earliest time is the same but path lexicographic order differs, the current best path must be retained and strictly compared during relaxation. Third, s == t is a special boundary: the shortest path should be (start_time, 0, [s]), and it must not become later by taking cycles or waiting. Fourth, multiple edges must not be deduplicated by (u, v), because different phases, periods, and costs may produce different results. Fifth, large integer times must use integer types throughout; floating point is prohibited.

    4. Single-Label Shortest Path Is Not Enough

    The edge arrival function is non-decreasing: a later arrival time through the same edge will not produce an earlier arrival. Therefore, earliest arrival time can be found with a Dijkstra-like priority queue. However, cost optimization cannot simply keep only the earliest-time single label for each node. The reason is that waiting may “absorb” time differences: a path that reaches a node slightly later but with lower cost may, after subsequent waiting, reach the destination at the same time as an earlier path, and thus be better in cost under the same earliest arrival. In engineering, Pareto label correction can be used: each node keeps several non-dominated (time, cost) labels; for the same (time, cost), only the lexicographically smallest path is kept; if the number of labels grows, pruning can be combined with a reverse latest allowed time window. When evaluating a model, the key is whether it recognizes that “later but cheaper” labels may be valid, rather than directly applying single-label shortest path.

    3. Problem Type 2: Out-of-Order Log Replay and Idempotent State Convergence

    The second problem requires replaying a set of out-of-order logs. Log fields include timestamp, actor, idempotency key, operation type, and payload. The system maintains several objects, each with an ID, owner, and value. Logs are replayed in ascending order by (ts, actor, op_id). Under the same actor, the same idempotency key can take effect only once. add creates the object when it does not exist and ignores it when it already exists. move takes effect only when the current owner equals the actor. delete also requires ownership match. snapshot records the visible state of the specified ID set at that moment; non-existent IDs are recorded as None.

    1. Idempotency Key Scope Is the Actor

    The most common mistake is treating op_id as globally unique. The problem explicitly states that “under the same actor, the same op_id can take effect only once,” so the idempotency set key should be (actor, op_id). Different actors using the same op_id can still each take effect. Second, all operation types should consume the idempotency key, including snapshot, because the rule says “under the same actor, the same op_id can take effect only once” and does not exclude snapshots.

    2. Sorting and Snapshot Timing

    Before replay, logs must be sorted in ascending order by (ts, actor, op_id). None of the sort keys can be omitted: sorting only by timestamp breaks determinism at the same timestamp; sorting only by actor disrupts time order. snapshot itself does not change object state; it only records the current visible state. Therefore, it must read the state at the time the log is processed, not earlier or later. If the ID list in a snapshot contains duplicates, each should be recorded in input order; non-existent IDs return None.

    1. function reconcile(events):
    2. seen = empty set
    3. objects = empty map
    4. snapshots = empty list
    5. sort events by (ts, actor, op_id) ascending
    6. for each log ev:
    7. key = (ev.actor, ev.op_id)
    8. if key in seen: continue
    9. add key to seen
    10. if ev.kind == "add":
    11. if ev.payload.id not in objects:
    12. objects[id] = {owner: actor, value: value}
    13. else if ev.kind == "move":
    14. if objects[id] exists and owner == actor:
    15. objects[id].owner = new_owner
    16. else if ev.kind == "delete":
    17. if objects[id] exists and owner == actor:
    18. delete objects[id]
    19. else if ev.kind == "snapshot":
    20. state = empty list
    21. for each id in ids:
    22. if id in objects: state.append(visible state of objects[id])
    23. else: state.append(None)
    24. snapshots.append((label, state))
    25. return snapshots

    3. Engineering Hidden Pitfalls

    Beyond idempotency scope, note the following: after deletion, the object does not exist, and later snapshots should record None; add on an existing object is ignored and must not overwrite the original owner; when move and delete do not satisfy ownership, they are ignored but the idempotency key is still consumed; logs with identical sort keys need deterministic handling, usually with the first one taking effect and later ones ignored due to idempotency. If the log volume is large, full sorting may be limited by memory. In engineering, external sorting or sharding followed by merging may be needed, but evaluation should first ensure semantic correctness.

    4. How to Evaluate LLM Performance: Six Dimensions

    First, correctness. Hidden test cases should cover both the main flow and boundaries, not just examples. Second, boundary coverage: s == t, period = 1, cost = 0, multiple edges, large integer times, empty events, duplicate idempotency keys, snapshots after deletion, and so on. Third, complexity: the graph problem should be close to O((n + m) log n), and the log problem should consider sorting cost and state query cost; exponential or quadratic brute force is not acceptable. Fourth, explanation and proof: whether the model can explain the waiting function, FIFO property, label dominance, and idempotency scope is more valuable than code alone. Fifth, test generation: asking the model to actively construct differential test cases and counterexamples shows whether it truly understands the pitfalls. Sixth, engineering maintainability: whether naming, modularization, comments, and error handling are clear.

    Common failure modes include: writing only the main flow and ignoring lexicographic order; single-label shortest path losing low-cost later paths; making the idempotency key a global set; missing actor or op_id in the sort key; reading snapshots at the wrong time; and using floating point for large integers. Evaluation should first run hidden test cases, then manually review complexity and explanations, and finally use random small-scale brute-force solutions for differential testing.

    5. Engineering Evaluation Pipeline

    Inside an enterprise, problem statements, generators, reference solutions, and hidden test cases can be stored in object storage. Candidate code can be run in isolated containers. A logging service can collect failed cases, and monitoring and alerting can track pass rates and timeout rates. Randomly generating small-scale data and cross-checking it against a brute-force solution can reveal semantic errors; large-scale stress cases can reveal complexity problems. In a general cloud environment, teams can use container platforms, object storage, logging services, and monitoring and alerting to build a similar pipeline. The key is not a one-time leaderboard score, but a reproducible, extensible evaluation set that continuously exposes boundary issues.

    6. Conclusion

    The value of these two problems is that they separate “can write code” from “can deliver a correct algorithm.” The first problem tests time functions, multi-objective comparison, and label correction; the second tests sorting, idempotency, ownership, and snapshot consistency. When evaluating a newly released LLM, look less at marketing claims and more at hidden test pass rates, complexity analysis, boundary coverage, and failure modes. Only by making evaluation an engineering system can we reach credible conclusions about model capability.