Skip to content

Instantly share code, notes, and snippets.

View rjvitorino's full-sized avatar

Ricardo Vitorino rjvitorino

View GitHub Profile
@rjvitorino
rjvitorino / piano_largest_interval.py
Created March 11, 2025 23:25
Cassidy's interview question of the week: a function that takes a list of piano keys played in sequence and returns the largest interval (in semitones) between any two consecutive keys.
"""
Finds the largest interval in semitones between consecutive piano notes.
Supports both a standard library implementation and an optimized version
using the `mido` library (if installed).
USAGE:
- If `mido` is installed (`pip install mido` or `uv pip install mido`), it will use it automatically.
- If `mido` is not available, it falls back to a pure Python implementation.
"""