2813. Maximum Elegance of a K-Length Subsequence
You are given a 0-indexed 2D integer array
itemsof lengthnand an integerk.
items[i] = [profiti, categoryi], whereprofitiandcategoryidenote the profit and category of theithitem respectively.Let’s define the elegance of a subsequence of
itemsastotal_profit + distinct_categories2, wheretotal_profitis the sum of all profits in the subsequence, anddistinct_categoriesis the number of distinct categories from all the categories in the selected subsequence.Your task is to find the maximum elegance from all subsequences of size
kinitems.Return an integer denoting the maximum elegance of a subsequence of
itemswith size exactlyk.Note: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements’ relative order.
2812. Find the Safest Path in a Grid
You are given a 0-indexed 2D matrix
gridof sizen x n, where(r, c)represents:
- A cell containing a thief if
grid[r][c] = 1- An empty cell if
grid[r][c] = 0You are initially positioned at cell
(0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.
Return the maximum safeness factor of all paths leading to cell
(n - 1, n - 1).An adjacent cell of cell
(r, c), is one of the cells(r, c + 1),(r, c - 1),(r + 1, c)and(r - 1, c)if it exists.The Manhattan distance between two cells
(a, b)and(x, y)is equal to|a - x| + |b - y|, where|val|denotes the absolute value of val.
2811. Check if it is Possible to Split Array
You are given an array
numsof lengthnand an integerm. You need to determine if it is possible to split the array intonnon-empty arrays by performing a series of steps.In each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:
- The length of the subarray is one, or
- The sum of elements of the subarray is greater than or equal to
m.Return
trueif you can split the given array intonarrays, otherwise returnfalse.Note: A subarray is a contiguous non-empty sequence of elements within an array.
Your laptop keyboard is faulty, and whenever you type a character
'i'on it, it reverses the string that you have written. Typing other characters works as expected.You are given a 0-indexed string
s, and you type each character ofsusing your faulty keyboard.Return the final string that will be present on your laptop screen.
2806. Account Balance After Rounded Purchase
Initially, you have a bank account balance of
100dollars.You are given an integer
purchaseAmountrepresenting the amount you will spend on a purchase in dollars.At the store where you will make the purchase, the purchase amount is rounded to the nearest multiple of
10. In other words, you pay a non-negative amount,roundedAmount, such thatroundedAmountis a multiple of10andabs(roundedAmount - purchaseAmount)is minimized.If there is more than one nearest multiple of
10, the largest multiple is chosen.Return an integer denoting your account balance after making a purchase worth
purchaseAmountdollars from the store.Note:
0is considered to be a multiple of10in this problem.
2807. Insert Greatest Common Divisors in Linked List
Given the head of a linked list
head, in which each node contains an integer value.Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.
Return the linked list after insertion.
The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.