Calculate the minimum number of parentheses to add to make a string valid.
A parentheses string is valid if and only if it is empty, or properly balanced. Return the minimum number of parentheses you must add to make the resulting string valid.
Input: s = "((("
Output: 3
Explanation: There are three open parentheses without any matchi…
Unique Combinations that Sum to a Target
Find all unique combinations in an array that sum to a target.
Input: candidates = [2,4,6], target = 6
Output: [[2,2,2], [2,4], [6]]
Explanation: Uses backtracking to find all valid combinations that sum to 6, allowing for explicitly repeated elements.
Count nodes in a complete binary tree.
Given the root of a complete binary tree, return the number of the nodes in the tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.
Input: root = [1,2,3,4,5,6,7]
Output: 7
Explanation: The lowes…
Continuous Subarrays Sum Equals K
Find the total number of continuous subarrays whose sum equals K.
Input: nums = [1,2,3], k = 3
Output: 2
Explanation: Both the contiguous subarray [1,2] and the single-element subarray [3] sum perfectly to the target of 3.