Hashing Redistribute Characters to Make All Strings Equal Solution In C++/Java/Python/JS Problem Description You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return true if you can make every string in
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
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
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
Minimum Operations to Make Array Equal II Solution In C++/Java/Python/JS Problem Description You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1: Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i]
Minimum Score by Changing Two Elements Solution In C++/Java/Python/JS Problem Description You are given an integer array nums. The low score of nums is the minimum absolute difference between any two integers. The high score of nums is the maximum absolute difference between any two integers. The score of nums is the sum of the high and low scores.
Advantage Shuffle Solution In C++/Java/Python/JS Problem Description You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i]. Return any permutation of nums1 that maximizes its advantage with respect to nums2.
Wiggle Subsequence Solution In C++/Java/Python/JS Problem Description A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequences. For example,
Jump Game II Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any
Jump Game Solution In C++/Java/Python/JS Problem Description You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. Example Input: nums = [2,
Dynamic Memory Allocation in C++ 1. Why Dynamic Memory is Like Apartment Hunting Have you ever tried to pack for a trip before knowing exactly where you're going, how long you’ll stay, or what the weather will be like? It’s tricky, right? You end up guessing. Maybe you overpack. Maybe you
Namespaces in C++ Namespaces in C++: Naming Without the Headaches Why Namespaces Even Exist Let’s start with a situation you’ve probably experienced — whether in real life or in code. Imagine You’re in a Busy Coffee Shop… You’re meeting up with a few friends at a local café. It’s
Nested if and switch Statement and ?: Operator in C++ 1.Layered Thinking – Why Decisions Sometimes Need Sub-Decisions Have you ever asked someone a question, and based on their answer, you had to ask something else? Like this: “Hey, do you want to go out for dinner?” — “Yeah!” → “Great, do you want pizza or pasta?” See what just happened? One
Decision Making Statements and Its Types in C++ The Decision-Making Moment – Why Code Needs to Think Let’s start with a simple question. Have you ever had to choose between pizza or pasta? Or maybe between watching a movie or finishing your homework? Chances are… yes. That little pause where your brain asks, “What’s the situation?”, and
Bitwise Operators and Operators Precedence in C++ 1. Why Should I Even Care About Bits? Let’s ask something very simple. When you write something like a + b in your C++ program... what’s really happening inside the machine? Do you imagine tiny elves with calculators? Maybe sparks flying between transistors? Well, not quite — but let’s
Operators in C++ The Operators Toolbox: Why All the Symbols? When you first dive into C++, all those weird little symbols—+, -, =, *, &&—can feel overwhelming. What are they really doing? And why does C++ need so many of them? Let me flip the question: If you were building a machine, would
Modifiers in C++ 1.“You Can Look, But Not Touch”: A Friendly Dive into C++ Type Qualifiers Have you ever opened a document and seen that dreaded “View Only” message? You can scroll, read, admire the formatting—but no matter how hard you type, nothing changes. Why does that happen? To protect something
Constants and Literals in C++ Why Bother About Something So "Small"? "Wait… literals? Constants? That sounds… tiny. Are they really worth our attention?" Absolutely. If a program is like a recipe, then literals are the actual ingredients: 2 cups of sugar, 3 eggs, a pinch of salt. Without them, you’re
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
Math Basics Check if a number is prime without using the Sieve of Eratosthenes Solution In C++/Java/Python/JS What exactly is a prime number? A prime number is a number that is greater than 1 and has only two factors: 1 and itself. In other words, a prime number is not divisible by any other numbers except 1 and itself. For example: * 7 is a prime number because
Matrix Diagonal Traverse Solution In C++/Python/java/JS Problem Description Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order. Example Input: mat = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,4,7,5,3,6,8,9] Explanation: We pick elements diagonally.
Minimum Operations to Make a Uni-Value Grid Solution In C++/Python/java/JS Problem Description You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid. A uni-value grid is a grid where all the elements of it are equal. Return
Image Overlap Solution In C++/Python/java/JS Problem Description You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values. We translate one image however we choose by sliding all the 1 bits left, right, up, and/or down any
Where Will the Ball Fall Solution In C++/Python/java/JS Problem Description You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides. Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball