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 352: Data Stream as Disjoint Intervals

source: https://leetcode.com/problems/data-stream-as-disjoint-intervals/description/ Data Stream as Disjoint Intervals Given a data stream input of non-negative integers a1, a2, …, an, summarize the numbers seen so far as a list of disjoint intervals. Implement the SummaryRanges class: SummaryRanges() Initializes the object with an empty stream. void addNum(int value) Adds the integer value to the stream. int[][] getIntervals() ...

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 567: Permutation in String

source: https://leetcode.com/problems/permutation-in-string/ Permutation in String Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1’s permutations is the substring of s2. Example 1: Input: s1 = “ab”, s2 = “eidbaooo” Output: true Explanation: s2 contains one permutation of ...

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