Back to problems

Replace Non-Coprime Numbers in Array

Algorithm · Microsoft · Medium

You are handed a list of positive integers named nums. Keep simplifying the list with the following rule until no further simplification can be made. Look at any two neighbouring entries nums[i] and nums[i + 1]. When the two share a greatest common divisor larger than 1, take both out of the list and put a single entry in the spot they occupied: their least common multiple. Produce the list as it stands once the rule can no longer be applied. The final list does not depend…

Loading the rest of the question…