here is a code that works in O(n) void solve() { ll n; cin >> n; vector<ll> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } unordered_map<ll, ll, custom_hash> index; ll ans = 0, low = 0; for (int i = 1; i <= n; i++) { if (index...
void badCharHeuristic(const string &pattern, unordered_map<char, int> &badCharacter) { int patternLength = pattern.length(); for (int i = 0; i < patternLength - 1; ++i) { badCharacter[pattern[i]] = patternLength - 1 - i; }}void boyermoore(const string &text, const string &...
Directly realizing this in code using a matrix to cache intermediate recursion values results in aO(I * n^2)upper bound for the time complexity. The key insight in improving the time complexity is that the contiguous region in the text that ends at a certain indexi, where all characters in...