Tip 1: One way to approach this problem is to start by looking at the simpler following problem: given two equal-length sequences of notes a1 ... aC and b1...bC do they match after transposition and re-order? ========================================================================= Solution for Tip 1: For that we find the following algorithm: sort both sequence and check that the difference a_i-b_i is constant ========================================================================= Tip 2 : What is the complexity of a function taking a position p of the input and checking whether input[p:p+C] is a ruminant seventh chord? ========================================================================= Solution tip 2 : We just apply the solution to tip 1. It is O(C×log(C)). Since C is small we just need to repeat this for all positions.