Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0436389

Browse files
committedMar 9, 2025
Add solution #2559
1 parent 15636d4 commit 0436389

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@
768768
2529|[Maximum Count of Positive Integer and Negative Integer](./2529-maximum-count-of-positive-integer-and-negative-integer.js)|Easy|
769769
2535|[Difference Between Element Sum and Digit Sum of an Array](./2535-difference-between-element-sum-and-digit-sum-of-an-array.js)|Easy|
770770
2542|[Maximum Subsequence Score](./2542-maximum-subsequence-score.js)|Medium|
771+
2559|[Count Vowel Strings in Ranges](./2559-count-vowel-strings-in-ranges.js)|Medium|
771772
2570|[Merge Two 2D Arrays by Summing Values](./2570-merge-two-2d-arrays-by-summing-values.js)|Easy|
772773
2579|[Count Total Number of Colored Cells](./2579-count-total-number-of-colored-cells.js)|Medium|
773774
2618|[Check if Object Instance of Class](./2618-check-if-object-instance-of-class.js)|Medium|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 2559. Count Vowel Strings in Ranges
3+
* https://leetcode.com/problems/count-vowel-strings-in-ranges/
4+
* Difficulty: Medium
5+
*
6+
* You are given a 0-indexed array of strings words and a 2D array of integers queries.
7+
*
8+
* Each query queries[i] = [li, ri] asks us to find the number of strings present at the
9+
* indices ranging from li to ri (both inclusive) of words that start and end with a vowel.
10+
*
11+
* Return an array ans of size queries.length, where ans[i] is the answer to the ith query.
12+
*
13+
* Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.
14+
*/
15+
16+
/**
17+
* @param {string[]} words
18+
* @param {number[][]} queries
19+
* @return {number[]}
20+
*/
21+
var vowelStrings = function(words, queries) {
22+
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
23+
const prefix = [0];
24+
for (let i = 0; i < words.length; i++) {
25+
prefix[i + 1] = prefix[i] + (vowels.has(words[i][0]) && vowels.has(words[i].at(-1)));
26+
}
27+
return queries.map(([l, r]) => prefix[r + 1] - prefix[l]);
28+
};

0 commit comments

Comments
 (0)
Please sign in to comment.