I'm sorry about the poor treatment user2112791 received on SO and you received on MSO.
The question didn't start out very well. While it was technically sufficient and answerable, it was difficult to get ahold of. The example added by an anonymous editor helps a lot.
The question may or may not be on-topic on Stack Overflow (which allows questions about “a software algorithm”). But since you're at the stage of designing an algorithm or looking for an already known algorithm, it is rather more appropriate for Computer Science. It has now been migrated there.
A good rule of thumb to decide between SO and CS is: will this question and its answer benefit more from code markup, or from MathJax (LaTeX)? Here, there is some mathematical notation, and the question is indeed more appropriate for CS.
The migration reset the score to 0, as always happens for negatively-scored migrated posts (posts with a nonnegative score keep their votes).