LeetCode

[Solved] Minimum Recolors to Get K Consecutive Black Blocks LeetCode Contest

[Solved] Minimum Recolors to Get K Consecutive Black Blocks LeetCode Contest

You are given a 0-indexed string blocks of length n, where blocks[i] is either ‘W’ or ‘B’, representing the color of the ith block. The characters ‘W’ and ‘B’ denote the colors white and black, respectively. You are also given an integer k, which is the desired number of consecutive black blocks. In one operation, you can recolor a white block…

[Solved] Construct Smallest Number From DI String LeetCode Contest Problem

[Solved] Construct Smallest Number From DI String LeetCode Contest Problem

You are given a 0-indexed string pattern of length n consisting of the characters ‘I’ meaning increasing and ‘D’ meaning decreasing. A 0-indexed string num of length n + 1 is created using the following conditions: num consists of the digits ‘1’ to ‘9’, where each digit is used at most once. If pattern[i] == ‘I’, then num[i] < num[i + 1]. If pattern[i] == ‘D’, then num[i] >…

[Solved] Node With Highest Edge Score LeetCode Contest Problem

[Solved] Node With Highest Edge Score LeetCode Contest Problem

You are given a directed graph with n nodes labeled from 0 to n – 1, where each node has exactly one outgoing edge. The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i]. The edge score of a node i is defined as…

[Solved] Task Scheduler II LeetCode Contest

[Solved] Task Scheduler II LeetCode Contest

You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the ith task. You are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another task…

[Solved] Count Number of Bad Pairs LeetCode Contest

[Solved] Count Number of Bad Pairs LeetCode Contest

You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j – i != nums[j] – nums[i]. Return the total number of bad pairs in nums. Count Number of Bad Pairs LeetCode Contest Example 1: Input: nums = [4,1,3,3] Output: 5…

[Solved] Merge Similar Items LeetCode Contest

[Solved] Merge Similar Items LeetCode Contest

You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties: items[i] = [valuei, weighti] where valuei represents the value and weighti represents the weight of the ith item. The value of each item in items is unique. Return a 2D integer array ret where ret[i] = [valuei, weighti], with weighti being the sum of weights of…

[Solved] Number of Excellent Pairs LeetCode Contest Problem

[Solved] Number of Excellent Pairs LeetCode Contest Problem

You are given a 0-indexed positive integer array nums and a positive integer k. A pair of numbers (num1, num2) is called excellent if the following conditions are satisfied: Both the numbers num1 and num2 exist in the array nums. The sum of the number of set bits in num1 OR num2 and num1 AND num2 is greater than…