Here is the link to SO where I provided code and explained the question:
Please help me if you know how.