Day74

강태훈·2026년 4월 16일

nbcamp TIL

목록 보기
74/97

알고리즘 코드카타

Confirmation Rate

with usercount as (
    select user_id, count(user_id) as counting
    from Confirmations
    group by user_id
), actioncount as (
    select user_id, count(action) as counting
    from Confirmations
    group by user_id, action
    having action = 'confirmed'
), totalcount as (
    select a.user_id, ifnull(b.counting,0) / a.counting as counting
    from usercount a
    left join actioncount b
    on a.user_id = b.user_id   
)

select a.user_id, round(ifnull(b.counting, 0), 2) as confirmation_rate 
from Signups a
left join totalcount b
on a.user_id = b.user_id
;

로또의 최고 순위와 최저 순위

import java.util.Arrays;

class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer = {7,7};
        int[] lotto = Arrays.stream(lottos).sorted().toArray();
        int[] win = Arrays.stream(win_nums).sorted().toArray();
        int zero = Math.toIntExact(Arrays.stream(lotto).filter(i -> i == 0).count());

        for(int num:win){
            boolean correct = Arrays.binarySearch(lotto, num) >= 0; //없으면 음수반환하기 때문
            if(correct){
                answer[0]--;
                answer[1]--;
            }
        }
        answer[0] -= zero;

        if(answer[0] > 6){
            answer[0] = 6;
        }
        if (answer[1] > 6) {
            answer[1] = 6;
        }
        return answer;
    }
}

0개의 댓글