Implement Power Function (pow(x,n)) Solution in C++/Java/Python/JS Description Implement pow(x,n), which calculates x raised to the power n (i.e., xn). Examples Input: x = 2.00000, n = 10 Output: 1024.00000 Input: x = 2.10000, n = 3 Output: 9.26100 Input: x = 2.00000, n = -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4
How to Find nPr and nCr Solution In C++/Java/Python/JS Introduction In the journey of learning Data Structures and Algorithms (DSA), we often come across problems that require counting arrangements, selections, or groupings. Whether it's calculating possibilities in recursion, brute force combinations, or logic puzzles, one concept keeps popping up — Permutation and Combination. Understanding this topic early will
How to Find Ceil and Floor Solution In C++/Java/Python/JS How to find Ceil and Floor Problem Description Given a real number x, find: Ceil of x: The smallest integer that is greater than or equal to x. Floor of x: The largest integer that is less than or equal to x. You must return both values as output. Examples:
Minimize Maximum of Array Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed array nums comprising of n non-negative integers. In one operation, you must: Choose an integer i such that 1 <= i < n and nums[i] > 0. Decrease nums[i] by 1. Increase nums[i - 1] by 1. Return the minimum
Maximum Bags With Full Capacity of Rocks Solution In C++/Java/Python/JS Problem Description You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of
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,
Maximum Number of Robots Within Budget Solution In C++/Java/Python/JS Maximum Number of Robots Within Budget Problem Description: You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The i-th robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget. The
Maximum Running Time of N Computers Solution In C++/Java/Python/JS Maximum Running Time of N Computers Problem Description: You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries. Initially,
Split Array Largest Sum Solution In C++/Java/Python/JS Split array largest sum Problem Description: Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. A subarray is a contiguous part of the array. Examples: Input:
Minimum Number of Days to Make m Bouquets Solution In C++/Java/Python/JS Problem Description: You are given an integer array bloomDay, an integer m and an integer k. You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the i-th flower will bloom in the bloomDay[
Find the Smallest Divisor Given a Threshold Solution In C++/Java/Python/JS Problem Description: Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. Each
Koko Eating Bananas Solution In C++/Java/Python/JS Problem Description: Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours. Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats
Capacity To Ship Packages Within D Days Solution In C++/Java/Python/JS Problem Description: A conveyor belt has packages that must be shipped from one port to another within D days. The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights)
Find in Mountain Array Solution In C++/Java/Python/JS Problem Description: (This problem is an interactive problem.) You may recall that an array arr is a mountain array if and only if: * arr.length >= 3 * There exists some i with 0 < i < arr.length - 1 such that: * arr[0] < arr[1] < ... < arr[
Find Minimum in Rotated Sorted Array II 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,4,4,5,6,7] might become: * [4,5,6,7,0,1,4] if it was rotated 4 times. * [0,1,4,4,
Find the Duplicate Number Solution In C++/Java/Python/JS Find the Duplicate Number Problem Description: Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and using
Minimum Common Value Solution In C++/Java/Python/JS Minimum Common Value Problem Description: Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer among nums1 and nums2, return -1. An integer is said to be common to nums1 and nums2 if both arrays
Single Element in a Sorted Array Solution In C++/Java/Python/JS Problem Description: You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single element that appears only once. Your solution must run in O(log n) time and O(1) space. Examples: Input: nums
Kth Missing Positive Number Solution In C++/Java/Python/JS Problem Description: Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the k-th positive integer that is missing from this array. Examples: Input: arr = [2, 3, 4, 7, 11], k = 5 Output: 9 Explanation: The missing positive integers are [1, 5,
Most Beautiful Item for Each Query Solution In C++/Java/Python/JS Problem Description: You are given a 2D integer array items where items[i] = [priceᵢ, beautyᵢ] denotes the price and beauty of an item respectively. You are also given a 0-indexed integer array queries. For each queries[j], you want to determine the maximum beauty of an item whose price is