Here’s the problem statement: Given an array of integers that represents supermarket-purchase-points accumulated by customers. The points are arranged in the order of period of customer membership and no 2 members have the same points. Find the minimum number of free items that must be given out to the customers such that every customer receivesContinue reading “Scribble 4: Free Items”
Tag Archives: Code Spree
Scribble 3: Longest Mountain Range in the array
Here’s the problem statement:Given an array of integers, find the length of the longest mountain in the array.Mountain here represents a subarray where the values of the constituent integers first follow a strictly increasing and then a strictly decreasing order. For example:The array: 10, 12, 40, 30, 20, -1, 5, 6, 1Output: 6 where theContinue reading “Scribble 3: Longest Mountain Range in the array”
Scribble 2: Quadruplet Sum
Here’s the problem statement:Given an array of unique integers, find all quadruplets of distinct integers (in any order) that add up to a given target sum. For example:The array: 10, 20, 30, 40, 1, 2Target sum: 91Output: [[20, 30, 40, 1]] Let’s dive into the solution: Let’s try to build the solution using the insightsContinue reading “Scribble 2: Quadruplet Sum”
Scribble 1: Triplet Sum
Here’s the problem statement:Given an array of unique integers, find all triplets of distinct integers (in any order) that add up to a given target sum. For example:The array: 4, 19, 8, 6, -1, 15, 10Target sum: 13Output: [[4, -1, 10,], [-1, 6, 8]] Let’s dive into the solution: We can extend the approaches usedContinue reading “Scribble 1: Triplet Sum”
Scribble 0: Pair Sum
This is the first problem listed on most coding platforms. Here’s the problem statement:Given an array of unique integers, find a pair of distinct integers (in any order) that add up to a given target sum. For example:The array: 4, 19, 8, 6, -1, 15, 10Target sum: 9Output: -1, 10 Let’s dive into the solution:Continue reading “Scribble 0: Pair Sum”