Binary Search Maximum Side Length of a Square with Sum Less than or Equal to Threshold Maximum Side Length of a Square with Sum Less than or Equal to Threshold Problem Description: Given an m * n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such
Evaluate the Bracket Pairs of a String Solution In C++/Java/Python/Javascript Problem Description You are given a strings that contains some bracket pairs, with each pair containing a non-empty key. For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "age". You know the values
Group the People Given the Group Size They Belong To Solution In C++/Java/Python/Javascript Problem Description In this problem, we have n individuals, each identified by a unique ID ranging from 0 to n-1. Every person belongs to a specific group, but instead of being explicitly assigned to a group, they are only given a number indicating how many people should be in their
Aggressive Cows Leetcode Solution Aggressive Cows Problem Description: You are given an array with unique elements of stalls[], which denote the position of a stall. You are also given an integer k which denotes the number of aggressive cows. Your task is to assign stalls to k cows such that the minimum distance between
Maximum Candies Allocated to K Children Solution Maximum Candies Allocated to K Children Problem Description: You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub-piles, but you cannot merge two piles together. You are also
Most Profit Assigning Work Leetcode Solution Most Profit Assigning Work Problem Description: You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where: difficulty[i] and profit[i] are the difficulty and the profit of the ith job, and worker[j] is the ability of the jth worker (i.e.
Binary Search Maximum Value at a Given Index in a Bounded Array Solution in C++/Java/Python/JS Maximum Value at a Given Index in a Bounded Array Problem Description: You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions: nums.length == n nums[i] is a positive integer where 0 <= i < n.
Binary Search Search in Rotated Sorted Array Leetcode Solution | Code In C++/Python/Java/JS Problem Description: There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[
Binary Search Find Peak Index in a Mountain Array Solution | Code In C++/Java/Python/JS Problem Description: You are given an integer mountain array arr of length n where the values increase to a peak element and then decrease. Return the index of the peak element. Your task is to solve it in O(log(n)) time complexity. Examples: Input: arr = [0,1,0] Output:
Binary Search Find Minimum in Rotated Sorted Array Solution In C++/Java/Python/JS Problem Description: Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: * [4,5,6,7,0,1,2] if it was rotated 4 times. * [0,1,2,4,
Find Peak Element LeetCode Solution | Code in C++/Java/Python/JS Problem Description: A peak element is an element that is strictly greater than its neighbors. Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[
Binary Search Sqrt(x) LeetCode Solution | Approaches in C++/Java/Python/JS Problem Description: Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. For example, do not use pow(x, 0.5) in C++ or x
Move Pieces to Obtain a String Problem Description You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: The characters 'L' and 'R' represent pieces, where a piece 'L' can move
Next Permutation Problem Description A permutation of an array of integers is an arrangement of its members into a sequence or linear order. For example, for arr = [1,2,3], the following are all the permutations of arr: [1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,
Next Greater Element III Problem Description Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1. Note that the returned integer should fit in 32-bit integer, if there is
Sentence Similarity III Problem Description You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters. Two sentences s1
Rotate Array Problem Description Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,
Sort Array By Parity Problem Statement Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. Examples Input: nums = [3,1,2,4] Output: [2,4,3,1] Explanation: The outputs [4,2,3,1]
Convert an Array Into a 2D Array With Conditions Solution In C++/Java/Python/Javascript Problem Description Imagine you are given a list of numbers and need to transform it into a 2D array while following some rules. Each row in the 2D array must contain distinct numbers—no duplicates are allowed within a row. If a number appears multiple times in the input list,
Finding the Users Active Minutes Solution In C++/Java/Python/Javascript Problem Description You are given an 2D integer matrix logs , where each entry consists of a pair [ID,time]. The ID represents a user who performed an action at a given time (in minutes). A single user can perform multiple actions at the same minute. Multiple users can perform actions
Binary Search Binary Search Algorithm Solution: Iterative & Recursive Ways Problem Description: Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. Examples: Input: nums
Two Pointer Two Sum Solution In C++/Java/Python/JS Problem Description Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input will have exactly one solution, and you may not use the same element twice. You can return the answer
Dinner Plate Stacks Problem Statement You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity. Implement the DinnerPlates class: DinnerPlates(int capacity) Initializes the object with the maximum capacity of the stacks capacity. void push(int
Score of Parentheses Problem Description Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: "()" has score 1. AB has score A + B, where A and B are balanced parentheses strings. (A) has score 2 * A,
Maximum Frequency Stack Problem Description Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. Implement the FreqStack class: FreqStack() constructs an empty frequency stack. void push(int val) pushes an integer val onto the top of the stack. int pop() removes and