Spectator solves two coding problems from screenshots
By CheatCodeAI team3 min read
CheatCodeAI is a desktop assistant for job interviews. Spectator is the part that reads screenshots, and in Coding mode it turns a problem on your screen into a worked solution: a restatement, clarifying questions, an approach, code that prints the problem's examples, and a complexity analysis.
We gave it two problems as screenshots, with the default settings. Spectator writes code but doesn't run it, so we ran every program ourselves and compared it with brute-force versions of our own.
Throttled requests
The first problem is a familiar sliding-window kind, close to the hit-counter and recent-calls practice problems. A gateway accepts a request only if fewer than limit earlier requests were accepted in the last window seconds. The window is strict, so a request exactly window seconds old no longer counts, and rejected requests don't count toward the limit. We sent it as screenshots (1, 2).
Spectator kept a queue of accepted times and dropped expired ones from the front. Its Python code printed the expected output for all three examples and matched our brute-force version on 20,000 random inputs.
We typed a follow-up in the same thread: "Why a deque and not a heap?" The reply pointed at the input order:
Because the input times array is already sorted, the accepted requests are naturally added to the queue in chronological order. A deque maintains this insertion order perfectly. A heap would maintain the elements in a min-heap structure, which is unnecessary overhead when the data is already sorted.
From the reply to the follow-up.
It also noted that a deque adds and removes in O(1), where a heap of K items needs O(log K). Then we set the language to Go in Settings and sent the same screenshots. The Go program printed the same three correct results.
Affected versions
The second problem is ours, sent as screenshots (1, 2). A library has published versions such as "1.10.0", and each security advisory covers a range: every version from lo up to, but not including, hi, where hi can be "*" for no upper bound. For each version, return how many advisories affect it.
Versions compare part by part as numbers, so 1.10.0 is newer than 1.9.3. The upper bound is excluded, an advisory whose lo equals its hi covers nothing, and both lists can hold 100,000 entries, so checking every pair means 10 billion comparisons. Counting how many ranges cover a point is a known technique; the version rules are ours.
The answer shown here restated the rules correctly, and its clarifying questions picked out the numeric comparison. For the counting it used two sorted lists and binary search:

This works because lo <= hi in every advisory. Any advisory that has ended by version v has also started by then, so the difference counts the advisories still open at v. An empty range such as ["3.0.0", "3.0.0"] lands in both counts or in neither, so it always cancels out. For N versions and M advisories, sorting the bounds once and running two binary searches per version gives O((N + M) log M), which is the complexity the answer stated.
import bisect
def parse_version(v_str):
# Convert "MAJOR.MINOR.PATCH" string to a tuple of integers for comparison
return tuple(map(int, v_str.split('.')))
def affected_counts(versions, advisories):
# Parse all versions into comparable tuples
parsed_versions = [parse_version(v) for v in versions]
# Parse all advisory bounds
# We use a large tuple (float('inf'), float('inf'), float('inf')) to represent "*"
inf = (float('inf'), float('inf'), float('inf'))
starts = []
ends = []
for lo, hi in advisories:
starts.append(parse_version(lo))
if hi == "*":
ends.append(inf)
else:
ends.append(parse_version(hi))
# Sort the bounds to enable binary search
starts.sort()
ends.sort()
results = []
for v in parsed_versions:
# Count how many advisories have started (lo <= v)
# bisect_right returns the insertion point after all elements <= v
count_started = bisect.bisect_right(starts, v)
# Count how many advisories have ended (hi <= v)
# bisect_right returns the insertion point after all elements <= v
count_ended = bisect.bisect_right(ends, v)
# The number of active advisories is the difference
active_count = count_started - count_ended
results.append(active_count)
return resultsThe code ends with a block that prints the three examples. We ran it as written:
$ python3 solution.py
[0, 1, 2, 1]
[1, 1, 0]
[1, 1, 2]All three lines match the expected output. Against our brute-force version on 20,000 random inputs it agreed every time, and with 100,000 versions and 100,000 advisories it finished in about a quarter of a second on a laptop.
Our Terms of Service don't allow using CheatCodeAI where an employer's or interview platform's rules forbid outside help. They also rule out schoolwork; academic, licensing, certification and government exams; and proctored or supervised tests that forbid outside help.