For further actions, you may consider blocking this person and/or reporting abuse. Out of 14 testcases the solution worked on 7 (including all the open ones and a bunch of closed ones), and didn't work on the remaining 7 (all closed). In this Leetcode Create Maximum Number problem solution You are given two integer arrays nums1 and nums2 of lengths m and n respectively. count[i min]++;4) Find the index of maximum element in count array. 1), Solution: Maximum Score From Removing Substrings (ver. The maximum count among them is 3. Else return it. Loop through the whole array of elements and increase the value at the starting point by 1 and similarly decrease the value after ending point by 1. Complete the function filledOrders in the editor below. Choose at most k different engineers out of the n engineers to form a team with the maximum performance. But it drives me crazy; I can't figure out what might be wrong with it. LeetCode claims that the optimal solution (shown in the "Solution" tab) uses a linear search for the maximum value of the sub-array in each recursive step. Consider adding an explanation to help future visitors learn important elements of your solution, so they can apply this info to their own coding issues. Templates let you quickly answer FAQs or store snippets for re-use. How can I remove a key from a Python dictionary? This problem 1. Reverse Integer LeetCode 8. Below is the implementation of above approach: Time Complexity: O(n*log(n))Auxiliary Space: O(n), Approximate Greedy algorithm for NP complete problems, Some medium level problems on Greedy algorithm, Divide N segments into two non-empty groups such that given condition is satisfied, Maximum types of candies a person can eat if only N/2 of them can be eaten, Maximum number of prime factors a number can have with exactly x factors, Maximum number of parallelograms that can be made using the given length of line segments, Maximum number of teams that can be formed with given persons, Maximum number of segments that can contain the given points, Maximum XOR value of maximum and second maximum element among all possible subarrays, Count cells in a grid from which maximum number of cells can be reached by K vertical or horizontal jumps, Maximum number of diamonds that can be gained in K minutes, Maximum number that can be display on Seven Segment Display using N segments. This is part of a series of Leetcode solution explanations (index). This is the same example as the first but k = 3. Minimum Absolute Sum Difference, LeetCode 1819. Are you sure you want to hide this comment? Minimum Degree of a Connected Trio in a Graph, LeetCode 1764. which action is legal for an operator of a pwc? Are you sure you want to create this branch? Maximum XOR for Each Query, LeetCode 1830. 2), Solution: Minimum Remove to Make Valid Parentheses, Solution: Find the Most Competitive Subsequence, Solution: Longest Word in Dictionary through Deleting, Solution: Shortest Unsorted Continuous Subarray, Solution: Intersection of Two Linked Lists, Solution: Average of Levels in Binary Tree, Solution: Short Encoding of Words (ver. Two Sum Leetcode Solution. Type is an everyday concept to programmers, but its surprisingly difficult to define it succinctly. 3) For each interval [x, y], run a loop for i = x to y and do following in loop. You may assume that each input would have exactly one solution, and you may not use the same element twice. Is it possible to rotate a window 90 degrees if it has the same length and width. The idea is to define the size of our buckets such that the maximum gap will necessarily be larger than a single bucket. Minimum Elements to Add to Form a Given Sum, LeetCode 1786. A tag already exists with the provided branch name. (Jump to: Problem Description || Solution Idea). 1), Solution: Maximum Score From Removing Substrings (ver. (Jump to: Problem Description || Code: JavaScript | Python | Java | C++). "After the incident", I started to be more careful not to trip over things. This blog is served on the requirements of some peoples. 1 n 2 x 105. Find Nearest Point That Has the Same X or Y Coordinate Cannot retrieve contributors at this time. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68. n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4. What is the purpose of this D-shaped ring at the base of the tongue on my hiking boots? Python / Modern C++ Solutions of All 2577 LeetCode Problems (Weekly Update) Awesome Open Source. With you every step of your journey. 2), Solution: The K Weakest Rows in a Matrix (ver. filledOrders has the following parameter (s): order : an array of integers listing the orders. Unflagging seanpgallivan will restore default visibility to their posts. Keep track of maxFreq which is basically a pointer to the largest key in stacks. Lowest Common Ancestor of a Binary Tree, LeetCode 238. . Complete the function filledOrders in the editor below. Put call objects in TreeMap, with key = the call's start time and value = Call object TreeMap<Integer, Call> treemap HashMap<Call, Integer> dp //caches max possible volume for a given call earliestCall = tm.firstKey (); return dfs (earliest) function dfs (Call call) { if dp.get (call) != null return dp.get (call) Median of Two Sorted Arrays 5. 2), Solution: The K Weakest Rows in a Matrix (ver. Made with love and Ruby on Rails. A subarray is a contiguous subsequence of the array. Built on Forem the open source software that powers DEV and other inclusive communities. Read N Characters Given Read4, LeetCode 158. (Jump to: Problem Description || Code: JavaScript | Python | Java | C++). It will become hidden in your post, but will still be visible via the comment's permalink. Lowest Common Ancestor of a Binary Tree III, LeetCode 1676. Approach: In order to meet the demand of maximum number of customers we must start with the customer with minimum demand so that we have maximum amount of rice left to satisfy remaining customers. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. @DenisShvetsov--placed suggested code in answer. For example, if 53 is pushed twice, the first copy will be saved to Stack 1, the second copy to Stack 2. Over one million developers have joined DEV in order to ensure they stay up-to-date on modern best practices. The idea is to consider all events (all arrivals and exits) in sorted order. Form Array by Concatenating Subarrays of Another Array, LeetCode 1770. The sizes a and b are decided by staff as per the demand. Conclusion Sliding Window Maximum is nothing but the maximum element present in each contiguous subarray of size k k k (given). Why do we calculate the second half of frequencies in DFT? Sliding Window Maximum (LeetCode) Given an array nums, there is a sliding window of size k which is moving from the very left of the array to . Python / Modern C++ Solutions of All 2493 LeetCode Problems (Weekly Update) - LeetCode-Solutions/orders-with-maximum-quantity-above-average.sql at master . Find Median from Data Stream, Leetcode 297. 22 . Return the maximum total number of units that can be put on the truck. Are you sure you want to hide this comment? One extremely powerful typescript feature is automatic type narrowing based on control flow. Here is what you can do to flag seanpgallivan: seanpgallivan consistently posts content that violates DEV Community's Input: nums = [0,1,2,2,5,7], maximumBit = 3, vector getMaximumXor(vector& nums, int maximumBit) {, for (int i = nums.size() - 1; i >= 0; i--) {. Example 2: Input: nums = [-3,-2,-1,0,0,1,2] Output: 3 Explanation: There are 2 positive integers and 3 negative integers. By using our site, you michael grant actor . Complete the function maximumProfit which takes in the integer array denoting the profit factors of all components and returns a single integer denoting the answer. (Jump to: Solution Idea || Code: JavaScript | Python | Java | C++). Only one valid answer exists. Maximize Number of Nice Divisors, LeetCode 1810. ZigZag Conversion LeetCode 7. Unflagging seanpgallivan will restore default visibility to their posts. Thanks for keeping DEV Community safe. Fledgling software developer; the struggle is a Rational Approximation. Search. Problem solution in Python. 1. Maximum Profit in Job Scheduling [Java/C++/Python] DP Solution lee215 176415 Oct 20, 2019 Explanation Sort the jobs by endTime. Also, we should remember to modulo 1e9+7 before we return best. Return the maximum performance of this team. Find Nearest Point That Has the Same X or Y Coordinate, LeetCode 1780. A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you have the best browsing experience on our website. Palindrome Number 10. Now, let's see the leetcode solution of 1. . Once the truck is full (T == 0), or once the iteration is done, we should return ans. DEV Community 2016 - 2023. This tutorial is only for Educational and Learning purpose. Once unpublished, this post will become invisible to the public and only accessible to seanpgallivan. Maximum Number of Vowels in a Substring of Given Length: C++ Python: O . Therefore, sort the customers according to the increasing order of demand so that maximum number of customers can be satisfied. 1), Solution: Short Encoding of Words (ver. Count Nice Pairs in an Array, LeetCode 1815. Your answer would be more helpful if you explain why the code you posted works- could you perhaps edit your answer to include that? 157 more parts. 2nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7. Remove Duplicates From an Unsorted Linked List, LeetCode 1839. Also time complexity of above solution depends on lengths of intervals. Zigzag Conversion 7. Ryan Carniato and Dan Abramov discuss the evolution of React! Letter Combinations of a Phone Number, LeetCode 19. 160 Solution: Out of Boundary Paths 161 Solution: Redundant Connection Maximize the Beauty of the Garden, LeetCode 1790. . 1) Traverse all intervals and find min and max time (time at which first guest arrives and time at which last guest leaves) 2) Create a count array of size 'max - min + 1'. Solution: Vertical Order Traversal of a Binary Tree, Solution: Count Ways to Make Array With Product, Solution: Smallest String With A Given Numeric Value, Solution: Concatenation of Consecutive Binary Numbers, Solution: Minimum Operations to Make a Subsequence, Solution: Find Kth Largest XOR Coordinate Value, Solution: Change Minimum Characters to Satisfy One of Three Conditions, Solution: Shortest Distance to a Character, Solution: Number of Steps to Reduce a Number to Zero, Solution: Maximum Score From Removing Substrings (ver. Input: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70] Output: 120 Explanation: The subset chosen is the first and fourth job. Since the answer can be a huge number, return it modulo 10^9 + 7. At Each Problem with Successful submission with all Test Cases Passed, you will get a score or marks and LeetCode Coins. Examples: Constraints: 1 <= <= k <= n <= 10^5 speed.length == n efficiency.length == n 1 <= speed [i] <= 10^5 We're a place where coders share, stay up-to-date and grow their careers. (Jump to: Solution Idea || Code: JavaScript | Python | Java | C++). You're going to want to catch up on this comment thread! Javascript is faster by passing only the index reference into the priority queue, rather than combining both stats into an array before storage. DEV Community 2016 - 2023. The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers. Premium. A widget manufacturer is facing unexpectedly high demand for its new product,. 2 hours ago. acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Data Structure & Algorithm-Self Paced(C++/JAVA), Android App Development with Kotlin(Live), Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Introduction to Greedy Algorithm Data Structures and Algorithm Tutorials, Greedy Algorithms (General Structure and Applications), Difference between Greedy Algorithm and Divide and Conquer Algorithm, Comparison among Greedy, Divide and Conquer and Dynamic Programming algorithm, Activity Selection Problem | Greedy Algo-1, Maximize array sum after K negations using Sorting, Minimum sum of absolute difference of pairs of two arrays, Minimum increment/decrement to make array non-Increasing, Sum of Areas of Rectangles possible for an array, Largest lexicographic array with at-most K consecutive swaps, Partition into two subsets of lengths K and (N k) such that the difference of sums is maximum, Program for First Fit algorithm in Memory Management, Program for Best Fit algorithm in Memory Management, Program for Worst Fit algorithm in Memory Management, Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive), Job Scheduling with two jobs allowed at a time, Prims Algorithm for Minimum Spanning Tree (MST), Dials Algorithm (Optimized Dijkstra for small range weights), Number of single cycle components in an undirected graph, Greedy Approximate Algorithm for Set Cover Problem, Bin Packing Problem (Minimize number of used Bins), Graph Coloring | Set 2 (Greedy Algorithm), Greedy Approximate Algorithm for K Centers Problem, Approximate solution for Travelling Salesman Problem using MST, Greedy Algorithm to find Minimum number of Coins, Buy Maximum Stocks if i stocks can be bought on i-th day, Find the minimum and maximum amount to buy all N candies, Find maximum equal sum of every three stacks, Divide cuboid into cubes such that sum of volumes is maximum, Maximum number of customers that can be satisfied with given quantity, Minimum rotations to unlock a circular lock, Minimum rooms for m events of n batches with given schedule, Minimum cost to make array size 1 by removing larger of pairs, Minimum cost for acquiring all coins with k extra coins allowed with every coin, Minimum increment by k operations to make all elements equal, Find minimum number of currency notes and values that sum to given amount, Smallest subset with sum greater than all other elements, Maximum trains for which stoppage can be provided, Minimum Fibonacci terms with sum equal to K, Divide 1 to n into two groups with minimum sum difference, Minimum difference between groups of size two, Minimum Number of Platforms Required for a Railway/Bus Station, Minimum initial vertices to traverse whole matrix with given conditions, Largest palindromic number by permuting digits, Find smallest number with given number of digits and sum of digits, Lexicographically largest subsequence such that every character occurs at least k times, Maximum elements that can be made equal with k updates, Minimize Cash Flow among a given set of friends who have borrowed money from each other, Minimum cost to process m tasks where switching costs, Find minimum time to finish all jobs with given constraints, Minimize the maximum difference between the heights, Minimum edges to reverse to make path from a source to a destination, Find the Largest Cube formed by Deleting minimum Digits from a number, Rearrange characters in a String such that no two adjacent characters are same, Rearrange a string so that all same characters become d distance away. Problem List. Longest Palindromic Substring 6. rev2023.3.3.43278. Relation between transaction data and transaction id. Then we could go through the individual buckets and perform another, smaller sort before joining the entire deck together. (Jump to: Problem Description || Solution Idea). Two Sum Leetcode Solution Leetcode Solution. Given the size of the packets a and b, the total quantity of rice available d and the number of customers n, find out maximum number of customers that can be satisfied with the given quantity of rice. Two Sum - Solution in Java This is an O (N) complexity solution. At Each Problem with Successful submission with all Test Cases Passed, you will get a score or marks and LeetCode Coins. Note: If a customer orders 2 3, he requires 2 packets of size a and 3 packets of size b. code of conduct because it is harassing, offensive or spammy. Search in Rotated Sorted Array II, LeetCode 124. Substring with Concatenation of All Words, LeetCode 33. Templates let you quickly answer FAQs or store snippets for re-use. How do/should administrators estimate the cost of producing an online introductory mathematics class? 2), Solution: The K Weakest Rows in a Matrix (ver. Queries on Number of Points Inside a Circle, LeetCode 1829. class Solution { Hello Programmers/Coders, Today we are going to share solutions to the Programming problems of LeetCode Solutions in C++, Java, & Python. Minimum Interval to Include Each Query, . 2), Solution: Remove Palindromic Subsequences, Solution: Check If a String Contains All Binary Codes of Size K, Solution: Swapping Nodes in a Linked List, Solution: Best Time to Buy and Sell Stock with Transaction Fee, Solution: Generate Random Point in a Circle, Solution: Reconstruct Original Digits from English, Solution: Flip Binary Tree To Match Preorder Traversal, Solution: Minimum Operations to Make Array Equal, Solution: Determine if String Halves Are Alike, Solution: Letter Combinations of a Phone Number, Solution: Longest Increasing Path in a Matrix, Solution: Remove All Adjacent Duplicates in String II, Solution: Number of Submatrices That Sum to Target, Solution: Remove Nth Node From End of List, Solution: Critical Connections in a Network, Solution: Furthest Building You Can Reach, Solution: Find First and Last Position of Element in Sorted Array, Solution: Convert Sorted List to Binary Search Tree, Solution: Delete Operation for Two Strings, Solution: Construct Target Array With Multiple Sums, Solution: Maximum Points You Can Obtain from Cards, Solution: Flatten Binary Tree to Linked List, Solution: Minimum Moves to Equal Array Elements II, Solution: Binary Tree Level Order Traversal, Solution: Evaluate Reverse Polish Notation, Solution: Partitioning Into Minimum Number Of Deci-Binary Numbers, Solution: Maximum Product of Word Lengths, Solution: Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts, Solution: Construct Binary Tree from Preorder and Inorder Traversal, Solution: Minimum Number of Refueling Stops, Solution: Number of Subarrays with Bounded Maximum, 11 Tips That Make You a Better Typescript Programmer, n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Once unpublished, all posts by seanpgallivan will become hidden and only accessible to themselves. Save my name, email, and website in this browser for the next time I comment. How can I use it? Largest Merge Of Two Strings, LeetCode 1760. Note that the implementation doesnt create a single sorted list of all events, rather it individually sorts arr[] and dep[] arrays, and then uses merge process of merge sort to process them together as a single sorted array. You must write an algorithm that runs in linear time and uses linear extra space. Here is what you can do to flag seanpgallivan: seanpgallivan consistently posts content that violates DEV Community's For this problem, we don't need to actually sort every element, which would take longer than O(N) time. We use Stacks so that "if there is a tie for most frequent element, the element closest to the top of the stack is removed and returned.". Two Sum is generated by Leetcode but the solution is provided by CodingBroz. 1), Solution: Maximum Score From Removing Substrings (ver. Assume indexing of customers starts from 1. Read N Characters Given Read4 II - Call multiple times, LeetCode 236. In this Leetcode Maximum Product Subarray problem solution we have Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. Palindrome Number LeetCode 10. This is O (n^2) in the worst case. Why did Ukraine abstain from the UNHRC vote on China? he always will to help others. Code only answers are discouraged on SO. 2nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3. maximum value from ith to last element. Count Pairs With XOR in a Range, LeetCode 1804. Yash is a Full Stack web developer. Your email address will not be published. Lowest Common Ancestor of a Binary Tree IV, Leetcode 1727. Longest Substring Without Repeating Characters, LeetCode 5. Given a number of widgets available and a list of customer orders, what is the maximum number of orders the manufacturer can fulfill in full? Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. The maximum count among them is 3. Each customer demands the rice in two different packaging of size a and size b. DEV Community 2016 - 2023. If the array contains less than two elements, return 0. Maximum Average Pass Ratio, LeetCode 1793. Once unpublished, all posts by seanpgallivan will become hidden and only accessible to themselves. The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3. A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you have the best browsing experience on our website. Customer Placing the Largest Number of Orders - LeetCode Submissions 4.71 (38 votes) Solution Approach: Using LIMIT [Accepted] Algorithm First, we can select the customer_number and the according count of orders using GROUP BY. code of conduct because it is harassing, offensive or spammy. A new variety of rice has been brought in supermarket and being available for the first time, the quantity of this rice is limited. Once unpublished, this post will become invisible to the public and only accessible to seanpgallivan. Calculate the maximum possible profit that a valid machine consisting of three components can have, or decide that it's impossible to build any machine. This would be a better answer if you explained how the code you provided answers the question. I find it helpful to use Set as a conceptual model instead. Once suspended, seanpgallivan will not be able to comment or publish posts until their suspension is removed. 160 Solution: Out of Boundary Paths 161 Solution: Redundant Connection This is part of a series of Leetcode solution explanations ( index ). 157 more parts. Create an auxiliary array used for storing dynamic data of starting and ending points.2). nums1 and nums2 represent the digits of two numbers. Connect and share knowledge within a single location that is structured and easy to search. The test contains 2 problems; they give you 90 minutes to solve them. That would mean that our answer could then be found by comparing the highest value in each bucket with the lowest value in the next occupied bucket. Programming Languages. If we make sure to define the bucket size smaller than this value, then as stated earlier, the two numbers that form the maximum gap will have to be found in separate buckets. The function must return a single integer denoting the maximum possible number of fulfilled orders. Library implementations of Sorting algorithms, Maximum sum of at most two non-overlapping intervals in a list of Intervals | Interval Scheduling Problem, Find Non-overlapping intervals among a given set of intervals, Check if any two intervals intersects among a given set of intervals, Check if any K ranges overlap at any point, Maximum number of operations required such that no pairs from a Matrix overlap, Maximum rods to put horizontally such that no two rods overlap on X coordinate, Maximum prefix sum which is equal to suffix sum such that prefix and suffix do not overlap, Minimum time at which at least K out of N circles expanding 1 unit per second overlap, Find time required to reach point N from point 0 according to given rules. Find Minimum in Rotated Sorted Array II, LeetCode 157. 1), Solution: Short Encoding of Words (ver. Zhongli4869. Time range [1-3]+ [3-6] , we get profit of 120 = 50 + 70. This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. . Fledgling software developer; the struggle is a Rational Approximation. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Maximum Sum Circular Subarray, LeetCode 953. Maximum Number of Groups Getting Fresh Donuts, LeetCode 1817. And since we only need to make one comparison per pair of buckets with consecutive numbers, and as there are only a maximum of 2 * N buckets, the comparisons will only take O(N) time, as well. Identify those arcade games from a 1983 Brazilian music video. Implement Trie II (Prefix Tree), LeetCode 1805. Once suspended, seanpgallivan will not be able to comment or publish posts until their suspension is removed. Since the index numbers between speed and efficiency correspond to each other, we shouldn't just sort efficiency, however. Solution: Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts # algorithms # javascript # java # python Leetcode Solutions (161 Part Series) 1 Solution: Next Permutation 2 Solution: Trim a Binary Search Tree . Fledgling software developer; the struggle is a Rational Approximation. Shortest Path in a Hidden Grid, LeetCode 1779. Minimum Limit of Balls in a Bag, LeetCode 1761. In end, check if diff is less than or equal to 0, maximum difference does not exist. A bucket sort involves creating an array (buckets) in which the elements represent buckets that cover the spread of the numbers to be sorted. Being inexperienced as I am, I failed, because it took me longer than that. If you choose a job that ends at time X you will be able to start another job that starts at time X. We're a place where coders share, stay up-to-date and grow their careers. Welcome, & thanks for contributing. Longest Substring Without Repeating Characters 4. In this post, we are going to solve the 1. Thanks for keeping DEV Community safe. If seanpgallivan is not suspended, they can still re-publish their posts from their dashboard. The MinPriorityQueue() npm is easier to use, but not as efficient. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. Saving highest frequencies in descending order - Create Map> stacks which is a Map from frequency (1, 2,) to a Stack of Integers with that frequency. Made with love and Ruby on Rails. Given an integer array nums, return the maximum difference between two successive elements in its sorted form. Time Complexity of this method is O(nLogn).Thanks to Gaurav Ahirwar for suggesting this method.Another Efficient Solution :Approach :1). Most upvoted and relevant comments will be first. Saving frequency of each number - Create Map freq that's a Map from x to the number of occurrences of x. Quality answers are upvoted over time, mostly by future visitors gaining insight from your explanations. Reverse Integer 8. Serialize and Deserialize Binary Tree, LeetCode 300. Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2. Maximum Product of Splitted Binary Tree LeetCode Solution - Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.. Return the maximum product of the sums of the two subtrees.Since the answer may be too large, return it modulo 10 9 + 7. push() and pop() are implemented by updating the above freq, stacks, and maxFreq. Specifically, I came up with the solution for the first problem (filled orders, see below) in, like 30 minutes, and spent the rest of the time trying to debugg it. Example 2: Longest Palindromic Substring, LeetCode 17. If you liked this solution or found it useful, please like this post and/or upvote my solution post on Leetcode's forums. Are you sure you want to create this branch? The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers. Minimum Number of Operations to Make String Sorted, LeetCode 1832. This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. DEV Community A constructive and inclusive social network for software developers. Explanation: In first example, the order of customers according to their demand is: From this, it can easily be concluded that only customer 5 and customer 1 can be satisfied for total demand of 1 + 2 = 3.