Solved! Leetcode 1586. Binary Search Tree Iterator II

source: https://leetcode.com/problems/binary-search-tree-iterator-ii/description/ Binary Search Tree Iterator II Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number ...

Solved! Leetcode 320. Generalized Abbreviation

source: https://leetcode.com/problems/generalized-abbreviation/description/ Generalized Abbreviation A word’s generalized abbreviation can be constructed by taking any number of non-overlapping and non-adjacent substrings and replacing them with their respective lengths. For example, "abcde" can be abbreviated into: "a3e" ("bcd" turned into "3") "1bcd1" ("a" and "e" both turned into "1") "5" ("abcde" turned into "5") "abcde" (no substrings ...

Solved! Leetcode 638. Shopping Offers

source: https://leetcode.com/problems/shopping-offers/description/ Shopping Offers In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. You are given an integer array price where price[i] is the price of the ...

Solved Leetcode 474. Ones and Zeroes

source: https://leetcode.com/problems/ones-and-zeroes/description/ Ones and Zeroes You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0’s and n 1’s in the subset. A set x is a subset of a set y if all ...

Solved! Leetcode 1255. Maximum Score Words Formed by Letters

source: https://leetcode.com/problems/maximum-score-words-formed-by-letters/description/ Maximum Score Words Formed by Letters Given a list of words, list of single letters (might be repeating) and score of every character. Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times). It is not necessary to use ...

Solved! Leetcode 1129: Shortest Path with Alternating Colors

source: https://leetcode.com/problems/shortest-path-with-alternating-colors/ You are given an integer n, the number of nodes in a directed graph where the nodes are labeled from 0 to n – 1. Each edge is red or blue in this graph, and there could be self-edges and parallel edges. You are given two arrays redEdges and blueEdges where: redEdges[i] = ...

Solved! Leetcode 2477. Minimum Fuel Cost to Report to the Capital

source: https://leetcode.com/problems/minimum-fuel-cost-to-report-to-the-capital/description/ There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n – 1 and exactly n – 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that ...

Solved! Leetcode 1463. Cherry Pickup II

Solved! Leetcode 1463. Cherry Pickup II
source: https://leetcode.com/problems/cherry-pickup-ii/description/ Cherry Pickup II You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell. You have two robots that can collect cherries for you: Robot #1 is located at the top-left corner (0, 0), ...

Solved! Leetcode 1236: Web Crawler

Solved! Leetcode 1236: Web Crawler
source: https://leetcode.com/problems/web-crawler/description/ Given a url startUrl and an interface HtmlParser, implement a web crawler to crawl all links that are under the same hostname as startUrl. Return all urls obtained by your web crawler in any order. Your crawler should: Start from the page: startUrl Call HtmlParser.getUrls(url) to get all urls from a webpage of ...

Solved! Leetcode 2431. Maximize Total Tastiness of Purchased Fruits

source: https://leetcode.com/problems/maximize-total-tastiness-of-purchased-fruits/description/ Maximize Total Tastiness of Purchased Fruits You are given two non-negative integer arrays price and tastiness, both arrays have the same length n. You are also given two non-negative integers maxAmount and maxCoupons. For every integer i in range [0, n – 1]: price[i] describes the price of ith fruit. tastiness[i] describes the ...