Find K-th Smallest Pair Distance Problem

Problem The distance of a pair of integers a and b is defined as the absolute difference between a and b. Given an integer array nums and an integer k, return the kth smallest distance among all the pairs nums[i] and nums[j] where 0 <= i < j < nums.length. Examples Example 1: Input: nums = [1,3,1], k = 1 Output: 0 Explanation: Here are all the pairs: (1,3) -> 2 (1,1) -> 0 (3,1) -> 2 Then the 1st smallest distance pair is (1,1), and its distance is 0. ...

Magnetic Force Between Two Balls Problem

Problem In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum. Rick stated that magnetic force between two different balls at positions x and y is |x - y|. ...

Most Profit Assigning Work Problem

Problem You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where: difficulty[i] and profit[i] are the difficulty and the profit of the ith job, and worker[j] is the ability of jth worker (i.e., the jth worker can only complete a job with difficulty at most worker[j]). Every worker can be assigned at most one job, but one job can be completed multiple times. ...

Implement Power Function 1

Problem Implement pow(x, n), which calculates x raised to the power n (i.e., x^n). Examples Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3 Output: 9.26100 ...

Find first position of target element in sorted array

Problem Given a sorted array and an element, find the first occurrence of key in array. As array can contain duplicate values, there can be multiple occurrences of same element, problem is to find first index. Examples Example 1: Input: a = [1, 4, 4, 10, 10, 15, 20], target = 10 Output: 3 ...

Square root of an integer Problem

Problem Implement int sqrt(int x). OR Compute and return the square root of x. OR If x is not a perfect square, return floor(sqrt(x)) OR floor(√n) OR Given a non-negative integer x, compute and return the square root of x. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. ...

Koko Eating Bananas Problem

Problem 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 k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour. ...

Valid Perfect Square Problem

Problem Given a positive integer num, write a function which returns True if num is a perfect square else False. Follow up: Do not use any built-in library function such as sqrt. Examples Example 1: Input: num = 16 Output: true Example 2: Input: num = 14 Output: false ...

Intersection of Two Arrays 1 - Unique Elements

Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Examples Example 1: Input: nums1 = [1, 2, 2, 1], nums2 = [2, 2] Output: [2] ...

Binary Search Algo 13 - on a linked list

Problem Given the head of a sorted singly linked list and a target value, implement a function to find the target value using a binary search approach. If the target is found in the linked list, return the node; otherwise, return None. Examples Example 1: Input: head = [1, 3, 5, 7, 9, 11], target = 7 Output: Node with value 7 Explanation: The target 7 is found in the linked list. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy