TypeScript bootcamp · Lab 06

Maximum in an array

mediumArrays12 minLesson: Arrays

Read the question, write TypeScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

First line n. Second line n integers. Log the max. Type the array as number[].

Examples

Example 1
Input
5
3 1 8 2 4
Output
8
Example 2
Input
1
42
Output
42
Hint
  1. const nums: number[] = readLine().trim().split(" ").map(Number);
Show correct code

Peek only after you have tried. You can still Check your own version.

const n: number = Number(readLine());
const nums: number[] = readLine().trim().split(" ").map(Number);
console.log(Math.max(...nums));
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.