[LeetCode] 2375. Construct Smallest Number From DI String (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing. A 0-indexed string num of length n + 1 is created using the following conditions:num consists of the digits '1' to '9', where each digit is used at most once.If pattern[i] == 'I', then num[i] .If pattern[i] == 'D', then num[i] > num[i + 1].Return th..
[LeetCode] 1079. Letter Tile Possibilities (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles. 문제 예제Example 1:Input: tiles = "AAB"Output: 8Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".Example 2:Input: tiles = "AAABBC"Output: 188Example 3:Input:..
[LeetCode] 1718. Construct the Lexicographically Largest Valid Sequence (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명Given an integer n, find a sequence that satisfies all of the following:The integer 1 occurs once in the sequence.Each integer between 2 and n occurs twice in the sequence.For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.The distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j -..
[LeetCode] 2698. Find the Punishment Number of an Integer (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 Given a positive integer n, return the punishment number of n. The punishment number of n is defined as the sum of the squares of all integers i such that:1 The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i. 문제 예제Example 1:Input: n = 10Output: 182Explanation: There are exactly 3 ..
[LeetCode] 1352. Product of the Last K Numbers (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명Design an algorithm that accepts a stream of integers and retrieves the product of the last k integers of the stream. Implement the ProductOfNumbers class:ProductOfNumbers() Initializes the object with an empty stream.void add(int num) Appends the integer num to the stream.int getProduct(int k) Returns the product of the last k numbers in the current list. You can assume that alw..
[LeetCode] 3066. Minimum Operations to Exceed Threshold Value II (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed integer array nums, and an integer k. In one operation, you will: Take the two smallest integers x and y in nums.Remove x and y from nums.Add min(x, y) * 2 + max(x, y) anywhere in the array. Note that you can only apply the described operation if nums contains at least two elements. nums. Return the minimum number of operations needed so that all element..