python

[Solved] Maximum Segment Sum After Removals LeetCode Contest

[Solved] Maximum Segment Sum After Removals LeetCode Contest

You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the ith query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments. A segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a segment. Return an integer array answer, of length n,…

[Solved] Shifting Letters II LeetCode Contest

[Solved] Shifting Letters II LeetCode Contest

You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0. Shifting a character forward means replacing it…

[Solved] Time Needed to Rearrange a Binary String LeetCode Contest

[Solved] Time Needed to Rearrange a Binary String LeetCode Contest

You are given a binary string s. In one second, all occurrences of “01” are simultaneously replaced with “10”. This process repeats until no occurrences of “01” exist. Return the number of seconds needed to complete this process. Time Needed to Rearrange a Binary String LeetCode Contest Example 1: Input: s = “0110101”…

[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] 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…

[Solved] First Letter to Appear Twice LeetCode Contest Problem

[Solved] First Letter to Appear Twice LeetCode Contest Problem

Given a string s consisting of lowercase English letters, return the first letter to appear twice. Note: A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b. s will contain at least one letter that appears twice. First Letter to Appear Twice LeetCode Contest…