알고리즘 코드카타
Game Play Analysis IV
WITH ranked AS (
SELECT a.*, b.event_date as after_event_date, if(datediff(b.event_date, a.event_date) = 1, 1, 3) as date_gap,
ROW_NUMBER() OVER (PARTITION BY a.player_id
ORDER BY a.event_date asc ,
if(datediff(b.event_date, a.event_date) = 1, 1, 3) asc
) AS rn
FROM Activity a
left join Activity b
on a.player_id = b.player_id
)
SELECT ROUND(
AVG(CASE
WHEN date_gap = 1 THEN 1
ELSE 0
END), 2
) AS fraction
FROM ranked
WHERE rn = 1;
성격 유형 검사하기
import java.util.Arrays;
class Solution {
public String solution(String[] survey, int[] choices) {
String answer = "";
int[] RCJA = {0,0,0,0};
int[] TFMN = {0,0,0,0};
String[] surveylist = {"RT", "TR", "CF", "FC", "JM", "MJ", "AN", "NA"};
for (int i = 0; i < survey.length; i++) {
int[] points = {};
for (int j = 0; j < surveylist.length; j++) {
if (survey[i].equals(surveylist[j])) {
points = point(j, choices[i]);
}
}
if(points[0] == 0){
RCJA[points[1]-1] += points[2];
}else{
TFMN[points[1]-1] += points[2];
}
}
char[][] word = {{'R', 'T'}, {'C', 'F'}, {'J', 'M'}, {'A', 'N'}};
for (int i = 0; i < RCJA.length; i++) {
if (RCJA[i] >= TFMN[i]) {
answer += word[i][0];
}else {
answer += word[i][1];
}
}
return answer;
}
public int[] point(int i, int choice){
int[] points = {0,0,0};
points[1] = (i+2)/2;
if(choice == 4){
points[2] = 0;
}else if (choice < 4){
points[2] = 4 - choice;
points[0] = (i+2)%2;
}else{
points[2] = choice - 4;
points[0] = (i+3)%2;
}
return points;
}
}