Problem Statement:
You are given an array of integers and a number d. Select a group of three elements where the difference between the largest and smallest values in the group is at most d.
Return the total number of such groups, modulo (10^9 + 7).
Example 1:
Input: arr = [-3, -2, -1, 0], d = 2
Output: 2
Explanation:
All Valid Triplets:
Elements: [-3, -2, -1] Maximum Difference: (-1) - (-3) = 2
Elements: [-2, -1, 0] Maximum Difference: 0 - (-2) = 2
Example 2:
Input: arr = [2, 1, 3, 4], d = 3
Output: 4
Explanation:
All Valid Triplets:
Elements: [2, 1, 3] Maximum Difference: 3 - 1 = 2
Elements: [2, 1, 4] Maximum Difference: 4 - 1 = 3
Elements: [2, 3, 4] Maximum Difference: 4 - 2 = 2
Elements: [1, 3, 4] Maximum Difference: 4 - 1 = 3
Problem Statement:
A palindrome is a string that reads the same forwards and backwards, such as 121 or tacocat. A substring is a continuous sequence of characters within a string.
Given a string $s$, how many unique substrings of s are palindromes?
Example:
s = "mokkori"
Some of its substrings are [m, o, k, r, i, mo, ok, mok, okk, kk, okko].
There are 7 distinct palindromes: [m, o, k, r, i, kk, okko].
Function Description:
Complete the function palindrome in the editor.
palindrome has the following parameter(s):
string s: a string
Returns:
int: the number of distinct palindromes