You are given an array of positive integers nums. Your task is to return the least common multiple (LCM) of all the elements in the array. The LCM is the smallest positive integer that is divisible by every element without leaving a remainder.
Input: nums = [4, 6, 8]
Output: 24
Explanation: The smallest positive integer divisible by 4, 6, and 8 is 24.
Input: nums = [2, 3, 5]
Output: 30
Explanation: Since 2, 3, and 5 are pairwise coprime, their LCM is their product: 2 × 3 × 5 = 30.
Input: nums = [7]
Output: 7
Explanation: Since the array contains only one number, its LCM is the number itself: 7.
Sign in to write, run, and submit your solution against the full test suite.