# [Algorithm/JS] ๋ฐฑ์ค€ 2562๋ฒˆ ์ตœ๋Œ“๊ฐ’

๐Ÿ”— ๋ฌธ์ œ ๋ฐ”๋กœ๊ฐ€๊ธฐ (opens new window)

# Question

N๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ์ตœ์†Ÿ๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

9๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ด๋“ค ์ค‘ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ๊ณ  ๊ทธ ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ ์ˆ˜์ธ์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ์„œ๋กœ ๋‹ค๋ฅธ 9๊ฐœ์˜ ์ž์—ฐ์ˆ˜

3, 29, 38, 12, 57, 74, 40, 85, 61

์ด ์ฃผ์–ด์ง€๋ฉด, ์ด๋“ค ์ค‘ ์ตœ๋Œ“๊ฐ’์€ 85์ด๊ณ , ์ด ๊ฐ’์€ 8๋ฒˆ์งธ ์ˆ˜์ด๋‹ค.

# Input

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ ์•„ํ™‰ ๋ฒˆ์งธ ์ค„๊นŒ์ง€ ํ•œ ์ค„์— ํ•˜๋‚˜์˜ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ž์—ฐ์ˆ˜๋Š” 100 ๋ณด๋‹ค ์ž‘๋‹ค.

# Output

์ฒซ์งธ ์ค„์— ์ตœ๋Œ“๊ฐ’์„ ์ถœ๋ ฅํ•˜๊ณ , ๋‘˜์งธ ์ค„์— ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ ์ˆ˜์ธ์ง€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

# Example Input

5
20 10 35 30 7
1
2

# Example Output

7 35
1

# Solution

const input = require('fs').readFileSync('dev/stdin').toString().split('\n');
let [count, arr] = input;
nums = arr.split(' ').map(Number);
let max = nums[0];
let min = nums[0];
for (let i = 0; i < count; i++) {
  if (max < nums[i]) {
    max = nums[i];
  }
  if (min > nums[i]) {
    min = nums[i];
  }
}
console.log(min, max);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Last Updated: 2022. 6. 5. ์˜คํ›„ 3:42:39