Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Nth Magical Number (hard)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given the three integers n, a, and b, return the n<sup>th</sup> magical number modulo 10^9 + 7 as it can be very large.

A positive integer is called magical if it is divisible by either a or b.

Examples

  • Example 1:

    • Input: n = 3, a = 2, b = 3
    • Expected Output: 4
    • Justification: The first three magical numbers divisible by 2 or 3 are 2, 3, and 4. The third magical number is 4.
  • Example 2:

    • Input: n = 5, a = 3, b = 4
    • Expected Output: 9

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible