Distinct characters
Practice
4 (2 votes)
Medium
Hiring
Range query
Recruit
Data structures
Strings
Problem
58% Success 607 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 \)
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:20
20 votes
Tags:
Binary search algorithmNumber TheoryAlgorithmsEasyMathematicsOpenApproved
Points:30
1 votes
Tags:
MediumAlgorithmsMathematicsOpenApprovedGame Theory
Points:30
82 votes
Tags:
Medium
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