Most Popular Video Creator Problem Solution In C++/Java/Python/Javascript Problem Description You are given two string arrays creators and ids, and an integer array views, all of length n. The i th video on a platform was created by creators[i], has an id of ids[i], and has views[i] views. The popularity of a creator is the
Single Threaded CPU Problem Solution In C++/Java/Python/Javascript Problem Description You are given n tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTime i, processingTime i]means that the i t task will be available to process at enqueueTime i and will take processingTime i to finish processing.
Maximum Average Pass Ratio Solution In C++/Java/Python/Javascript Problem Description There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the ith class, there are totali total students, but only passi number
Reorganize String Solution In C++/Java/Python/Javascript Problem Description Given a string s, rearrange the characters of s so that any two adjacent characters are not the same. Return any possible rearrangement of s or return "" if not possible. Examples Input: s = "aab" Output: "aba" Explanation: In the rearranged string "
Longest Happy String Solution In C++/Java/Python/Javascript Problem Description A string s is called happy if it satisfies the following conditions: 1. 's' only contains the letters 'a', 'b', and 'c'. 2. 's' does not contain any of "aaa", "bbb", or "ccc&
Reduce Array Size to The Half Solution In C++/Java/Python/Javascript Problem Description You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half of the integers of the array are removed. Example Input: arr
Two Pointer Make String a Subsequence Using Cyclic Increments Solution In C++/Java/Python/JS Make String a Subsequence Using Cyclic Increments Problem Description: You are given two 0-indexed strings str1 and str2. In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a'
Largest Merge Of Two Strings Solution In C++/Java/Python/JS Problem Description You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options: If word1 is non-empty, append the first character in word1 to merge and delete it from
Reverse Words in a String III Solution In C++/Java/Python/JS Problem Description: Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Examples: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" Input: s = "Mr Ding&
Reverse Words in a String Solution In C++/Java/Python/JS Problem Description: Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order, concatenated by a single space. Note
4Sum Solution In C++/Java/Python/JS Problem Description Given an array nums of nn integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 ≤ a,b,c,d < n a,b,c and d are distinct indices nums[a] + nums[b] + nums[c] + nums[d]
Find All K-Distant Indices in an Array Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed integer array nums and two integers key and k. An index i in the array is said to be k-distant if there exists at least one index j such that: * |i - j| <= k, and * nums[j] == key In simple terms, a
Two Pointer Apply Operations to an Array Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed array nums of size n that contains non-negative integers. The goal is to apply a sequence of operations to this array and return the final result after all transformations are complete. For each index i from 0 to n - 2, you need
Remove Element Solution In C++/Java/Python/JS Problem Description Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. Consider the number of elements in nums which are
Rearrange Array Elements by Sign Problem Description You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers. You should return the array of nums such that the array follows the given conditions: 1. Every consecutive pair of integers has opposite signs. 2. For all
Perfect Rectangle Solution In C++/Java/Python/JS Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi). Return true if all the rectangles together form an exact cover of a rectangular region. Example Input:
Rectangle Area II Solution In C++/Java/Python/JS Problem Description You are given a 2D array of axis-aligned rectangles. Each rectangle[i] = [xi1, yi1, xi2, yi2] denotes the ith rectangle where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinates of the top-right corner. Calculate the total area covered by all rectangles
Prefix Sum Number of Flowers in Full Bloom Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed 2D integer array flowers, where flowers[i] = [start i, end i] means the ith flower will be in full bloom from start i to end i (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is
Prefix Sum Minimum Cost to Make Array Equal Solution In C++/Java/Python/JS Problem Description You are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: * Increase or decrease any element of the array nums by 1. The cost of doing one operation on the ith element is cost[
Count Vowel Strings in Ranges Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed array of strings words and a 2D array of integers queries. Each query queries[i] = [li, ri] asks us to find the number of strings present at the indices ranging from li to ri (both inclusive) of words that start and end with
Number System What is a number? A number is a mathematical object used to count, measure, and label. Numbers are also used to represent quantities and make calculations. For example, we use numbers in everyday life to count money, time, and things. Numbers themselves are categorized into various types, such as Natural
Logarithm basics for DSA Solution In C++/Java/Python/JS What is a Logarithm? Description A logarithm is the inverse operation of exponentiation. It determines the power to which a given base must be raised to obtain a specified number. Mathematically, if: b^x = y Then, using logarithms: logb y = x This is read as "logarithm of y to
Find the AP/GP/HP Solution In C++/Java/Python/JS When preparing for DSA interviews, we often come across number sequences. Three common types are: * Arithmetic Progression (AP) – where the difference between consecutive terms is constant. * Geometric Progression (GP) – where the ratio between consecutive terms is constant. * Harmonic Progression (HP) – where the reciprocals of the terms form an AP. Understanding
Find the Mean/Median/Mode of the Given Array Solution In C++/Java/Python/JS Description Statistical measures help us understand data distribution and central tendency. When analyzing data, we often need to find representative values that summarize the entire dataset. The three most common statistical measures are: 1. Mean: The arithmetic average of all values in the array. 2. Median: The middle value when
Check if an Integer is a Power of 2/3/4/5... Solution In C++/Java/Python/JS Problem Description: Given an integer n, check if it is a power of 2, 3, 4, 5.... Return True if it is, otherwise return False. Examples: Input: n = 16 Output: True Explanation: 16 is a power of 2 and 4. Input: n = 27 Output: True Explanation: 27 is a power