This question evaluates string algorithm skills — specifically parentheses balancing and shortest covering-substring problems — testing linear-time algorithm design, frequency tracking, and handling of large input-size constraints in the coding & algorithms domain.

Answer both parts. A) Parentheses correction: Given a string s consisting only of '(' and ')', output the minimum number of parentheses you must insert (at any positions) to make s a valid balanced parentheses string. Define validity in the usual way via matching pairs and proper nesting. Constraints: 1 <= |s| <= 100,000. Describe an O(n)-time algorithm with O(