All Posts

Leetcode 998: Maximum Binary Tree II

You are given the root of a maximum binary tree and an integer val. The task is to insert val into the tree by constructing a new maximum binary tree with a list that contains val appended to the original list used to construct the tree.

Leetcode 1003: Check If Word Is Valid After Substitutions

You are given a string s consisting of only the characters ‘a’, ‘b’, and ‘c’. A string is considered valid if it can be formed by repeatedly inserting the substring ‘abc’ into any position of an empty string. Your task is to determine if s can be a valid string after performing this operation any number of times.

Leetcode 1004: Max Consecutive Ones III

Given a binary array nums and an integer k, return the maximum number of consecutive 1’s in the array if you can flip at most k 0’s to 1’s.

Leetcode 1006: Clumsy Factorial

Given a positive integer n, compute the ‘clumsy factorial’ of n. A clumsy factorial is computed using a series of operations (multiplication, division, addition, subtraction) in a fixed order applied to the integers from n down to 1. The operations follow this order: multiplication ‘*’, division ‘/’, addition ‘+’, subtraction ‘-’, and are repeated cyclically. Division is performed as floor division, and multiplication and division are processed left to right before addition and subtraction.

Leetcode 1007: Minimum Domino Rotations For Equal Row

You are given two arrays, tops and bottoms, where each array represents the top and bottom halves of a series of dominoes. A domino can be rotated, which means swapping its top and bottom halves. The task is to determine the minimum number of rotations required to make either the entire top row or the bottom row consist of the same value. If it is not possible to achieve this, return -1.

Leetcode 1008: Construct Binary Search Tree from Preorder Traversal

You are given an array representing the preorder traversal of a binary search tree (BST). Your task is to construct the BST from this preorder traversal and return the root of the tree.