Tap here to switch tabs
Problem
Submissions

Problem: Number of Same-End Substrings

Try to solve the Number of Same-End Substrings problem.

Statement

You are given a string s and a 22D integer array queries where queries[i] =[li,ri]= [l_i, r_i].

A same end substring is a substring whose first character and last character are identical.

For each query, determine the number of same end substrings contained within the substring extending from index lil_i to index rir_i inclusive.

Return an array of integers representing the answer to each query in the order they appear.

Constraints:

  • 2≤2 \leq s.length ≤3×104\leq 3 \times 10^4

  • s consists only of lowercase English letters.

  • 1≤1 \leq queries.length ≤3×104\leq 3 \times 10^4

  • queries[i] =[li,ri]= [l_i, r_i]

  • 0≤li≤ri<0 \leq l_i \leq r_i < s.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Same-End Substrings

Try to solve the Number of Same-End Substrings problem.

Statement

You are given a string s and a 22D integer array queries where queries[i] =[li,ri]= [l_i, r_i].

A same end substring is a substring whose first character and last character are identical.

For each query, determine the number of same end substrings contained within the substring extending from index lil_i to index rir_i inclusive.

Return an array of integers representing the answer to each query in the order they appear.

Constraints:

  • 2≤2 \leq s.length ≤3×104\leq 3 \times 10^4

  • s consists only of lowercase English letters.

  • 1≤1 \leq queries.length ≤3×104\leq 3 \times 10^4

  • queries[i] =[li,ri]= [l_i, r_i]

  • 0≤li≤ri<0 \leq l_i \leq r_i < s.length