TopcoderArchive
TCO9 Jan 2019
TCO19 SRM 747

MostFrequentLastDigit

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given the ints n and d. Return any int[] with the following properties:

  • The number of elements is n.
  • Each element is between 0 and 10^9, inclusive.
  • All elements are distinct.
  • No element is divisible by 10.
  • If we take all n*(n-1)/2 possible sums of two elements and look at the last digit of each of them, the digit d will be the unique most frequent one.

Definition

Class:
MostFrequentLastDigit
Method:
generate
Parameters:
int, int
Returns:
int[]
Method signature:
int[] generate(int n, int d)
(be sure your method is public)

Constraints

  • n will be between 2 and 200, inclusive.
  • d will be between 0 and 9, inclusive.

Examples

  1. 4
    7
    Returns: {1, 6, 13, 4 }
    The pairwise sums are 7, 14, 5, 19, 10, and 17. The last digit 7 appears in two of them, and each other digit appears at most once as a last digit of one of these sums.
  2. 2
    8
    Returns: {44, 444 }
    Note that {4, 4} is not a valid return value because all numbers must be distinct.}
  3. 7
    2
    Returns: {109, 22, 74, 23, 29, 9, 1003 }
Back to all problems