Input: integer array nums (length n), integers K (1 ≤ K ≤ 10^
and R (0 ≤ R < K).
Output: the number of subarrays [i..j] such that (sum(nums[i..j]) mod K) == R.
Requirements: O(n) time and O(K) space; describe the approach, justify correctness, and analyze complexity. Provide an implementation of countSubarraysByRemainder(nums, K, R).
Remove the minimum parentheses to balance a string
Input: string s containing lowercase letters and parentheses '()'.
Output: any string formed by deleting the minimum number of parentheses so that the result is a valid, balanced parentheses string (characters’ relative order must be preserved).
Requirements: O(n) time and O(
extra space beyond the output; describe the algorithm and provide an implementation.