[programmers] 인사고과

주의 사항

  • 인센티브를 못 받는 직원들의 카운트를 제외 해야 한다.
  • 되도록 On 으로 끝내야 한다.

추론

  • 2차원 배열의 두 값 다 커야 할 경우 한쪽으로 정렬 후 나머지 한쪽만 비교하여 카운팅 한다.
package com.lotte;

import java.util.Arrays;

class Result {

    /*
     * Complete the 'climbingLeaderboard' function below.
     *
     * The function is expected to return an INTEGER_ARRAY.
     * The function accepts following parameters:
     *  1. INTEGER_ARRAY ranked
     *  2. INTEGER_ARRAY player
     */

    public int solution(int[][] scores) {
        int[] wonho = scores[0];
        int wonhoTotal = wonho[0]+wonho[1];

        Arrays.sort(scores, (o1,o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o2[0] - o1[0] );

        int maxScore = scores[0][1];

        int cnt = 1;
        for(int i = 0; i < scores.length; i++) {
            if (scores[i][1] >= maxScore) {
                maxScore = scores[i][1];
                if(scores[i][0] + scores[i][1] > wonhoTotal) cnt++;
            }else{
                if(Arrays.equals(scores[i], wonho)) return -1;
            }
        }

        return cnt;
    }

    public static void main(String[] args) {
        int[][] scores = { {2,2},{1,4},{3,2},{3,2},{2,1} };

        Result r = new Result();
        System.out.println(r.solution(scores));

    }
}

Link


© 2023 Lee. All rights reserved.