Skip to main content

Posts

Leetcode 93: Restore IP Addresses

  1. Problem Summary You’re given a string s consisting only of digits. You must insert  three dots  into s to form  exactly four parts  that make a valid IPv4 address: Each part is an integer in [0, 255]. No leading zeros allowed,  unless  the part is exactly "0". You must: Use all digits in s in order (no reordering or deletion). Return  all  possible valid IP addresses in any order. Input:  s (string of digits, 1 <= len(s) <= 20) Output:  List of strings, each a valid IPv4 address formed from s. 2. Examples Explanation Example 1: Input:  s = "25525511135" Output:  ["255.255.11.135","255.255.111.35"] Possible splits into 4 segments that are in [0,255] and valid (no leading zeros): 255.255.11.135: all segments valid. 255.255.111.35: all segments valid. Other splits either exceed 255 or create leading zeros. Example 2: Input:  s = "0000" Output: ...

Valid Parenthesis String Practice

  Problem Summary You’re given a string parenthesisString containing only '(', ')', and '*'. Rules: Each '(' must have a matching ')' after it. Each ')' must have a matching '(' before it. Each '*' can be treated as: '(', or ')', or empty string "". For each test case, you must determine if there exists  some  interpretation of '*' such that the whole string becomes a  valid parenthesis string . Input: T test cases. For each test case: One string parenthesisString of length between 1 and 100. Output: For each test case, print true if the string can be valid, otherwise false. Constraints: 1 <= T <= 10 5 1 <= |parenthesisString| <= 1001 Characters are only '(', ')', '*'. Total characters over all test cases ≤ 10 7 , still fine for an O(n) solution per test. Examples Explanation Sample Input: 5 () (*) (*)) ((*)...