I know you have put in a lot of efforts to write this and come up with this solution algorithm but from a layman’s perspective, an algorithm/solution is as complex as the author makes it. It can be represented in a very simpler way i.e in a pseudocode-ish way or maybe a more structured writing which can allow the reader to not loose the train the thought which leads to the secret ingredient. To quote Po from Kung Fu Panda,”There is no secret ingredient”.Simplicity would make this such a wonderful read. I take it you like to code in python. There is a reason for the popularity of Python over C or Java when anyone starts to learn to code. It’s because of its simplicity.