Greatest Common Divisor

Given 2 non negative integers m and n, find gcd(m, n)

GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n.
Both m and n fit in a 32 bit signed integer.


m : 6
n : 9

GCD(m, n) : 3 


NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Greatest Common Divisor on Interview Code Editor
Sign Up
to access hints and editorial solutions for Greatest Common Divisor
17827 successful submissions.
Asked In:
  • NetApp
  • Google
Click here to start solving coding interview questions