최근 글 ✨

Study

[LeetCode] 570. Managers with at Least 5 Direct Reports

문제Write a solution to find managers with at least five direct reports.Return the result table in any order.The result format is in the following example. 쿼리SELECT NAMEFROM EMPLOYEEWHERE ID IN ( SELECT MANAGERID FROM EMPLOYEE GROUP BY MANAGERID HAVING COUNT(MANAGERID) >= 5); 제출하고 보니 생각보다 실행 시간이 길게 나왔다. 생각해보니 그냥 조인만 써서도 풀 수 있을 것 같아서 쿼리를 다시 작성했다 SELECT E.NAME..

[백준] 12891 DNA 비밀번호 Java

문제평소에 문자열을 가지고 노는 것을 좋아하는 민호는 DNA 문자열을 알게 되었다. DNA 문자열은 모든 문자열에 등장하는 문자가 {‘A’, ‘C’, ‘G’, ‘T’} 인 문자열을 말한다. 예를 들어 “ACKA”는 DNA 문자열이 아니지만 “ACCA”는 DNA 문자열이다. 이런 신비한 문자열에 완전히 매료된 민호는 임의의 DNA 문자열을 만들고 만들어진 DNA 문자열의 부분문자열을 비밀번호로 사용하기로 마음먹었다.하지만 민호는 이러한 방법에는 큰 문제가 있다는 것을 발견했다. 임의의 DNA 문자열의 부분문자열을 뽑았을 때 “AAAA”와 같이 보안에 취약한 비밀번호가 만들어 질 수 있기 때문이다. 그래서 민호는 부분문자열에서 등장하는 문자의 개수가 특정 개수 이상이여야 비밀번호로 사용할 수 있다는 규칙을 ..

[LeetCode] 97. Rising Temperature

문제Write a solution to find all dates' id with higher temperatures compared to its previous dates (yesterday).Return the result table in any order.The result format is in the following example. 전날보다 온도가 높은 날의 id값을 출력하면 된다. 쿼리 #1SELECT a.id AS IdFROM Weather aJOIN Weather b ON DATEDIFF(a.recordDate, b.recordDate) = 1 AND a.temperature > b.temperature; 쿼리 #2(LAG 활용)SELECT idFROM ( SELECT ..

[LeetCode] 196. Delete Duplicate Emails

문제Write a solution to delete all duplicate emails, keeping only one unique email with the smallest id.For SQL users, please note that you are supposed to write a DELETE statement and not a SELECT one.For Pandas users, please note that you are supposed to modify Person in place.After running your script, the answer shown is the Person table. The driver will first compile and run your piece of cod..

[백준] 17144 미세먼지 안녕! Java

문제미세먼지를 제거하기 위해 구사과는 공기청정기를 설치하려고 한다. 공기청정기의 성능을 테스트하기 위해 구사과는 집을 크기가 R×C인 격자판으로 나타냈고, 1×1 크기의 칸으로 나눴다. 구사과는 뛰어난 코딩 실력을 이용해 각 칸 (r, c)에 있는 미세먼지의 양을 실시간으로 모니터링하는 시스템을 개발했다. (r, c)는 r행 c열을 의미한다.공기청정기는 항상 1번 열에 설치되어 있고, 크기는 두 행을 차지한다. 공기청정기가 설치되어 있지 않은 칸에는 미세먼지가 있고, (r, c)에 있는 미세먼지의 양은 Ar,c이다.1초 동안 아래 적힌 일이 순서대로 일어난다.미세먼지가 확산된다. 확산은 미세먼지가 있는 모든 칸에서 동시에 일어난다.(r, c)에 있는 미세먼지는 인접한 네 방향으로 확산된다.인접한 방향에 ..

[백준] 2473 빙산 Java

문제지구 온난화로 인하여 북극의 빙산이 녹고 있다. 빙산을 그림 1과 같이 2차원 배열에 표시한다고 하자. 빙산의 각 부분별 높이 정보는 배열의 각 칸에 양의 정수로 저장된다. 빙산 이외의 바다에 해당되는 칸에는 0이 저장된다. 그림 1에서 빈칸은 모두 0으로 채워져 있다고 생각한다. 2453 3 252 7624 그림 1. 행의 개수가 5이고 열의 개수가 7인 2차원 배열에 저장된 빙산의 높이 정보빙산의 높이는 바닷물에 많이 접해있는 부분에서 더 빨리 줄어들기 때문에, 배열에서 빙산의 각 부분에 해당되는 칸에 있는 높이는 일년마다 그 칸에 동서남북 네 방향으로 붙어있는 0이 저장된 칸의 개수만큼 줄어든다. 단, 각 칸에 저장된 높이는 0보다 더 줄어들지 않는다. 바닷물은 ..

[LeetCode] 185. Department Top Three Salaries

문제A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.Write a solution to find the employees who are high earners in each of the departments.Return the result table in any order.The result format is in the following example...

[LeetCode] 184. Department Highest Salary

문제Write a solution to find employees who have the highest salary in each of the departments.Return the result table in any order.The result format is in the following example. 쿼리SELECT B.NAME AS DEPARTMENT, A.NAME AS EMPLOYEE, A.SALARY AS SALARYFROM EMPLOYEE ALEFT JOIN DEPARTMENT B ON A.DEPARTMENTID = B.IDWHERE (A.DEPARTMENTID, A.SALARY) IN ( SELECT ..

[LeetCode] 183. Customers Who Never Order

문제Write a solution to find all customers who never order anything.Return the result table in any order.The result format is in the following example. 아무것도 주문하지 않은 사용자를 출력하면 된다. 쿼리 #1 NOT INSELECT NAME AS CUSTOMERSFROM CUSTOMERSWHERE ID NOT IN ( SELECT CUSTOMERID FROM ORDERS ); #2 JOIN + IS NULLSELECT A.NAME AS CUSTOMERSFROM CUSTOMERS A..

[LeetCode] 182. Duplicate Emails

문제Write a solution to report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.Return the result table in any order.The result format is in the following example. 중복되는 이메일이 있으면 해당 이메일을 출력하도록 해야한다. 쿼리SELECT EMAILFROM PERSONGROUP BY EMAILHAVING COUNT(EMAIL) > 1; 문제 출처https://leetcode.com/problems/duplicate-emails/description/