Maximize Happiness of Selected Children

Problem You are given an array happiness of length n, and a positive integer k. There are n children standing in a queue, where the ith child has happiness value happiness[i]. You want to select k children from these n children in k turns. In each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive. ...

Relative Ranks Problem

Problem You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique. The athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on. The placement of each athlete determines their rank: ...

Sort Characters By Frequency Problem

Problem 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. Examples Example 1: Input: s = "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer. ...

Minimum Increment to Make Array Unique Problem

Problem You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1. Return the minimum number of moves to make every value in nums unique. The test cases are generated so that the answer fits in a 32-bit integer. Examples Example 1: Input: nums = [1,2,2] Output: 1 Explanation: After 1 move, the array could be [1, 2, 3]. ...

Minimum Time Difference Problem

Problem Given a list of 24-hour clock time points in “HH:MM” format, return the minimum minutes difference between any two time-points in the list. Examples Example 1: Input: timePoints = ["23:59","00:00"] Output: 1 Example 2: Input: timePoints = ["00:00","23:59","00:00"] Output: 0 ...

Arrange Given Number To Form The Biggest Number Possible

Problem Arrange Given Numbers To Form The Biggest Number Possible. OR Write a function that takes a number as input and outputs the biggest number with the same set of digits. Examples Example 1: Input: num = 423865 Output: 865432 Similar Problems Next Greater Element 3 - Find smallest number larger than given number using same digits ...

Intersection of Two Arrays 2 - Duplicates allowed

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

Merge Sort Algorithm

Problem Array Sorting Problem Similar Sorts 3-way Merge Sort Solution Mergesort is one of the older algorithms known since 1945. It is very good example of divide and conquer paradigm and is better than other simpler sort algorithms like selection, insertion or bubble sort. Method 1 - Recursive Top Down Merge Sort Merge sort is a recursive algorithm that repeatedly calls itself on progressively smaller subsets of the problem. ...

Dutch National Flag DNF problem

Problem Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. You must solve this problem without using the library’s sort function. By the way this is Dutch National Flag - 🇳🇱. ...

Boats to Save People Problem

Problem You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit. Return the minimum number of boats to carry every given person. Examples Example 1: ...

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