Binary Search
Demo
Star Sum
Amazon Online Assessment
E-Mart Product Ranking
Amazon Online Assessment
Minimum Total Wattage
Amazon Online Assessment
Best Stock Combos
Amazon Online Assessment Subset
Split String
Amazon Online Assessment Array
Find Pairs
Amazon Online Assessment Array
Merge Adjacent Numbers
Amazon Online Assessment Array
Split Array III
Amazon Online Assessment Array
Minimum Number of Swaps
Amazon Online Assessment Array
Collection of Circles
Google Onsite MST
Search Extensible String
New Google Onsite
Maximum Deviation Among All Substrings
Online Assessment String
Maximum Greyness
New Online Assessment Matrix
Separate Pages
New Online Assessment Bit
Shop for Clothes on a Budget
New Online Assessment
Color Palette
Online Assessment Array
Min Appends to Make Subsequence
Online Assessment String
Min Swaps to Partition
New Online Assessment
Minimum Net Price Change
New Online Assessment Intern Array
Channels Maximum Quality
New Online Assessment
Slice Array
New Online Assessment Array
Stock Fluctuation
New Online Assessment Array
Decoding String
New Online Assessment String
Maximum Precipitation
New Online Assessment
Count Reviews II
New Online Assessment
Count Reviews Combinations
New Online Assessment
LRU Browser History
New Online Assessment
Split Array II
Amazon Google New
Load Cargo
Amazon Google New
Split Array
Amazon Google New
Find Bridges In A Graph
Amazon Google MST New
Closest Pair of Molecules
Google Amazon New
Search Matrix
Facebook New
Max Submatrix Sum
Google Facebook New
Cache Hit Ratio
Google Facebook Amazon New
Find Cut Vertices
Google Amazon New
Two Sum Smaller Than Target
Google Amazon New
Can Make Palindrome
Facebook New
Discount Calculator
Amazon New Online Assessment
Max Sink Area
Amazon New
Measure Island Border
Facebook New
Construct Word Using Dice
Google New
Recursive Islands and Lakes
Google Hard New
Packaging Automation
Amazon New Online Assessment
Secret Fruit List
Amazon Online Assessment New
Find Related Products
Amazon Online Assessment New
Optimize Memory Usage
Online Assessment
Min Cost To Add New Roads
Online Assessment
Connect Ropes
Amazon Online Assessment
Pizza Shop
Google Phone
Least Common Ancestor Of Multiple Nodes
Amazon Phone Tree
Remove Duplicated IPv4 Addresses
Amazon Onsite
Fibonacci Base I
Google
Activate Fountain
Twitter Online Assessment
Reaching Point
Twitter Online Assessment
K-Difference
Twitter Online Assessment
Find Critical Nodes
Amazon Online Assessment
Zombie Matrix
Amazon HOT
Data Center Critical Connection
Amazon Online Assessment
Min Cost to Repair Edges (Minimum Spanning Tree II)
Amazon Online Assessment MST Graph
Rose Garden
Google Online Assessment
Minimum Number Of Decreasing Subsequence Partitions
Google Online Assessment Hard DP
Cut Binary Search Tree
Amazon Tree BST Hard LC
Subtree: Maximum Average Node
Amazon Online Assessment Medium Tree
Fill 2D Array
Google Online Assessment
Rearrange String
String
Pickup Coupon
Google Online Assessment
Tree Diameter
Google
Top N Buzzwords
Amazon Online Assessment HOT
Load Balancer
Amazon Online Assessment
Find Substrings
Amazon Online Assessment Hard
Partition String
Amazon Online Assessment String Medium

Packaging Automation

The Fulfillment Center consists of a packaging bay where orders are automatically packaged in groups(n). The first group can only have 1 item and all the subsequent groups can have one item more than the previous group. Given a list of items on groups, perform certain operations in order to satisfy the constraints required by packaging automation.
The conditions are as follows:
-The first group must contain 1 item only.
-For all other groups, the difference between the number of items in adjacent groups must not be greater than 1. In other words, for 1<=i<n, arr[i]-arr[i-1]<=1

To accomplish this, the following operations are available:
- Rearrange the groups in any way.
- Reduce any group to any number that is at least 1
Write an algorithm to find the maximum number of items that can be packaged in the last group with the conditions in place.

Input
The function/method consists of two arguments:
numGroups, an integer representing the number of groups(n);
arr, a list of integers representing the number of items in each group

Output
Return an integer representing the maximum items that can be packaged for the final group of the list given the conditions above.

Example1:
Input:
[3,1,3,4]
Output:
4
Explanation:
Subtract 1 from the first group making the list [2, 1, 3, 4]. Rearrange the list into [1, 2, 3, 4]. The final maximum of items that can be packaged in the last group is 4.
Example2:
Input:
[1,3,2,2]
Output:
3
Example3:
Input:
[1,1,1,1]
Output:
1
Example4:
Input:
[3,2,3,5]
Output:
4


Python


def packaging(numGroups, arr): """ :type numGroups: int :type arr: List[int] :rtype: int """