1658. Minimum Operations to Reduce X to Zero

1658. Minimum Operations to Reduce X to Zero Difficulty: Medium Related Topics: Two Pointers, Binary Search, Greedy You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifiesContinueContinue reading “1658. Minimum Operations to Reduce X to Zero”

1657. Determine if Two Strings Are Close

1657. Determine if Two Strings Are Close Difficulty: Medium Related Topics: Greedy Two strings are considered close if you can attain one from the other using the following operations: Operation 1: Swap any two existing characters.For example, a<u style=”display: inline;”>b</u>cd<u style=”display: inline;”>e</u> -> a<u style=”display: inline;”>e</u>cd<u style=”display: inline;”>b</u>Operation 2: Transform every occurrence of one existingContinueContinue reading “1657. Determine if Two Strings Are Close”

998. Maximum Binary Tree II

998. Maximum Binary Tree II Difficulty: Medium Related Topics: Tree We are given the root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree. Just as in the , the given tree was constructed from an list A (root = Construct(A)) recursively with the following Construct(A) routine: IfContinueContinue reading “998. Maximum Binary Tree II”

713. Subarray Product Less Than K

713. Subarray Product Less Than K Difficulty: Medium Related Topics: Array, Two Pointers Your are given an array of positive integers nums. Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k. Example 1: Input: nums = [10, 5, 2, 6], k =ContinueContinue reading “713. Subarray Product Less Than K”

611. Valid Triangle Number

611. Valid Triangle Number Difficulty: Medium Related Topics: Array Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. Example 1: Input: [2,2,3,4] Output: 3 Explanation: Valid combinations are: 2,3,4 (usingContinueContinue reading “611. Valid Triangle Number”