Minimum Level Sum of a Binary Tree Problem

Problem Given a binary tree, return the level of the tree with minimum sum. OR Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is minimal. Opposite of this problem - Minimum Level Sum of a Binary Tree Problem. ...

Append Characters to String to Make Subsequence Problem

Problem You are given two strings s and t consisting of only lowercase English letters. Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s. A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. Examples Example 1: ...

Search in Rotated Sorted Array - Duplicates Allowed

Problem Given an array, sorted in non-decreasing order (not necessarily with distinct values) is rotated at some pivot unknown to you beforehand. (i.e., [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]). You are given a target value to search. If found in the array return its index, otherwise return -1. Examples Example 1: Input: nums = [8, 11, 13, 15, 1, 4, 6], target = 1 Output: 4 ...

Count Triplets That Can Form Two Arrays of Equal XOR

Problem Given an array of integers arr. We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). Let’s define a and b as follows: a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1] b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k] Note that ^ denotes the bitwise-xor operation. ...

Number of Steps to Reduce a Number in Binary Representation to One

Problem Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules: If the current number is even, you have to divide it by 2. If the current number is odd, you have to add 1 to it. It is guaranteed that you can always reach one for all test cases. Examples Example 1: ...

Maximum Sum Subarray of Size K

Problem Given an array of positive integers, and a positive number k, find the maximum sum of any contiguous subarray of size k. Examples Example 1 Input: nums = [3, 5, 2, 1, 7], k = 2 Output: 8 Explanation: Subarray with maximum sum is [1, 7]. ...

Get Equal Substrings Within Budget

Problem You are given two strings s and t of the same length and an integer maxCost. You want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters). Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or equal to maxCost. If there is no substring from s that can be changed to its corresponding substring from t, return 0. ...

The Number of Beautiful Subsets Problem

Problem You are given an array nums of positive integers and a positive integer k. A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k. Return the number of non-empty beautiful subsets of the array nums. A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different. ...

Distribute Coins in Binary Tree Problem

Problem You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree. In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent. Return the minimum number of moves required to make every node have exactly one coin. ...

Delete Leaves With a Given Value Problem

Problem Given a binary tree root and an integer target, delete all the leaf nodes with value target. Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you cannot). Examples Example 1: ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy