Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Prashant Mishra
Prashant Mishra

Posted on

Count vowel strings in ranges

Problem

TC: O(n) for calculating the prefix[] and O(k) for getting all the counts of the vowels in the given ranges

classSolution{publicint[]vowelStrings(String[]words,int[][]queries){intresult[]=newint[queries.length];intprefix[]=newint[words.length];intcurrentCount=0;for(inti=0;i<words.length;i++){Strings=words[i];currentCount+=check(s.charAt(0))&&check(s.charAt(s.length()-1))?1:0;prefix[i]=currentCount;}for(inti=0;i<queries.length;i++){intleft=queries[i][0];intright=queries[i][1];intrightCount=prefix[right];intleftCount=left>0?prefix[left-1]:0;result[i]=rightCount-leftCount;}returnresult;}publicbooleancheck(charc){returnc=='a'||c=='e'||c=='i'||c=='o'||c=='u';}}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

There is always a price for those who persevere.
  • Location
    India
  • Education
    Computer Science
  • Work
    Software Engineer @JPMorganChase&Co.
  • Joined

More fromPrashant Mishra

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp