ACl2 - Editorial

DIFFICULTY:

Easy

PREREQUISITES:

Condition and loop execution

PROBLEM:

To find number of vowels on even position of a given string.

EXPLANATION:

To solve this problem, first we have to initialize the counter by 0, then apply for loop from i=0 to i<(length of string) then we have to check whether the the position is even or odd, if the position is even then we have check whether the character at that position is vowel or not if vowel then increment the counter. After the completion of for loop print the counter.

Steps

  1. s<- string
  2. counter=0.
  3. for i=0 to i<lengthOfString
  4. if (i+1)%2!=0 then
  5.  if s[i] is vowel then
    
  6.  	counter = counter \+ 1  
    
  7. print(counter)

For Example:

Let s = 'programmer'

1. Characters at even positions are ('r','g','a','m','r'),
2. Only one vowel at even positions,
3. so output will be 1.

TIME COMPLEXITY:

n: length of string
Best: O(n/2)
Worst: O(n)

//