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 \)

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
72 votes
Tags:
Binary SearchHash MapsMediumOpenSorting
Points:10
1 votes
Tags:
Very-Easy
Points:50
3 votes
Tags:
AlgorithmsApprovedHardOpenSegment TreesTrees