Array Greatest Common Divisor LeetCode (GCD of an array elements)

Given an array of numbers, find GCD of the array elements. In a previous post we find GCD of two number.

Example 1:

  • Input  : arr[] = {1, 2, 3}
  • Output : 1

Example 2:

  • Input  : arr[] = {2, 4, 6, 8}
  • Output : 2

This is a classical problem and is also popular in LeetCode and several other forums - Forum 1, Forum 2, Forum 3 A collection of hundreds of interview questions and solutions are available in our blog at Interview Question Solutions

Solution:

 

No comments:

Post a Comment