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 &...
Their patterns are unordered sets of characters, and they match contiguous sequences of characters in the text that only contain characters in the set. The pattern can be omitted to match any character. Also, i type patterns can match sequences of any length if the length parameter is ...