Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

String Manipulation

Moderate
0/80
0 upvote

Problem statement

You are given a string S consisting of only lowercase alphabets of length at most 100 . A string T is created by concatenation of k copies of string S. Some changes are done to do in string T, such as -

You can pick a number p and character c and delete the p-th occurrence of character c from the string T

It is guaranteed that the letter to be deleted always exists, and after all operations not all letters are deleted from the string T. The letters' occurrences are numbered starting from 1.

Given string S, integer k and all the operations performed, you need to figure out the final string generated. N is the total number of operations performed. For every operation, p and c is given.

Detailed explanation ( Input/output format, Notes, Images )
Input Format :
Line 1 : Integer k 
Line 2 : A non-empty string S
Line 3 : Integer n
Next n lines : pi and ci, separated by space
Output Format :
Print a single string — final string after all changes are applied to it
Constraints :

1 ≤ k ≤ 2000

1 ≤ pi ≤ 200000

Sample Input 1 :
2
bacbac
3
2 a
1 b
2 c
Sample Output 1 :
acb
Sample Input 2 :
1
abacaba
4
1 a
1 a
1 c
2 b
Sample Output
baa
Sample Output 1 Explanation :

Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".

String Manipulation
Full screen
Console