[LeetCode] 1122. Relative Sort Array (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order. 문제 예제Example 1:Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]Output..
[LeetCode] 1014. Best Sightseeing Pair (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them. The score of a pair (i ) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them. Return the maximum score of a pair of sightseeing s..
[LeetCode] 494. Target Sum (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given an integer array nums and an integer target.You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.For example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression "+2-1".Return the number of different expressions ..
[LeetCode] 1962. Remove Stones to Minimize the Total (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remove floor(piles[i] / 2) stones from it.Notice that you can apply the operation on the same pile more than once. Return the minimum possible total number of stones rema..
[LeetCode] 2337. Move Pieces to Obtain a String (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where:The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if there is a blank space directly to its right.The character '_' repres..
[LeetCode] 769. Max Chunks To Make Sorted (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1]. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array. Return the largest number of chunks we can make to sort the array. 문제 예제Example 1:Input: arr = [4,3,2,..