Recently, I was helped in answering a question https://stackoverflow.com/a/65417494/14872543, but I do not have enough knowledge to modify the function to solve the same pro