[LeetCode] 1524. Number of Sub-arrays With Odd Sum (Python)
·
알고리즘/LeetCode
난이도: MediumProblem DescriptionGiven an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 109 + 7.  Problem ExampleExample 1:Input: arr = [1,3,5]Output: 4Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]All sub-arrays sum are [1,4,9,3,8,5].Odd sums are [1,9,3,5] so the answer is 4.Example 2:Input: arr = [2,4,..
[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] 2017. Grid Game (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix. Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)). At the start of the game, the first ro..
[LeetCode] 2381. Shifting Letters II (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명 You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0. Shifting a character forward means replacing it with the next letter in the alph..
[LeetCode] 2270. Number of Ways to Split Array (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed integer array nums of length n.nums contains a valid split at index i if the following are true:The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.There is at least one element to the right of i. That is, 0 Return the number of valid splits in nums. 문제 예제Example 1:Input: nums = [10,4,-8,7]Output: 2Expl..
[LeetCode] 2559. Count Vowel Strings in Ranges (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed array of strings words and a 2D array of integers queries. Each query queries[i] = [l_i, r_i] asks us to find the number of strings present in the range li to ri (both inclusive) of words that start and end with a vowel. Return an array ans of size queries.length, where ans[i] is the answer to the ith query. Note that the vowel letters are 'a', 'e', 'i'..