Encode and Decode Strings — Delimiter and Length-Prefix Schemes
Design an encode/decode scheme for a list of strings. Length-prefix encoding (4-byte header per string) is collision-proof unlike delimiter-based approaches.
1575 articles
Design an encode/decode scheme for a list of strings. Length-prefix encoding (4-byte header per string) is collision-proof unlike delimiter-based approaches.
Add minimum characters to the front of a string to make it a palindrome. KMP trick: concatenate s + '#' + rev(s), find the LPS value at the last position.
Count the number of distinct substrings using the suffix array and LCP array. Total substrings minus sum of LCP values gives distinct count in O(n log n).
Implement run-length encoding, string compression in-place, and decode compressed strings. Tests two-pointer technique and string manipulation.
Advanced trie applications beyond basic insert/search: binary trie for XOR maximization, palindrome pairs detection, and stream search using Aho-Corasick automaton concept.