FastPrepParameterized Divisibility Labels
Problem · Array

Parameterized Divisibility Labels

Learn this problem
EasyDeloitte logoDeloitteNEW GRADOA

Problem statement

You are given positive integers a, b, and n. For each integer i from 0 through n - 1, produce exactly one string:

  • "AB" if i is divisible by both a and b.
  • "A" if i is divisible by a only.
  • "B" if i is divisible by b only.
  • The decimal representation of i otherwise.

Return the n produced strings in order.

Function

divisibilityLabels(a: int, b: int, n: int) → String[]

Examples

Example 1

a = 2b = 3n = 7return = ["AB","1","A","B","A","5","AB"]

0 and 6 are divisible by both divisors. The remaining positions follow the single-divisor or decimal rules.

Example 2

a = 1b = 2n = 4return = ["AB","A","AB","A"]

Every number is divisible by 1, and the even positions are also divisible by 2.

Constraints

  • 1 <= a, b <= 10^9
  • 1 <= n <= 100000

More Deloitte problems

drafts saved locally
public String[] divisibilityLabels(int a, int b, int n) {
    // Write your solution here.
}
a2
b3
n7
expected["AB", "1", "A", "B", "A", "5", "AB"]
checking account