2807. Insert Greatest Common Divisors in Linked List

Practice Insert Greatest Common Divisors in Linked List for free on NudgeCode: Medium, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Between every pair of neighbouring nodes in the linked list, insert a new node whose value is the greatest common divisor of those two values. Return the head of the resulting list.

Example

head = [18,6,10,3]  ->  [18,6,6,2,10,1,3]

Constraints