212 lines
9.7 KiB
JSON
212 lines
9.7 KiB
JSON
{
|
|
"name": "backend-demo-ai-draft-v1",
|
|
"category": "backend",
|
|
"author": "ai:claude-draft",
|
|
"review": {
|
|
"status": "pending",
|
|
"reviewer": ""
|
|
},
|
|
"families": [
|
|
{
|
|
"key": "backend-rate-limit-window",
|
|
"version": 1,
|
|
"specialization": "rate-limiting",
|
|
"title": "Sliding-window request limiter",
|
|
"seed_generator": {
|
|
"algorithm": "rate_limit_window.v1",
|
|
"parameters": {
|
|
"requests": {
|
|
"min": 12,
|
|
"max": 40
|
|
},
|
|
"window": {
|
|
"min": 3,
|
|
"max": 15
|
|
},
|
|
"limit": {
|
|
"min": 2,
|
|
"max": 6
|
|
},
|
|
"max_gap": {
|
|
"min": 1,
|
|
"max": 5
|
|
}
|
|
},
|
|
"statement_template": "A gateway protects an endpoint with a sliding-window limiter. A request arriving at second t is accepted only when fewer than {{.limit}} previously accepted requests have an arrival time in the half-open interval (t - {{.window}}, t]. A rejected request is not remembered and does not count against later requests. The gateway receives {{.requests}} requests at these arrival times, in seconds and in non-decreasing order: {{.timestamps}}. How many requests does the gateway reject?"
|
|
},
|
|
"answer_key": {
|
|
"answer_format": "integer",
|
|
"reference_solution": "Keep the arrival times of accepted requests in a queue. Before handling a request at time t, drop queued times that are at most t - window. If the queue holds fewer than limit entries, append t; otherwise count a rejection. Each time enters and leaves the queue once, so the cost is linear in the number of requests."
|
|
},
|
|
"rubric": {
|
|
"principle": "A submission is first compared with the reference answer of its variant and then judged against the criteria below. This rubric defines no points and no pass mark: how criteria turn into a grade is decided by the versioned grading policy.",
|
|
"criteria": [
|
|
{
|
|
"id": "correct_answer",
|
|
"description": "The submitted number equals the reference answer of the variant."
|
|
},
|
|
{
|
|
"id": "window_boundary",
|
|
"description": "The solution treats the window as half-open: a request exactly window seconds old no longer counts."
|
|
},
|
|
{
|
|
"id": "rejected_not_counted",
|
|
"description": "Rejected requests are not stored and do not occupy window capacity."
|
|
},
|
|
{
|
|
"id": "approach",
|
|
"description": "The solution states an approach that handles each request in amortized constant time or explains why a slower one is enough for the input sizes."
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"key": "backend-idempotent-consumer-window",
|
|
"version": 1,
|
|
"specialization": "messaging",
|
|
"title": "Idempotent consumer with a duplicate window",
|
|
"seed_generator": {
|
|
"algorithm": "dedup_window.v1",
|
|
"parameters": {
|
|
"events": {
|
|
"min": 10,
|
|
"max": 40
|
|
},
|
|
"keys": {
|
|
"min": 2,
|
|
"max": 6
|
|
},
|
|
"ttl": {
|
|
"min": 3,
|
|
"max": 20
|
|
},
|
|
"max_gap": {
|
|
"min": 1,
|
|
"max": 6
|
|
}
|
|
},
|
|
"statement_template": "A consumer receives {{.events}} messages written as KEY@TIME, where TIME is the arrival second and times never decrease. It processes a message unless the same KEY was processed less than {{.ttl}} seconds earlier; such a message is dropped as a duplicate. A dropped message does not postpone the next processing of its KEY. The stream is: {{.stream}}. How many messages does the consumer process?"
|
|
},
|
|
"answer_key": {
|
|
"answer_format": "integer",
|
|
"reference_solution": "Keep a map from key to the time of its last processed message. For each message, if the key is present and the time difference is smaller than ttl, drop it; otherwise record the time and count the message as processed. One pass, constant work per message."
|
|
},
|
|
"rubric": {
|
|
"principle": "A submission is first compared with the reference answer of its variant and then judged against the criteria below. This rubric defines no points and no pass mark: how criteria turn into a grade is decided by the versioned grading policy.",
|
|
"criteria": [
|
|
{
|
|
"id": "correct_answer",
|
|
"description": "The submitted number equals the reference answer of the variant."
|
|
},
|
|
{
|
|
"id": "duplicate_boundary",
|
|
"description": "A message exactly ttl seconds after the last processed one with the same key is processed, not dropped."
|
|
},
|
|
{
|
|
"id": "dropped_not_extending",
|
|
"description": "A dropped duplicate does not move the time stored for its key."
|
|
},
|
|
{
|
|
"id": "approach",
|
|
"description": "The solution keeps state per key instead of rescanning earlier messages."
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"key": "backend-lru-cache-hits",
|
|
"version": 1,
|
|
"specialization": "caching",
|
|
"title": "Hit count of a least-recently-used cache",
|
|
"seed_generator": {
|
|
"algorithm": "lru_hits.v1",
|
|
"parameters": {
|
|
"accesses": {
|
|
"min": 15,
|
|
"max": 50
|
|
},
|
|
"keys": {
|
|
"min": 3,
|
|
"max": 10
|
|
},
|
|
"capacity": {
|
|
"min": 2,
|
|
"max": 5
|
|
}
|
|
},
|
|
"statement_template": "An in-memory cache holds at most {{.capacity}} entries and evicts the least recently used entry when it is full and a missing key must be stored. Reading a key that is present is a hit; reading a key that is absent is a miss, after which the key is stored. Both a hit and a miss make the key the most recently used one. The cache starts empty and serves these {{.accesses}} reads, drawn from {{.keys}} possible keys numbered from 1 to {{.keys}}: {{.sequence}}. How many reads are hits?"
|
|
},
|
|
"answer_key": {
|
|
"answer_format": "integer",
|
|
"reference_solution": "Maintain the cached keys ordered from least to most recently used, for example with a hash map plus a doubly linked list. On a hit move the key to the recent end; on a miss evict from the old end when the cache is full, then add the key at the recent end. Count the hits."
|
|
},
|
|
"rubric": {
|
|
"principle": "A submission is first compared with the reference answer of its variant and then judged against the criteria below. This rubric defines no points and no pass mark: how criteria turn into a grade is decided by the versioned grading policy.",
|
|
"criteria": [
|
|
{
|
|
"id": "correct_answer",
|
|
"description": "The submitted number equals the reference answer of the variant."
|
|
},
|
|
{
|
|
"id": "recency_on_hit",
|
|
"description": "A hit refreshes the recency of the key, so it is evicted later."
|
|
},
|
|
{
|
|
"id": "eviction_order",
|
|
"description": "On a miss in a full cache the least recently used key is evicted before the new key is stored."
|
|
},
|
|
{
|
|
"id": "approach",
|
|
"description": "The solution names a structure that makes lookup and recency updates cheap, or justifies a simple list for the input sizes."
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"key": "backend-job-dependency-order",
|
|
"version": 1,
|
|
"specialization": "scheduling",
|
|
"title": "Smallest valid job execution order",
|
|
"seed_generator": {
|
|
"algorithm": "dependency_order.v1",
|
|
"parameters": {
|
|
"tasks": {
|
|
"min": 5,
|
|
"max": 9
|
|
},
|
|
"links": {
|
|
"min": 4,
|
|
"max": 14
|
|
}
|
|
},
|
|
"statement_template": "A worker runs {{.tasks}} jobs numbered from 1 to {{.tasks}}, one at a time. A dependency A->B means job A must finish before job B starts. The dependencies are: {{.dependencies}}. The dependencies contain no cycle, so at least one valid order exists. Among all execution orders that respect every dependency, choose the one that is smallest when compared number by number from the first position. Write that order as job numbers separated by single spaces."
|
|
},
|
|
"answer_key": {
|
|
"answer_format": "integer_sequence",
|
|
"reference_solution": "Count unmet dependencies for every job. Repeatedly start the smallest-numbered job whose count is zero, then lower the counts of the jobs that depended on it. A priority queue keeps the choice cheap; the dependencies never form a cycle."
|
|
},
|
|
"rubric": {
|
|
"principle": "A submission is first compared with the reference answer of its variant and then judged against the criteria below. This rubric defines no points and no pass mark: how criteria turn into a grade is decided by the versioned grading policy.",
|
|
"criteria": [
|
|
{
|
|
"id": "correct_answer",
|
|
"description": "The submitted sequence equals the reference answer of the variant."
|
|
},
|
|
{
|
|
"id": "all_dependencies_respected",
|
|
"description": "Every job appears after every job it depends on."
|
|
},
|
|
{
|
|
"id": "smallest_choice",
|
|
"description": "Whenever several jobs are ready, the smallest number is chosen, which is not the same as sorting the jobs by number."
|
|
},
|
|
{
|
|
"id": "approach",
|
|
"description": "The solution explains how it finds ready jobs without rescanning all dependencies at every step, or justifies the simple scan for the input sizes."
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|