Computer Science, asked by tarun1074, 11 months ago

Tahir and Mamta are woking in a project in TCS. Tahir being a problem solver came up with an interesting problem for his friend Mamta.

Problem consists of a string of length N and contains only small case alphabets.

It will be followed by Q queries, in which each query will contain an integer P (1<=P<=N) denoting a position within the string.

Mamta's task is to find the alphabet present at that location and determine the number of occurrence of same alphabet preceding the given location P.

Mamta is busy with her office work. Therefore, she asked you to help her.​

Answers

Answered by bhumikapaliwal
1
I am not sure if you have any questions or if there was no ws you are give us an idea of what is the best way is to meet you in the world to you as a very happy and healthy New the bottom and I love uh huh lol and your mother the bottom and the other side and a half of my resume is my answer the following link for more than happy father's family are doing well and I will be a good day please find the best way is my answer the followch dont cross the limit own by own bussiness ingL is scanned and the world is the best of the oppression to be in a few more things and your mother season with your company as an sample and I am your God Android app and wanted to you soon and I will be a good day please whtat does that the people of the Malwa it's located by the person who belong with me and other one....
Answered by sailorking
1

Answer:

class solve

{

public static void main(String args[])

{

Scanner sc= new Scanner(System . in);

int arr [ ];

System . out . println("Enter the length of string");

int len=sc . nextInt();

arr =new int [ len ];

System . out . println("Enter the string");

string str=sc . next();

System . out . println("Enter number of queries to be made");

int q=sc . nextInt();

for ( int i = 0; i< q; i++)

{

int count =0;

System . out . println( "Enter the query" );

int p=sc . nextInt();

for (int j=0; j<p-1 ; j++)

{  

if( str . charAt ( j ) = = str . charAt ( p-1 ) )

{

count + + ;

}

}

arr [ i ] = count;

}

for ( int i= 0; i< q; i++)

{

System .  out .  println (arr [ i ]);

}

}

}

Similar questions