Online Election Solution In C++/Java/Python/JS Problem Description: You are given two integer arrays persons and times. In an election, the ith vote was cast for persons[i] at time times[i]. For each query at a time t, find the person that was leading the election at time t. Votes cast at time t will
Find Target Indices After Sorting Array Solution In C++/Java/Python/JS Problem Description: You are given a 0-indexed integer array nums and a target element target. A target index is an index i such that nums[i] == target. Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an
Search Insert Position Solution In C++/Java/Python/JS Problem Description: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Examples: Input: nums
Find the Distance Value Between Two Arrays Solution In C++/Java/Python/JS Problem Description: Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays. The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where | arr1[i]-arr2[j] | <= d. Examples:
First Bad Version Solution in C++/Java/Python/JS Problem Description: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you
Find Smallest Letter Greater Than Target Solution in C++/Java/Python/JS Problem Description: You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters. Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the
Simplify Path Solution In C++/Python/Java/JS Simplify Path Problem Statement You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this absolute path into its simplified canonical path. The rules of a Unix-style file system are as follows: 1. A single period
Grumpy Bookstore Owner Solution In C++/Java/Python/JS Problem Description: There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the ,of the customers that enter the store at the start of the ith minute and all those customers leave after
Fruit Into Baskets Solution In C++/Java/Python/JS Problem Description: You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the ith tree produces. You want to collect as much fruit as possible.
Maximum Points You Can Obtain from Cards Solution In C++/Java/Python/JS Problem Description There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to take
Sliding Subarray Beauty Solution In C++/Java/Python/JS Problem Description Given an integer array nums containing n integers, find the beauty of each subarray of size k. The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers. Return an integer array
Find All Anagrams in a String Solution In C++/Java/Python/JS Problem Description Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. What is an Anagram? An Anagram is when two words contain the exact same characters with the same frequency,
Minimum Seconds to Equalize a Circular Array Solution In C++/Java/Python/JS Problem Description There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse. A point of the cheese with index i (0-indexed) is: reward1[i] if the first mouse eats it. reward2[i] if the second mouse eats it. You
Hashing Maximum Size of a Set After Removals Solution In C++/Java/Python/JS Problem Description You are given two 0-indexed integer arrays nums1 and nums2 of even length n. You must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s. Return the maximum possible
Card Flipping Game Solution In C++/Java/Python/JS Problem Description You are given two 0-indexed integer arrays fronts and backs of length n, where the ith card has the positive integer fronts[i] printed on the front and backs[i] printed on the back. Initially, each card is placed on a table such that the front number is
Vowel Spellchecker Solution In C++/Java/Python/JS Problem Description Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word. For a given query word, the spell checker handles two categories of spelling mistakes: Capitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is
Alphabet Board Path Solution In C++/Java/Python/JS Problem Description On an alphabet board, we start at position (0, 0), corresponding to character board[0][0]. Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"]. We may make the following moves: 'U' moves our position
Pairs of Songs With Total Durations Divisible by 60 Solution In C++/Java/Python/JS Problem Description You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i
Brick Wall Solution In C++/Java/Python/JS Problem Description There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.
Sort Characters By Frequency Solution In C++/Java/Python/Javascript Problem Description Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string. Return the sorted string. If there are multiple answers, return any of them. Example Input: s = "
Minimum Number of Operations to Make Word K-Periodic Solution In C++/Java/Python/Javascript Problem Description You are given a string word of size n and an integer k such that k divides n. In one operation, you can pick any two indices i and j that are divisible by k, then replace the substring of length k starting at i with the substring
Can Convert String in K Moves Solution In C++/Java/Python/Javascript Problem Description Given two strings s and t, your goal is to convert s into t in k moves or less. During the ith (1 <= i <= k) move you can: 1) Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j
Restore the Array From Adjacent Pairs Solution In C++/Java/Python/Javascript Problem Description There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums. You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates
Tuple with Same Product Solution In C++/Java/Python/Javascript Problem Description Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d. Problem Explanation what is tuple? A group of immutable elements
Split the Array to Make Coprime Products Solution In C++/Java/Python/Javascript Problem Description You are given a 0-indexed integer array nums of length n. A split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime. For example,