Two cars X and Y travelling in opposite directions along the same high way at…