강의

멘토링

커뮤니티

Inflearn Community Q&A

q33as1836's profile image
q33as1836

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

5. Finding the rank

이중 for문을 돌아야 하는 정확한 이유가 있을까요?

Written on

·

414

0

function solution(arr){
    let copy = arr.slice().sort((a, b) => b - a);
    return copy.map(it => arr.indexOf(it) + 1)
}

let arr=[87, 89, 92, 100, 76];
console.log(solution(arr));

 

제가 코테공부는 거의 안해서 잘 모르는데 시간복잡도가 연관이 있을것 같습니다 2중 for문을 돌아야 하는 이유가 있을까요?

 

javascript코딩-테스트

Answer 2

1

지수님 질문있습니다. 이 경우에는 동일한 점수가 있을 때 해결이 될까요?

1

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

네. N제한이 크지 않아서 시간복잡도를 크게 생각하지 않고 그냥 2중 for문으로 구해 봤습니다. 별다른 이유는 없습니다. 이렇게도 구한다 정도입니다.

q33as1836님의 프로필 이미지
q33as1836
Questioner

감사합니다 강사님!!

q33as1836's profile image
q33as1836

asked

Ask a question