[LeetCode] 1945. Sum of Digits of String After Convert (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps:Convert s into an integer by replacing each letter with its position in the alphabet (i.e. replace 'a' with 1, 'b' ..
[LeetCode] 2593. Find Score of an Array After Marking All Elements (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given an array nums consisting of positive integers.Starting with score = 0, apply the following algorithm:Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.Add the value of the chosen integer to score.Mark the chosen element and its two adjacent elements if they exist.Repeat until all the array element..
[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..