Distinct characters
Practice
0 (0 votes)
Medium
Hiring
Range query
Recruit
Data structures
Strings
Problem
64% Success 31 Attempts 30 Points 1.5s Time Limit 256MB Memory 1024 KB Max Code
You are given a string S of length N and there are Q queries. In each query, you are provided with 2 integers L and R. You need to find the number of distinct characters present in the range L to R.
Input :
- First line of Input contains N , length of string S.
- Second line of input contains string S containing lowercase alphabets only.
- Third line of Input contains Q , number of queries
- Each following Q lines contains 2 integers , L and R .
Output :
For each query , output number of distinct characters in newline .
Constraints :
- \( 1 \le N \le 10^{5} \)
- \( 1 \le Q \le 10^{5} \)
- \( 1 \le L \le R \le N \)
Sample Input
6 nikunj 2 1 6 1 4
Sample Output
5 4
Explanation
In the First Query , there are 5 distinct characters from substring 'nikunj ' .
In the Second Query , 4 there are 4 distinct characters from substring 'niku'.
Code Editor
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
Submissions
Please login to view your submissions
Similar Problems
Points:30
15 votes
Tags:
2D dynamic programmingAlgorithmsData StructuresDynamic Programming
Points:50
18 votes
Tags:
AlgorithmsGraphsGreatest common divisorMediumSievegcdscc
Points:50
19 votes
Tags:
ArraysData StructuresMedium
Editorial
Login to unlock the editorial
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