Vowel Query
Practice
5 (3 votes)
Algorithms
Binary search
Implementation
Medium
Searching
Problem
48% Success 4063 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string S consisting of lowercase alphabets and an integer array val consisting of N integers. Using the given string S and array val, you need to create another string X according to the code snippet below:


Initially string X is empty
Let len be the length of string S

for i := 0 to N-1
    pos := absolute value of val[i]
    if(val[i] >= 0)
      X := X + S[0,pos] // append substring of string S from index 0 to pos (both including) into X
    else
      X := X + S[pos,len-1] // append substring of string S from index pos to len-1 (both including) into X

You have to answer Q tasks. For each task, you are given an integer K and you have to print the Kth vowel in the string X. If the Kth vowel doesn't exist print -1.

Note: The vowels are a, e, io, and u.

Input Format:

The first line contains a string S.

The second line contains an integer N.

The third line contains N space-separated integers, denoting the element of the array val.

The fourth line contains an integer Q, denoting the number of tasks.

The fifth line contains Q space-separated integers, denoting the tasks.

Output Format:

Print the answer for each of the Q tasks in a newline.

Constraints:

\(1 \le |S|,N,Q \le10^5\)

\(0\le |val_i| \le|S|-1\)

\(1 \le K \le 10^{10}\)

All the characters of string S are lowercase characters only.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
Binary SearchAlgorithmsGreedy Algorithms
Points:30
10 votes
Tags:
AlgorithmsBinary SearchGreedy AlgorithmsMediumOpenSorting
Points:30
53 votes
Tags:
Matrix ExponentiationMedium