H-Index II Solution In C++/Java/Python/JS Problem Description: Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in ascending order, return the researcher's h-index. According to the definition of h-index on Wikipedia: The h-index is defined as the
Guess Number Higher or Lower Solution In C++/Java/Python/JS Problem Description: We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.
Find a Peak Element II Solution In C++/Java/Python/JS Problem Description: A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom. Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i]
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[
Watering Plants II Problem Description Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. Each plant needs a specific amount of water.
Separate Black and White Balls Problem Description There are n balls on a table, each ball has a color black or white. You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively. In each step, you can choose two adjacent balls and swap them.
String Compression Problem Description Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: * If the group's length is 1, append the character to s. * Otherwise, append the character followed by the group&
Container with Most Water Problem Description You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains
Minimum Length of String After Deleting Similar Ends Problem Description Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times: 1. Pick a non-empty prefix from the string s where all the characters in the
Count the Occurrences of Digit '1' in All Numbers from 1 to n Solution In C++/Java/Python/JS Problem Description: Given an integer n, count the occurrences of the digit '1' in all numbers from 1 to n. Examples: Input: n = 13 Output: 6 Explanation: The numbers containing '1' are 1, 10, 11, 12, 13. The total count is 6. Example 2: Input: n
Find the Grid of Region Average Solution In C++/Python/java/JS Problem Description: You are given m x n grid image which represents a grayscale image, where image[i][j] represents a pixel with intensity in the range [0..255]. You are also given a non-negative integer threshold. Two pixels are adjacent if they share an edge. A region is a
Check if Move is Legal Solution In C++/Python/java/JS Problem Description: You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board. On the board, free cells are represented by '.', white cells are represented by 'W', and black cells are represented by '
Valid Sudoku Solution In C++/Python/java/JS Problem Description: Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 1. Each row must contain the digits 1-9 without repetition. 2. Each column must contain the digits 1-9 without repetition. 3. Each of the nine
Game of Life Solution In C++/Python/java/JS Problem Description: According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." The board is made up of an m x n grid of cells, where each cell has