Your question needs a lot of work. There is no problem statement, no example input, what I'm guessing is the expected output (the image) is not well explained, and no expected output. I don't know enough about the topic to know whether the example is an
MCVE or not, but if it isn't then it should be.