Largest Number

Description


Given an integer n, return the largest number that contains exactly n digits.

Example

For n = 2, the output should be largestNumber(n) = 99.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] integer n

    A positive two-digit integer.

    Guaranteed constraints:
    1 \leq n \leq 9.

  • [output] integer

    • The largest integer of length n.

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
function largestNumber(n) {
	return Number(Array(n).fill(9).join(''))
}