2635. Apply Transform Over Each Element in Array
⭐️ # 題目敘述 Given an integer array arr and a mapping function fn , return a new array with a transformation applied to each element. The returned array should be created such that returnedArray[i] = fn(arr[i], i) . Please solve it without the built-in Array.map method. # Example 1 Input: arr =...
more...1572. Matrix Diagonal Sum
⭐️ # 題目敘述 Given a square matrix mat , return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. # Example 1 Input: mat = [[1,2,3], [4,5,6], [7,8,9]] Output:...
more...2665. Counter II
⭐️ # 題目敘述 Write a function createCounter . It should accept an initial integer init . It should return an object with three functions. The three functions are: increment() increases the current value by 1 and then returns it. decrement() reduces the current value by 1 and then returns it. reset()...
more...1498. Number of Subsequences That Satisfy the Given Sum Condition
⭐️⭐️ # 題目敘述 You are given an array of integers nums and an integer target . Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target . Since the answer may be too large, return it modulo 10^9 + 7 . # Example 1 Input:...
more...2620. Counter
⭐️ # 題目敘述 Given an integer n , return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called ( n , n + 1 , n + 2 , etc). # Example 1 Input: n = 10 [“call”,“call”,“call”] Output:...
more...2667. Create Hello World Function
⭐️ # 題目敘述 Write a function createHelloWorld . It should return a new function that always returns "Hello World" . # Example 1 Input: args = [] Output: “Hello World” Explanation: const f = createHelloWorld(); f(); // “Hello World” The function returned by createHelloWorld should...
more...1456. Maximum Number of Vowels in a Substring of Given Length
⭐️⭐️ # 題目敘述 Given a string s and an integer k , return the maximum number of vowel letters in any substring of s with length k . Vowel letters in English are 'a' , 'e' , 'i' , 'o' , and 'u' . # Example 1 Input: s = “abciiidef”, k = 3 Output: 3 Explanation:...
more...1964. Find the Longest Valid Obstacle Course at Each Position
⭐️⭐️⭐️ # 題目敘述 You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n , where obstacles[i] describes the height of the ith obstacle. For every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such...
more...649. Dota2 Senate
⭐️⭐️ # 題目敘述 In the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of senators coming from two parties. Now the Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can...
more...