Challenge 1: Find the Greatest Common Divisor

Given two numbers, find their greatest common divisor.

Problem Statement

Implement a function that takes two numbers, testVariable1 and testVariable2 and returns their greatest common divisor.

What is the Greatest Common Divisor?

The Greatest Common Divisor of two or more integers is the largest positive integer that divides each of the integers.

For example, take two numbers 4242 and 5656.

4242 can be completely divided by 11, 22, 33, 66, 77, 1414, 2121 and 4242.

5656 can be completely divided by 11, 22, 44, 77, 88, 1414, 2828 and 5656.

Therefore, the greatest common divisor of 4242 and 5656 is 1414.

Input

Two variables testVariable1 and testVariable2 containing numbers.

Output

The greatest common divisor of testVariable1 and testVariable2.

Sample Input

6, 9

Sample Output

3

Try it Yourself

Try this challenge yourself before examining the solution. Good luck!

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.