The index of the Python notes doubles as a drill set: small HackerRank-style SRE questions on a sample Nginx combined access log, each answered with the smallest correct algorithm and its stated time and space cost.

The drills

DrillTechniqueCost
Count 5xx requestsStream the file line by line and read the status after the quoted requestO(n) time, O(1) space
Count each statusdict.get(status, 0), then sorted by countO(n) scan, O(k log k) sort
Top N pathsSplit the quoted request into method, path, protocol; slice [:n]O(m) scan, O(k log k) sort
Duplicate request IDsA seen set and a duplicates setO(n) average
Two SumA dictionary of complementsO(n) time and space
Maximum fixed-window countSlide the window, adding the entering value and removing the leaving oneO(n) time, O(1) space

As listed in the source.1

Answering in an interview

flowchart LR
    accTitle: Interview answer sequence
    accDescr: Confirm the contract, explain with a small example, write the smallest runnable solution, test edge cases, then state complexity.
    A[Confirm inputs and outputs] --> B[Explain with an example]
    B --> C[Smallest runnable solution]
    C --> D[Test edge cases]
    D --> E[State time and space]

Confirm input, output, and invalid-input behavior; explain the algorithm on a small example; write the smallest runnable solution; test empty input, duplicates, no result, and boundaries; then state time and space complexity.1

Footnotes

  1. Python SRE HackerRank Quick Reference, original ↩ ↩2