[LeetCode] 2558. Take Gifts From the Richest Pile (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:Choose the pile with the maximum number of gifts.If there is more than one pile with the maximum number of gifts, choose any.Leave behind the floor of the square root of the number of gifts in the pile. Take the rest of the gifts.Return the number of gifts remaini..
[LeetCode] 2779. Maximum Beauty of an Array After Applying Operation (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed array nums and a non-negative integer k.In one operation, you can do the following:Choose an index i that hasn't been chosen before from the range [0, nums.length - 1].Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].The beauty of the array is the length of the longest subsequence consisting of equal elements.Return the maximum ..
[LeetCode] 2981. Find Longest Special Substring That Occurs Thrice I (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a string s that consists of lowercase English letters.A string is called special if it is made up of only a single character. For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are special.Return the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.A su..
[LeetCode] 3152. Special Array II (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [from_i, to_i] your task is to check that subarray nums[from_i..to_i] is special or not. Return an array of booleans answer such that answer[i] is true if nums[from_i..to_i..
[LeetCode] 2054. Two Best Non-Overlapping Events (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed 2D integer array of events where events[i] = [startTime_i, endTime_i, value_i]. The ith event starts at startTime_i and ends at endTime_i, and if you attend this event, you will receive a value of value_i. You can choose at most two non-overlapping events to attend such that the sum of their values is maximized. Return this maximum sum. Note that the st..
[Programmers] 가장 먼 노드 (Python)
·
알고리즘/프로그래머스
난이도: Lv.3 문제 설명n개의 노드가 있는 그래프가 있습니다. 각 노드는 1부터 n까지 번호가 적혀있습니다. 1번 노드에서 가장 멀리 떨어진 노드의 갯수를 구하려고 합니다. 가장 멀리 떨어진 노드란 최단경로로 이동했을 때 간선의 개수가 가장 많은 노드들을 의미합니다. 노드의 개수 n, 간선에 대한 정보가 담긴 2차원 배열 vertex가 매개변수로 주어질 때, 1번 노드로부터 가장 멀리 떨어진 노드가 몇 개인지를 return 하도록 solution 함수를 작성해주세요. 제한 사항노드의 개수 n은 2 이상 20,000 이하입니다.간선은 양방향이며 총 1개 이상 50,000개 이하의 간선이 있습니다.vertex 배열 각 행 [a, b]는 a번 노드와 b번 노드 사이에 간선이 있다는 의미입니다. 입출력 예n..