Given an array of numbers. Perform below operations
- Find the adjacent numbers which are not co prime.
- Delete those two numbers and replace with the LCM of two numbers.
Example :: [2, 3 , 4 , 6, 7] output = [12,7]
--> [2, 3, 12, 7] since (4, 6) is replaced with the lcm of two numbers - 12
--> [2,12,7] since (3,12) is replaced with the lcm(3,12) - 12
--> [12, 7] since(2,12) is replaced with the lcm(2,12) - 12
Please provide effiicient soluton