Solved! Leetcode 2405. Optimal Partition of String

source: https://leetcode.com/problems/optimal-partition-of-string/description/ Optimal Partition of String Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of substrings in such a partition. Note that each character should belong ...

Solved Leetcode 245. Shortest Word Distance III

source: https://leetcode.com/problems/shortest-word-distance-iii/description/ Shortest Word Distance III Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between the occurrence of these two words in the list. Note that word1 and word2 may be the same. It is guaranteed that they represent two individual ...

Solved! Leetcode 881. Boats to Save People

source: https://leetcode.com/problems/boats-to-save-people/description/ Boats to Save People You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of ...

Solved! Leetcode 120. Triangle

Table of ContentsProblem DescriptionTriangleJavaPython Problem Description source: https://leetcode.com/problems/triangle/description/ Triangle Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i ...

Solved! Leetcode 1466. Reorder Routes to Make All Paths Lead to the City Zero

source: https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/description/ Reorder Routes to Make All Paths Lead to the City Zero There are n cities numbered from 0 to n – 1 and n – 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to ...

Solved! Leetcode 2492. Minimum Score of a Path Between Two Cities

source: https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/ Minimum Score of a Path Between Two Cities You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal ...

Solved! Leetcode 2348. Number of Zero-Filled Subarrays

source: https://leetcode.com/problems/number-of-zero-filled-subarrays/description/ Number of Zero-Filled Subarrays Given an integer array nums, return the number of zero-filled subarrays. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = [1,3,0,0,2,0,0,4] Output: 6 Explanation: There are 4 occurrences of [0] as a subarray. There are 2 occurrences of [0,0] as a ...

Solved! Leetcode 208. Implement Trie (Prefix Tree)

source: https://leetcode.com/problems/implement-trie-prefix-tree/ Implement Trie (Prefix Tree) A trie (pronounced as “try”) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. Implement the Trie class: Trie() Initializes the trie object. void insert(String ...

Solved! Leetcode 129. Sum Root to Leaf Numbers

source: https://leetcode.com/problems/sum-root-to-leaf-numbers/description/ Sum Root to Leaf Numbers You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf numbers. Test ...

Solved! Leetcode 568. Maximum Vacation Days

source: https://leetcode.com/problems/maximum-vacation-days/ Maximum Vacation Days LeetCode wants to give one of its best employees the option to travel among n cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some particular cities and weeks. Your job is to schedule the traveling to maximize ...