
You are given several independent implementation-focused tasks. For each task, write a function that returns the required value.
Given a string s, consider every contiguous substring of length 3: s[i..i+2] for 0 ≤ i ≤ len(s)-3.
Count how many such windows satisfy:
lower(s[i]) == lower(s[i+2])
(case-insensitive comparison)
Output: an integer count.
Notes:
len(s) < 3
, the answer is
0
.
You are given an m x n integer matrix grid where each integer represents a “color”.
A cell (r, c) has up to 4 orthogonal neighbors: up, down, left, right.
A cell (r, c) is considered a trigger if at least 2 of its orthogonal neighbors have the same value as grid[r][c].
When a cell triggers, the cell itself and all orthogonal neighbors that match its value are marked to be removed.
All removals for the step happen simultaneously.
After removals, the removed positions become empty. Then, for each column independently:
0
.
Repeat Explosion → Gravity until no more cells trigger.
Output: the final matrix after the process stabilizes.
Clarifications:
0
is treated as an empty cell after gravity; it does
not
participate in explosions.
Given a list of strings words of length n and a target string target, count the number of ordered index pairs (i, j) such that:
0 ≤ i, j < n
i != j
words[i] + words[j] == target
Output: an integer count.
Important: Ordered pairs are distinct, so (i, j) and (j, i) are counted separately when both satisfy the condition.