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 1485. Clone Binary Tree With Random Pointer

source: https://leetcode.com/problems/clone-binary-tree-with-random-pointer/description/ Clone Binary Tree With Random Pointer A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a deep copy of the tree. The tree is represented in the same input/output way as normal binary trees where each ...

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 ...

Solved! Leetcode 23. Merge k Sorted Lists

Table of ContentsMerge k Sorted ListsJavaPythonTime ComplexitySpace Complexity source: https://leetcode.com/problems/merge-k-sorted-lists/ Merge k Sorted Lists You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Example 1:Input: lists = [[1,4,5],[1,3,4],[2,6]]Output: [1,1,2,3,4,4,5,6]Explanation: The linked-lists are:[1->4->5,1->3->4,2->6]merging them into one sorted list:1->1->2->3->4->4->5->6 ...

Solved! Leetcode 1162: As Far from Land as Possible

source: https://leetcode.com/problems/as-far-from-land-as-possible/description/ As Far from Land as Possible Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the ...

Solved! Leetcode: 1029. Two City Scheduling

source: https://leetcode.com/problems/two-city-scheduling/description/ Two City Scheduling A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti. Return the minimum cost to fly every person ...

Solved! Leetcode 646. Maximum Length of Pair Chain

source: https://leetcode.com/problems/maximum-length-of-pair-chain/description/ Maximum Length of Pair Chain You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti. A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion. Return the length ...

Solved! 875. Koko Eating Bananas

Table of ContentsProblem Description : Koko Eating BananasExamplesConstraintsPython Problem Description : Koko Eating Bananas source: https://leetcode.com/problems/koko-eating-bananas/  Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from ...