Skip to the code
+10 XP

#634 Aspect Ratio Label

easy

A video settings panel shows each resolution with its aspect ratio, such as 1920 × 1080 with the label 16:9.

Write aspectRatioLabel(width, height) that returns the ratio in lowest terms as a string "w:h": divide both numbers by their greatest common divisor.

Example 1

Input: width = 1920, height = 1080
Output: "16:9"

The greatest common divisor is 120: 1920 / 120 = 16 and 1080 / 120 = 9.

Example 2

Input: width = 1080, height = 1080
Output: "1:1"

A square screen: both sides divide by 1080.

Constraints

  • 1 <= width, height <= 10^12
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).