Count Negative Numbers in a Sorted Matrix Solution In C++/Java/Python/JS Problem Description Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid. Examples Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]] Output: 8 Explanation: There
Search a 2D Matrix Solution In C++/Java/Python/JS Problem Description You are given an m x n integer matrix matrix with the following two properties: Each row is sorted in non-decreasing order. The first integer of each row is greater than the last integer of the previous row. Given an integer target, return true if target is in
Search a 2D Matrix II Solution In C++/Java/Python/JS Problem Description Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom.
Count Submatrices with Top-Left Element and Sum Less Than k Solution In C++/Python/java/JS Problem Description: You are given a 0-indexed integer matrix grid and an integer k. Return the number of submatrices that contain the top-left element of the grid, and have a sum less than or equal to k. Examples: Input: grid = [[7,6,3],[6,6,1]], k = 18 Output: 4
Add Binary Solution In C++/Java/Python/JS Problem Description Given two binary strings a and b, return their sum as a binary string. Example Input: a = "11", b = "1" Output: "100" Input: a = "1010", b = "1011" Output: "10101" Constraints * 1 <= a.length, b.length
Number of 1 Bits Solution In C++/Java/Python/JS Problem Description Given a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight). What are Set Bits in Binary Representation? In binary, a set bit is simply a bit whose value is 1. For example, if
Number Complement Solution In C++/Java/Python/JS Problem Description The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. For example, The integer 5 is "101" in binary and
Set the Rightmost Unset Bit Solution In C++/Java/Python/JS Problem Description Given a non-negative number n. The problem is to set the rightmost unset bit in the binary representation of n. What is Set/Unset Bit? What is a Bit? In binary, every number is made of bits — and each bit can either be 0 or 1. These are
Check Odd or Even Solution In C++/Java/Python/JS Problem Description Given a positive integer n, determine whether it is odd or even. Return true if the number is even and false if the number is odd. Example Input: n = 15 Output: false Explanation: The number is not divisible by 2, Odd number. Input: n = 44 Output: true Explanation:
Kth Bit is Set or Not Solution In C++/Java/Python/JS Problem Description Given two positive integer n and k, check if the kth index bit of n is set or not. What is a Kth Bit and Set Bit? What is the k-th bit? Every number in binary is made up of bits (0s and 1s). These bits are like
Get, Set, Clear ith Bit Solution In C++/Java/Python/JS Problem Description Given a 32 bit unsigned integer num and an integer i. Perform following operations on the number - 1. Get i-th bit 2. Set i-th bit 3. Clear i-th bit Note : For better understanding, we are starting bits from 1 instead 0. (1-based). You have to print space
Decimal to Binary Solution In C++/Java/Python/JS Problem Description Given a decimal number n, return its binary equivalent. What is Binary Representation of a Number? Binary representation of a number is a way of expressing it using only two digits: 0 and 1. Each digit represents a power of 2, starting from the right (least significant bit)
Stack Daily Temperatures Solution In C++/Java/Python/JS Problem Description Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep
Stack Number of Atoms Solution In C++/Java/Python/JS Problem Given a string formula representing a chemical formula, return the count of each atom. The atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name. One or more digits representing that element's count may follow if the count is greater
Shortest String That Contains Three Strings Solution In C++/Java/Python/JS Problem Description Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings. If there are multiple such strings, return the lexicographically smallest one. Return a string denoting the answer to the problem. Notes: -
Bag of Tokens Solution In C++/Java/Python/JS Problem Description You start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each tokens[i] denotes the value of tokeni. Your goal is to maximize the total score by strategically playing these tokens. In one
Boats to Save People Solution In C++/Java/Python/JS Problem Description You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the
Maximum Erasure Value Solution In C++/Java/Python/JS Problem Description You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements. Return the maximum score you can get by erasing exactly one subarray. An array
Longest Subarray of 1's After Deleting One Element Solution In C++/Java/Python/JS Problem Description Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray. Example Example 1: Input: nums = [1,1,0,1] Output: 3
Sliding Window Subarrays with K Different Integers Solution In C++/Java/Python/JS Problem Description Given an integer array nums and an integer k, return the number of good subarrays of nums. A good array is an array where the number of different integers in that array is exactly k. For example, [1,2,3,1,2] has 3 different integers: 1, 2,
Frequency of the Most Frequent Element Solution In C++/Java/Python/JS Problem Description: The frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1. Return the maximum
Sliding Window Maximum Average Subarray I Solution In C++/Java/Python/JS Problem Description You are given an integer array nums consisting of n elements, and an integer k. Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10^-5 will be accepted.
Sliding Window Maximum Number of Vowels in a Substring of Given Length Solution In C++/Java/Python/JS Problem Description Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'. What is a Substring?
Sliding Window Check If a String Contains All Binary Codes of Size K Solution In C++/Java/Python/JS Problem Description Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false. What is a Substring? A substring is a continuous sequence of characters taken from a string, without changing their order. For example,
Sliding Window Permutation in String Solution In C++/Java/Python/JS Problem Description Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permutations is the substring of s2. What is a Permutation? A permutation of a string is a rearrangement of