2024_10_10 Kata

SJ.CHO·2024년 10월 10일

알고리즘 Kata

80.

답안 :

class Solution {
	public int solution(int n, int a, int b) {
		int answer = 1;
		while (true) {
			a = (a + 1) / 2;
			b = (b + 1) / 2;
			if (a == b)
				break;
			answer++;

		}
		return answer;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Solution s = new Solution();
		int n = 8;
		int a = 4;
		int b = 7;
		System.out.println(s.solution(n, a, b));
	}
}
  • 알고리즘 설명 :
    • 토너먼트가 진행됄수록 인원은 n/2 화 되기때문에 2씩 나눠주면서 같은 대진에 마주쳤을때 값 반환.

SQL Kata

90.

  • action 값에 따른 확인률에 대한 평균 구하기.

답안 :

select s.user_id, round(avg(if(c.action="confirmed",1,0)),2) as confirmation_rate
from Signups as s 
left join Confirmations as c 
on s.user_id= c.user_id 
group by user_id;
  • 알고리즘 설명 :
    • 확인에 대한 평균을 구해 확인시 1, 아니면 0으로 맵핑, 이후 출력
profile
70살까지 개발하고싶은 개발자

0개의 댓글