Mothers Day and Fathers Day Challenge problems
All codes for the Fathers Day and Mothers Day Challenge
Problem Description Given an integer rowIndex, return the rowIndex-th (0-indexed) row of Pascal's Triangle. In Pascal’s Triangle, each number is the sum of the two numbers directly above it.
Input: rowIndex = 3 Output: [1, 3, 3, 1]
We start with the first element 1 and iteratively build each row using the previous values. We update the list in reverse order to avoid overwriting values.
Pascal's Triangle builds from previous rows. Reverse traversal helps avoid overwriting values while updating.
Problem Statement Given a string s containing only three types of characters: '(', ')', and '*', return true if s is valid.
Every '(' must have a corresponding ')'. Every ')' must have a corresponding '('. '(' must appear before the corresponding ')'. '*' can be treated as '(', ')', or an empty string "".
Input: s = "()" Output: true
We use a Greedy strategy to keep track of the range of possible open parentheses at any point:
Steps: Iterate through each character in the string. Update minOpen and maxOpen based on character: '(': increment both ')': decrement both '*': decrement minOpen, increment maxOpen If at any point maxOpen < 0, return false. If minOpen drops below 0, reset it to 0. After the loop, return true if minOpen == 0.