1375. Bulb Switcher III

1375. Bulb Switcher III Difficulty: Medium Related Topics: Array There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off. At moment k (for k from 0 to n – 1), we turn on the light[k] bulb. A bulbContinueContinue reading “1375. Bulb Switcher III”

1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K

1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K Difficulty: Medium Related Topics: Array, Greedy Given the number k, return the minimum number of Fibonacci numbers whose sum is equal to k, whether a Fibonacci number could be used multiple times. The Fibonacci numbers are defined as: F1 = 1F2 = 1FnContinueContinue reading “1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K”

1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold

1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold Difficulty: Medium Related Topics: Array Given an array of integers arr and two integers k and threshold. Return the number of sub-arrays of size k and average greater than or equal to threshold. Example 1: Input: arr = [2,2,2,2,5,5,5,8], kContinueContinue reading “1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold”

1582. Special Positions in a Binary Matrix

1582. Special Positions in a Binary Matrix Difficulty: Easy Related Topics: Array Given a rows x cols matrix mat, where mat[i][j] is either 0 or 1, return the number of special positions in mat. A position (i,j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed). Example 1: Input:ContinueContinue reading “1582. Special Positions in a Binary Matrix”

1572. Matrix Diagonal Sum

1572. Matrix Diagonal Sum Difficulty: Easy Related Topics: Array Given a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. Example 1: Input: mat = [[1,2,3],   [4,5,6],  ContinueContinue reading “1572. Matrix Diagonal Sum”

1588. Sum of All Odd Length Subarrays

1588. Sum of All Odd Length Subarrays Difficulty: Easy Related Topics: Array Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays. A subarray is a contiguous subsequence of the array. Return the sum of all odd-length subarrays of arr. Example 1: Input: arr = [1,4,2,5,3] Output: 58 Explanation: The odd-length subarrays of arrContinueContinue reading “1588. Sum of All Odd Length Subarrays”

1578. Minimum Deletion Cost to Avoid Repeating Letters

1578. Minimum Deletion Cost to Avoid Repeating Letters Difficulty: Medium Related Topics: Greedy Given a string s and an array of integers cost where cost[i] is the cost of deleting the character i in s. Return the minimum cost of deletions such that there are no two identical letters next to each other. Notice that you will delete the chosen charactersContinueContinue reading “1578. Minimum Deletion Cost to Avoid Repeating Letters”

1577. Number of Ways Where Square of Number Is Equal to Product of Two Numbers

1577. Number of Ways Where Square of Number Is Equal to Product of Two Numbers Difficulty: Medium Related Topics: Hash Table, Math Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules: Type 1: Triplet (i, j, k) if nums1[i]<sup>2</sup>&nbsp;== nums2[j] * nums2[k] whereContinueContinue reading “1577. Number of Ways Where Square of Number Is Equal to Product of Two Numbers”

1576. Replace All ?’s to Avoid Consecutive Repeating Characters

1576. Replace All ?’s to Avoid Consecutive Repeating Characters Difficulty: Easy Related Topics: String Given a string scontaining only lower case English letters and the ‘?’ character, convert all the ‘?’ characters into lower case letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non ‘?’ characters. It is guaranteed that thereContinueContinue reading “1576. Replace All ?’s to Avoid Consecutive Repeating Characters”

1418. Display Table of Food Orders in a Restaurant

1418. Display Table of Food Orders in a Restaurant Difficulty: Medium Related Topics: Hash Table Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerName<sub style=”display: inline;”>i</sub>,tableNumber<sub style=”display: inline;”>i</sub>,foodItem<sub style=”display: inline;”>i</sub>] where customerName<sub style=”display: inline;”>i</sub> is the name of the customer, tableNumber<sub style=”display: inline;”>i</sub> is the table customer sit at,ContinueContinue reading “1418. Display Table of Food Orders in a Restaurant”