1305. All Elements in Two Binary Search Trees

Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Example 1: Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4] Example 2: Input: root1 = [0,-10,10], root2 = [5,1,7,0,2] Output: [-10,0,0,1,2,5,7,10] Example 3: Input: root1 = [], root2 = [5,1,7,0,2] Output: [0,1,2,5,7] Example 4: Input: root1 = [0,-10,10], root2 = [] Output: [-10,0,10] 1 2 3 4 Example 5: Input: root1 = [1,null,8], root2 = [8,1] Output: [1,1,8,8] Constraints:...

<span title='2021-10-28 00:00:00 +0000 UTC'>October 28, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

173. Binary Search Tree Iterator

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 smaller than any element in the BST. boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false....

<span title='2021-10-28 00:00:00 +0000 UTC'>October 28, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

413. Arithmetic Slices

An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences. Given an integer array nums, return the number of arithmetic subarrays of nums. A subarray is a contiguous subsequence of the array. 1 2 3 4 5 6 7 8 9 10 Example 1: Input: nums = [1,2,3,4] Output: 3 Explanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself....

<span title='2021-10-26 00:00:00 +0000 UTC'>October 26, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

489. Robot Room Cleaner

You are controlling a robot that is located somewhere in a room. The room is modeled as an m x n binary grid where 0 represents a wall and 1 represents an empty slot. The robot starts at an unknown location in the root that is guaranteed to be empty, and you do not have access to the grid, but you can move the robot using the given API Robot....

<span title='2021-10-26 00:00:00 +0000 UTC'>October 26, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

981. Time Based Key-Value Store

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key’s value at a certain timestamp. Implement the TimeMap class: TimeMap() Initializes the object of the data structure. void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp. String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp....

<span title='2021-10-21 00:00:00 +0000 UTC'>October 21, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

121. Best Time to Buy and Sell Stock

You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. 1 2 3 4 5 6 Example 1: Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5....

<span title='2021-10-20 00:00:00 +0000 UTC'>October 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

23. 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. 1 2 3 4 5 6 7 8 9 10 11 12 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 1 2 3 4 Example 2: Input: lists = [] Output: [] 1 2 3 4 Example 3: Input: lists = [[]] Output: [] Constraints:...

<span title='2021-10-19 00:00:00 +0000 UTC'>October 19, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

951. Flip Equivalent Binary Trees

For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees. A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations. Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivelent or false otherwise....

<span title='2021-10-19 00:00:00 +0000 UTC'>October 19, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1123. Lowest Common Ancestor of Deepest Leaves

Given the root of a binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if it has no children The depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1. The lowest common ancestor of a set S of nodes, is the node A with the largest depth such that every node in S is in the subtree with root A....

<span title='2021-10-17 00:00:00 +0000 UTC'>October 17, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1503. Last Moment Before All Ants Fall Out of a Plank

We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with speed 1 unit per second. Some of the ants move to the left, the other move to the right. When two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions doesn’t take any additional time. When an ant reaches one end of the plank at a time t, it falls out of the plank imediately....

<span title='2021-10-17 00:00:00 +0000 UTC'>October 17, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target

Given an array nums and an integer target. Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Example 1: Input: nums = [1,1,1,1,1], target = 2 Output: 2 Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2)....

<span title='2021-10-16 00:00:00 +0000 UTC'>October 16, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

737. Sentence Similarity II

We can represent a sentence as an array of words, for example, the sentence “I am happy with leetcode” can be represented as arr = [“I”,“am”,happy",“with”,“leetcode”]. Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar. Return true if sentence1 and sentence2 are similar, or false if they are not similar....

<span title='2021-10-15 00:00:00 +0000 UTC'>October 15, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1027. Longest Arithmetic Subsequence

Given an array nums of integers, return the length of the longest arithmetic subsequence in nums. Recall that a subsequence of an array nums is a list nums[i1], nums[i2], …, nums[ik] with 0 <= i1 < i2 < … < ik <= nums.length - 1, and that a sequence seq is arithmetic if seq[i+1] - seq[i] are all the same value (for 0 <= i < seq.length - 1)....

<span title='2021-10-12 00:00:00 +0000 UTC'>October 12, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

261. Graph Valid Tree

Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h. 1 2 3 4 5 Example 1: Input: root = [1,2,3,4,5,6] Output: true Explanation: Every level before the last is full (ie....

<span title='2021-10-12 00:00:00 +0000 UTC'>October 12, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

124. Binary Tree Maximum Path Sum

A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node’s values in the path. Given the root of a binary tree, return the maximum path sum of any path....

<span title='2021-10-09 00:00:00 +0000 UTC'>October 9, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx