question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
minimum-amount-of-time-to-fill-cups
JAVA solution || PriorityQueue
java-solution-priorityqueue-by-anyoung_h-ofro
the quetion it is to find the minimum time ,and given that can fill 2 at a time or 1 \n* to find minimum first fill how many times 2 cups can be filled using pr
anyoung_haseyo
NORMAL
2022-07-10T04:16:24.785159+00:00
2022-07-10T04:22:51.449034+00:00
482
false
* the quetion it is to find the minimum time ,and given that can fill 2 at a time or 1 \n* to find minimum first fill how many times 2 cups can be filled using priority queue(filling last maximum 2 cups) and remaining will be a left out cup fill it directly with that value.\n\n```\nclass Solution {\n public int fillCups(int[] nums) {\n int c=0,t1=0,t2=0;\n PriorityQueue<Integer>q=new PriorityQueue<>(Collections.reverseOrder());\n for(int i:nums)\n q.add(i);\n while(q.peek()!=0){\n t1=q.remove();\n t2=q.remove();\n if(t2!=0){\n q.add(t1-1);\n q.add(t2-1);\n c++;\n }\n else return c+t1;\n }\n return c;\n }\n}\n```
2
0
['Heap (Priority Queue)', 'Java']
0
minimum-amount-of-time-to-fill-cups
javascript greedy 113ms
javascript-greedy-113ms-by-henrychen222-rqii
Main idea: each time needs to remove the max count of two color(to make as much as double color being removed per step), until there is only one color left\n\nc
henrychen222
NORMAL
2022-07-10T04:15:37.591306+00:00
2022-07-10T04:17:09.363745+00:00
369
false
Main idea: each time needs to remove the max count of two color(to make as much as double color being removed per step), until there is only one color left\n```\nconst fillCups = (a) => {\n let res = 0;\n while (!valid(a)) {\n a.sort((x, y) => x - y);\n if (a[1] > 0) { // can make two color remove\n a[2]--;\n a[1]--;\n res++;\n } else { // only one color left\n res += a[2];\n break;\n }\n }\n return res;\n};\n\nconst valid = (a) => a.every(x => x <= 0);\n```
2
0
['JavaScript']
0
minimum-amount-of-time-to-fill-cups
JAVA EASY SOLUTION
java-easy-solution-by-rajatgupta1402-mzuf
JAVA EASY SOLUTION\n\n First find max and smax elements \n Reduce max and smax and increase the time\n* Return the time\n\n\nclass Solution {\n public int fi
rajatgupta1402
NORMAL
2022-07-10T04:13:10.433896+00:00
2022-07-10T04:13:10.433921+00:00
81
false
**JAVA EASY SOLUTION**\n\n* First find max and smax elements \n* Reduce max and smax and increase the time\n* Return the time\n\n```\nclass Solution {\n public int fillCups(int[] amount) {\n \n int sec = 0;\n \n while(amount[0] > 0 || amount[1] > 0 || amount[2] > 0){\n \n int fmax = (amount[0] > amount[1]) ? (amount[0] > amount[2]) ? 0 : 2 : (amount[1] > amount[2]) ? 1 : 2; \n int smax = (amount[0] > amount[1]) ? (amount[0] > amount[2]) ? (amount[1] > amount[2]) ? 1 : 2 : 0 : (amount[1] > amount[2]) ? (amount[0] > amount[2]) ? 0 : 2 : 1;\n \n amount[fmax]--;\n amount[smax]--;\n \n sec++;\n }\n \n return sec;\n }\n}```
2
0
['Java']
0
minimum-amount-of-time-to-fill-cups
[Python3] priority queue
python3-priority-queue-by-ye15-kxqo
Please pull this commit for solutions of weekly 301. \n\n\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n pq = [-x for x in amount]
ye15
NORMAL
2022-07-10T04:04:52.926175+00:00
2022-07-11T00:15:14.838777+00:00
184
false
Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/f00c06cefbc1b2305f127a8cde7ff9b010197930) for solutions of weekly 301. \n\n```\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n pq = [-x for x in amount]\n heapify(pq)\n ans = 0 \n while pq[0]: \n x = heappop(pq)\n if pq[0]: heapreplace(pq, pq[0]+1)\n heappush(pq, x+1)\n ans += 1\n return ans \n```\n\nPer @lee215, a easier solution is \n```\nclass Solution: \n def fillCups(self, amount: List[int]) -> int:\n return max(max(amount), (sum(amount)+1)//2)\n```
2
0
['Python3']
0
minimum-amount-of-time-to-fill-cups
Easy Solution Java || Beats 100.0% 👋👋
easy-solution-java-beats-1000-by-vermaan-u2d1
IntuitionApproachComplexity Time complexity: Space complexity: Code
vermaanshul975
NORMAL
2025-03-25T14:59:22.415889+00:00
2025-03-25T14:59:22.415889+00:00
58
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int fillCups(int[] amount) { int max = 0; int sum = 0; for(int i = 0;i<amount.length;i++){ sum+=amount[i]; max = Math.max(max,amount[i]); } sum = sum%2 == 0? sum/2 : (sum+1)/2; if(sum>max) return sum; return max; } } ```
1
0
['Java']
0
minimum-amount-of-time-to-fill-cups
easy to understand solution ...
easy-to-understand-solution-by-hassan21k-k16b
IntuitionApproachComplexity Time complexity: Space complexity: Code
hassan21kh1996
NORMAL
2025-03-24T19:06:46.807390+00:00
2025-03-24T19:06:46.807390+00:00
49
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python3 [] class Solution: def fillCups(self, amount: List[int]) -> int: seconds = 0 while sum([1 for am in amount if am > 0]): amount.sort() # while two elements of the three still positive , substract from the biggest two elements amount[2] -= 1 amount[1] -= 1 seconds += 1 amount.sort() seconds += amount[2] # add that last one element if exist .. return seconds ```
1
0
['Python3']
0
minimum-amount-of-time-to-fill-cups
Most optimal solution using heap
most-optimal-solution-using-heap-by-cs_2-b5yk
Code
CS_2201640100153
NORMAL
2025-02-20T11:14:07.820400+00:00
2025-02-20T11:14:07.820400+00:00
39
false
# Code ```python3 [] class Solution: import heapq def fillCups(self, amount: List[int]) -> int: h=[] time=0 for i in amount: if i > 0: heapq.heappush(h, -i) while(len(h)>1): maxi1=-heapq.heappop(h) maxi2=-heapq.heappop(h) time+=1 if maxi1 - 1 > 0: heapq.heappush(h, -(maxi1 - 1)) if maxi2 - 1 > 0: heapq.heappush(h, -(maxi2 - 1)) if h: time += -h[0] return time ```
1
0
['Array', 'Greedy', 'Heap (Priority Queue)', 'Python3']
0
minimum-amount-of-time-to-fill-cups
Track the largest and second largest
track-the-largest-and-second-largest-by-7kqo3
IntuitionApproachComplexity Time complexity: Space complexity: Code
linda2024
NORMAL
2025-01-28T21:34:58.875958+00:00
2025-01-28T21:34:58.875958+00:00
13
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```csharp [] public class Solution { public int FillCups(int[] amount) { // sort amount Array.Sort(amount); if(amount[1]+ amount[0] <= amount[2]) return amount[2]; int res = 0; while(amount[2] >0) { if (amount[0] == 0) { res += Math.Max(amount[1], amount[2]); return res; } int diff = amount[2]-amount[0] == 0 ? 1 : amount[2]-amount[0]; res += diff; amount[2] -= diff; amount[1] -= diff; Array.Sort(amount); } return res; } } ```
1
0
['C#']
0
minimum-amount-of-time-to-fill-cups
leetcodedaybyday - Beats 100% with C++ and Beats 100% with Python3
leetcodedaybyday-beats-100-with-c-and-be-pw65
IntuitionThe problem involves determining the minimum time required to fill cups with three types of liquid. At any second, we can reduce at most two cups simul
tuanlong1106
NORMAL
2025-01-02T08:08:30.599880+00:00
2025-01-02T08:08:30.599880+00:00
243
false
# Intuition The problem involves determining the minimum time required to fill cups with three types of liquid. At any second, we can reduce at most two cups simultaneously. The goal is to minimize the total time required while ensuring all cups are filled. To solve this, we focus on two key factors: 1. The cup with the maximum amount of liquid (`maxi`), as it represents the most time-consuming case if filled alone. 2. The total amount of liquid (`total`), as this gives the theoretical minimum time required if we could fill two cups at every second. # Approach 1. **Calculate Total and Maximum**: - Traverse the `amount` array to calculate the total amount of liquid (`total`) and find the maximum value (`maxi`). 2. **Determine the Minimum Time**: - If we can always fill two cups simultaneously, the minimum time is `(total + 1) // 2`. - However, if the cup with the maximum amount requires more time than this, the answer is simply `maxi`. 3. **Return the Result**: - Return the maximum of `maxi` and `(total + 1) // 2`. # Complexity - **Time Complexity**: \(O(1)\), as the array size is fixed at 3, and all operations are constant. - **Space Complexity**: \(O(1)\), as no additional space is used apart from a few variables. --- # Code ```cpp [] class Solution { public: int fillCups(vector<int>& amount) { int maxi = 0; int total = 0; for (int i = 0; i < amount.size(); i++){ total += amount[i]; maxi = max(maxi, amount[i]); } return max(maxi, (total + 1) / 2); } }; ``` ```python3 [] class Solution: def fillCups(self, amount: List[int]) -> int: maxi = 0 total = 0 for i in range(len(amount)): total += amount[i] maxi = max(maxi, amount[i]) return max(maxi, (total + 1) // 2) ```
1
0
['C++', 'Python3']
0
minimum-amount-of-time-to-fill-cups
C# Greedy Solution
c-greedy-solution-by-getrid-12gv
Intuition\n- Describe your first thoughts on how to solve this problem. The intuition behind solving this problem is to minimize the number of seconds needed t
GetRid
NORMAL
2024-11-12T16:51:58.243209+00:00
2024-11-12T16:51:58.243248+00:00
9
false
# Intuition\n- <!-- Describe your first thoughts on how to solve this problem. -->The intuition behind solving this problem is to minimize the number of seconds needed to fill the cups by always maximizing the number of cups filled at each step. When I read the problem, my first thought was to try to fill two cups whenever possible, as this will clearly reduce the total number of seconds compared to filling just one cup at a time. Specifically, it seemed optimal to always pick the two largest numbers (representing the two types of water with the most cups left to fill) to decrement, thereby reducing the problem as fast as possible.\n___\n# Approach\n- <!-- Describe your approach to solving the problem. -->Identify Largest Elements: Repeatedly identify the two largest amounts in the array since filling these two will reduce the problem fastest.\n- Sorting: Sort the amount array in descending order so that the two largest values are always at the end.\n- Decrement and Track Seconds: In each iteration, decrement the two largest values if they are non-zero, and increment the counter representing the time taken.\n___\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(n) where \'n\' is the sum of all elements in \'amount\'.\n___\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(1) since we are only using a fixed amount of extra space regardless of the input size.\n___\n# Code\n```csharp []\npublic class Solution {\n public int FillCups(int[] amount) {\n int seconds = 0;\n\n // Sort until all values are 0\n while (amount[0] != 0 || amount[1] != 0 || amount[2] != 0) {\n Array.Sort(amount);\n // Fill the two largest cups (amount[2] and amount[1])\n if (amount[2] > 0) amount[2]--;\n if (amount[1] > 0) amount[1]--;\n seconds++;\n }\n\n return seconds;\n }\n}\n\n// Sorting: By sorting the amount array in each iteration, we ensure that we are always working with the two largest values, which helps minimize the number of seconds.\n// Loop: The loop continues until all values are zero.\n// Decrement: In each iteration, decrement the two largest values if they are greater than zero, and increment the seconds counter.\n```
1
0
['Array', 'Greedy', 'Sorting', 'C#']
0
minimum-amount-of-time-to-fill-cups
O(1) Complexity
o1-complexity-by-diegomc252525-vq0q
Complexity\n- Time complexity:\nO(1)\n- Space complexity:\nO(1)\n# Code\ncsharp []\npublic class Solution {\n public int FillCups(int[] amount)\n {\n
diegomc252525
NORMAL
2024-10-29T01:07:28.678357+00:00
2024-10-29T01:07:28.678377+00:00
5
false
# Complexity\n- Time complexity:\nO(1)\n- Space complexity:\nO(1)\n# Code\n```csharp []\npublic class Solution {\n public int FillCups(int[] amount)\n {\n Array.Sort(amount);\n if (amount[0] + amount[1] >= amount[2])\n return (amount.Sum() + 1) / 2;\n return amount[2];\n }\n}\n```
1
0
['C#']
0
minimum-amount-of-time-to-fill-cups
👨🏻‍💻 EASY CODE || C++ ✅
easy-code-c-by-kingz_0101-d0t9
Code\ncpp []\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n int Max=0 , sum=0;\n for(int i : amount){\n Max=max(
aryann_0101
NORMAL
2024-10-20T17:12:54.737536+00:00
2024-10-20T17:12:54.737566+00:00
22
false
# Code\n```cpp []\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n int Max=0 , sum=0;\n for(int i : amount){\n Max=max(i,Max);\n sum+=i;\n }\n return max(Max,(sum+1)/2);\n }\n};\n```
1
0
['C++']
0
minimum-amount-of-time-to-fill-cups
O(1) Time & Space, Plus Two Other Approaches with Explanations! 🥃🧊🔥
o1-time-space-plus-two-other-approaches-yuh66
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves determining the minimum amount of time needed to fill three types
sirsebastian5500
NORMAL
2024-06-13T15:28:13.487141+00:00
2024-06-13T15:29:13.371747+00:00
187
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves determining the minimum amount of time needed to fill three types of cups, each requiring a different number of fills. The main insight is that in each unit of time, we can fill at most two different types of cups. Therefore, our strategy should aim to maximize the efficiency of each time unit by always trying to fill the two types of cups that have the most remaining fills required.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThere are several approaches to solve this problem:\n\n1. **Direct Comparison and Sorting for Length 3 Array**: For an array of fixed length 3, we can directly sort and compare the elements to determine the minimum time required. If the maximum number of fills required is greater than the sum of the other two, the answer is simply the maximum value. Otherwise, the answer is half the total fills rounded up.\n\n2. **Sorting for Arbitrary Length Array**: For arrays of arbitrary length, sorting the array and comparing the maximum value with half the total fills provides an efficient solution.\n\n3. **Max Heap**: Using a max heap, we can always pair the two most filled cup types in each unit of time. This approach ensures that we are efficiently reducing the highest fills first.\n\n# Complexity\n- Time complexity:\n - `fillCups`: $$O(1)$$ because sorting and comparing a fixed-length array takes constant time.\n - `fillCups2`: $$O(n \\log n)$$ due to sorting the array.\n - `fillCups3`: $$O(n \\log n)$$ due to heap operations.\n\n- Space complexity:\n - `fillCups`: $$O(1)$$ as it uses constant extra space.\n - `fillCups2`: $$O(n)$$ due to sorting, which requires additional space for the sorted array.\n - `fillCups3`: $$O(n)$$ due to the space needed for the max heap.\n\n# Code\n```python\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n # Sorting for Length 3 Array\n if amount[0] > amount[1]: amount[0], amount[1] = amount[1], amount[0]\n if amount[1] > amount[2]: amount[1], amount[2] = amount[2], amount[1]\n if amount[0] > amount[1]: amount[0], amount[1] = amount[1], amount[0]\n\n if amount[2] >= amount[0] + amount[1]: # Max cup number give lower bound.\n return amount[2]\n \n return ((amount[0] + amount[1] + amount[2]) + 1) // 2 # Filling times halves (2 cups per filling).\n\n # O(1) time.\n # O(1) auxiliary space.\n # O(1) total space.\n \n\n def fillCups2(self, amount: List[int]) -> int:\n # Sorting for Arbitrary Length Array\n amount.sort() \n max_cups = amount[-1]\n total_cups = sum(amount)\n return max(max_cups, (total_cups + 1) // 2)\n\n # O(n * log(n)) time.\n # O(n) auxiliary space.\n # O(n) total space.\n\n\n def fillCups3(self, amount: List[int]) -> int:\n # Max Heap\n max_heap = [-num_cups for num_cups in amount if num_cups > 0]\n heapq.heapify(max_heap)\n\n seconds = 0\n while max_heap:\n if len(max_heap) >= 2:\n cups_type_1, cups_type_2 = heapq.heappop(max_heap), heapq.heappop(max_heap) \n cups_type_1, cups_type_2 = cups_type_1 + 1, cups_type_2 + 1\n\n if cups_type_1 < 0:\n heapq.heappush(max_heap, cups_type_1)\n if cups_type_2 < 0:\n heapq.heappush(max_heap, cups_type_2)\n \n else:\n cups_type_1 = heapq.heappop(max_heap)\n cups_type_1 += 1\n\n if cups_type_1 < 0:\n heapq.heappush(max_heap, cups_type_1)\n\n seconds += 1\n\n return seconds \n\n # O(n * log(n)) time.\n # O(n) auxiliary space.\n # O(n) total space.\n```\nUPVOTE IF HELPFUL \uD83E\uDD19\nTHANKS
1
0
['Python3']
0
minimum-amount-of-time-to-fill-cups
Python Max Heap Simple Solution
python-max-heap-simple-solution-by-asu2s-qoej
Complexity\n- Time complexity: O(k * logn)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n
asu2sh
NORMAL
2024-05-09T14:55:18.548734+00:00
2024-05-09T14:55:18.548764+00:00
168
false
# Complexity\n- Time complexity: $$O(k * logn)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n amount = [-a for a in amount]\n heapq.heapify(amount)\n res = 0\n while True:\n first = heapq.heappop(amount)\n second = heapq.heappop(amount)\n if not first and not second:\n break\n heapq.heappush(amount, first+1) if first else heapq.heappush(amount, first)\n heapq.heappush(amount, second+1) if second else heapq.heappush(amount, second)\n res += 1\n return res\n```
1
0
['Heap (Priority Queue)', 'Python3']
1
minimum-amount-of-time-to-fill-cups
Beats 76.64%🔥|| easy JAVA Solution✅
beats-7664-easy-java-solution-by-elockly-rhou
Intuition\nthe main idea of the problem is to try to make all value of the arry are Close and to try to fill 2 cup in each cycle \n# Approach\nStep 1 :\n sor
elocklymuhamed
NORMAL
2024-04-11T13:41:37.041031+00:00
2024-04-11T13:41:37.041061+00:00
174
false
# Intuition\nthe main idea of the problem is to try to make all value of the arry are Close and to try to fill 2 cup in each cycle \n# Approach\nStep 1 :\n sorting the arry to get the biggiest and the medium and the smallest value\nStep 2 : \n decrease the biggiest and the midium value \nStep 3 :\n resortin the array by compare each value by other to make always the biggiest value at the firist posation and the midimu at the secend posation \n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution {\n public int fillCups(int[] amount) {\n\n Arrays.sort(amount);\n int biggiestAmount = amount[2];\n int midiumAmount = amount[1];\n int smallestAmount = amount[0];\n int minNumOfSec = 0;\n\n while (biggiestAmount > 0) {\n\n minNumOfSec++;\n biggiestAmount--;\n midiumAmount--;\n if (biggiestAmount < midiumAmount) {\n int temp = biggiestAmount;\n biggiestAmount = midiumAmount;\n midiumAmount = temp;\n }\n if (midiumAmount < smallestAmount) {\n\n if (biggiestAmount < smallestAmount) {\n int temp = biggiestAmount;\n biggiestAmount = smallestAmount;\n smallestAmount = temp;\n }\n\n int temp = midiumAmount;\n midiumAmount = smallestAmount;\n smallestAmount = temp;\n }\n }\n\n return minNumOfSec;\n }\n}\n```
1
0
['Java']
0
minimum-amount-of-time-to-fill-cups
Python || One line || O(1)
python-one-line-o1-by-luisfrodriguezr-pmf6
\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n return max(max(amount), sum(amount) // 2 + sum(amount) % 2)\n
ergodico
NORMAL
2024-01-16T19:00:26.939640+00:00
2024-01-16T19:00:26.939664+00:00
7
false
```\nclass Solution:\n def fillCups(self, amount: List[int]) -> int:\n return max(max(amount), sum(amount) // 2 + sum(amount) % 2)\n```
1
0
[]
0
minimum-amount-of-time-to-fill-cups
Simple java code 0 ms beats 100 %
simple-java-code-0-ms-beats-100-by-arobh-7zi9
\n# Complexity\n- \n\n# Code\n\nclass Solution {\n public int fillCups(int[] amount) {\n int max=0,sum=0;\n for(int i:amount){\n max
Arobh
NORMAL
2024-01-10T04:10:05.320504+00:00
2024-01-10T04:10:05.320537+00:00
3
false
\n# Complexity\n- \n![image.png](https://assets.leetcode.com/users/images/0ebfc0d1-5b7f-4da6-91de-cf74580c1443_1704859802.2224016.png)\n# Code\n```\nclass Solution {\n public int fillCups(int[] amount) {\n int max=0,sum=0;\n for(int i:amount){\n max=Math.max(max,i);\n sum+=i;\n }\n int x=(sum + 1)/2;\n\n return Math.max(max,x);\n }\n}\n```
1
0
['Java']
0
minimum-amount-of-time-to-fill-cups
Java&JS&TS Solution (JW)
javajsts-solution-jw-by-specter01wj-k8uu
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
specter01wj
NORMAL
2023-11-06T07:07:38.190323+00:00
2023-11-06T07:07:38.190344+00:00
22
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\nJava:\n```\npublic int fillCups(int[] amount) {\n int mx = 0, sum = 0;\n for(int a : amount) {\n mx = Math.max(a, mx);\n sum += a;\n }\n return Math.max(mx, (sum + 1) / 2);\n}\n```\nJavascript:\n```\nvar fillCups = function(amount) {\n let max = 0, sum = 0;\n for (let i of amount) {\n max = Math.max(i, max);\n sum += i;\n }\n \n return Math.max(max, Math.floor((sum + 1) / 2));\n};\n```\nTypescript:\n```\nfunction fillCups(amount: number[]): number {\n let max = 0, sum = 0;\n for (let i of amount) {\n max = Math.max(i, max);\n sum += i;\n }\n \n return Math.max(max, Math.floor((sum + 1) / 2));\n};\n```
1
0
['Java', 'TypeScript', 'JavaScript']
0
minimum-amount-of-time-to-fill-cups
100% Beat runtime easy soln
100-beat-runtime-easy-soln-by-vishal_beg-l27n
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
VISHAL_BEGANI
NORMAL
2023-04-27T08:03:02.244417+00:00
2023-04-27T08:03:02.244455+00:00
160
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) \n {\n priority_queue<int>q;\n for(int a:amount)\n q.push(a);\n bool flag=true;\n int sum=0;\n while(flag)\n {\n int a=q.top();\n q.pop();\n int b=q.top();\n q.pop();\n if(b==0)\n {\n sum=sum+a;\n flag=false;\n }\n else\n {\n sum++;\n a--;b--;\n q.push(a);\n q.push(b);\n }\n }\n return sum;\n }\n};\n```
1
0
['C++']
0
minimum-amount-of-time-to-fill-cups
Java || Easy Solution || 0sec
java-easy-solution-0sec-by-sadanandsidhu-cb5o
Intuition\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
sadanandsidhu
NORMAL
2023-03-25T03:53:42.658357+00:00
2023-03-25T03:53:42.658401+00:00
10
false
# Intuition\n![upvote.png](https://assets.leetcode.com/users/images/70f44ef1-ed38-4e6d-9cc7-b1ec989cb21c_1679716414.3409834.png)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int fillCups(int[] amount) {\n int seconds = 0;\n Arrays.sort(amount);//First sorting the array.\n int highestNum = amount.length-1;\n int secondHighestNum = amount.length-2;\n //Now taking the two biggest numbers of the array which will be at the last and the second last index as the array is sorted.\n while (amount[highestNum]>0 && amount[secondHighestNum]>0){\n //If both these numbers are greater than 0 then we can fill two cups in one second and then decreasing their values.\n amount[highestNum]--;\n amount[secondHighestNum]--;\n seconds++;//This is one ans\n Arrays.sort(amount);//Now, again sorting using the inbuilt sort of java class so that the biggest two numbers are at the last two index of the array\n }\n\n //The above loop will break when either of the two places becomes 0\n //If the number at last and secon last index were equal, then both of them will become zero\n //Or if it is not the case, then only one type of water is present in the dispenser\n while (amount[highestNum]>0){\n //So, decreasing it one by one till it becomes zero\n amount[highestNum]--;\n seconds++;\n }\n return seconds;//Hence, we have found our answer\n }\n}\n```
1
0
['Java']
0
minimum-amount-of-time-to-fill-cups
c++ || easy to understand || using priority_queue || 2ms || clean code
c-easy-to-understand-using-priority_queu-rdxd
\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n priority_queue<int> p;\n for(auto it: amount) p.push(it);\n int tota
yashyadav12723
NORMAL
2023-02-24T14:05:33.891631+00:00
2023-02-24T14:05:33.891662+00:00
277
false
```\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n priority_queue<int> p;\n for(auto it: amount) p.push(it);\n int total=0;\n int a,b;\n while(1){\n a=p.top(); p.pop();\n b=p.top(); p.pop();\n if(a==0 || b==0){\n total+=(a+b);\n return total;\n }\n else{\n total++;\n a-- , b--;\n p.push(a);\n p.push(b);\n }\n }\n return 0;\n }\n};\n```
1
0
['C', 'Heap (Priority Queue)']
0
minimum-amount-of-time-to-fill-cups
Java solution with explanation
java-solution-with-explanation-by-saha_s-uzj3
Intuition\nJust keep filling the least and most required cups together\n\n# Approach\nSort the array. Keep removing the smallest value and the largest value by
Saha_Souvik
NORMAL
2023-01-24T13:44:55.089281+00:00
2023-01-24T13:44:55.089310+00:00
419
false
# Intuition\nJust keep filling the least and most required cups together\n\n# Approach\nSort the array. Keep removing the smallest value and the largest value by 1, until the smallest one is zero, then increase the answer by the left out max value\n\n# Complexity\n- Time complexity:\nO(smallest value)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int fillCups(int[] amount) {\n Arrays.sort(amount);\n int ans = 0;\n int lo=0, hi=2;\n if(amount[0] == 0) lo++;\n if(lo==1 && amount[1]==0) return amount[2];\n\n else if(lo==1){\n ans += amount[hi];\n return ans;\n }\n while(amount[lo] != 0){\n ans++;\n amount[lo]--;\n amount[hi]--;\n if(amount[hi-1] > amount[hi]){\n int temp = amount[hi-1];\n amount[hi-1] = amount[hi];\n amount[hi] = temp;\n }\n }\n\n ans += amount[2];\n return ans;\n }\n}\n```
1
0
['Java']
1
minimum-amount-of-time-to-fill-cups
C
c-by-tinachien-shoq
\nint cmp(const void* a, const void* b){\n return *(int*)b - *(int*)a ;\n}\nint fillCups(int* amount, int amountSize){\n qsort(amount, amountSize, sizeof(
TinaChien
NORMAL
2023-01-17T10:37:15.486211+00:00
2023-01-17T10:37:15.486258+00:00
193
false
```\nint cmp(const void* a, const void* b){\n return *(int*)b - *(int*)a ;\n}\nint fillCups(int* amount, int amountSize){\n qsort(amount, amountSize, sizeof(int), cmp) ;\n if(amount[0] >= (amount[1] + amount[2]))\n return amount[0] ;\n else{\n return amount[0] + (amount[1] + amount[2] - amount[0] + 1) / 2 ;\n } \n}\n```
1
0
[]
0
minimum-amount-of-time-to-fill-cups
C++ | using max and sort greater
c-using-max-and-sort-greater-by-ntxess-wfvv
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ntxess
NORMAL
2023-01-17T04:53:32.094652+00:00
2023-01-17T04:53:32.094694+00:00
36
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n int ans = 0;\n while(amount.size() > 2) {\n sort(amount.begin(), amount.end(), greater<int>());\n if(amount[2] == 0) {\n amount.pop_back();\n } else {\n amount[0]--;\n amount[2]--;\n ans++;\n }\n }\n return ans + max(amount[0], amount[1]);\n }\n};\n```
1
0
['C++']
0
minimum-amount-of-time-to-fill-cups
[Accepted] Swift
accepted-swift-by-vasilisiniak-yzcw
\nclass Solution {\n func fillCups(_ amount: [Int]) -> Int {\n \n var am = amount\n var res = 0\n \n while am.reduce(0, +)
vasilisiniak
NORMAL
2023-01-11T09:42:06.722175+00:00
2023-01-11T09:42:06.722207+00:00
24
false
```\nclass Solution {\n func fillCups(_ amount: [Int]) -> Int {\n \n var am = amount\n var res = 0\n \n while am.reduce(0, +) > 0 {\n am = am.sorted()\n am[1] = max(0, am[1] - 1)\n am[2] = max(0, am[2] - 1)\n res += 1\n }\n \n return res\n }\n}\n```
1
0
['Swift']
0
minimum-amount-of-time-to-fill-cups
C++ | Easy Solution | Priority queue
c-easy-solution-priority-queue-by-sushil-xra2
\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n priority_queue<int>pq;\n \n for(int i=0;i<amount.size();i++){\n
sushilkr0147
NORMAL
2022-12-09T13:34:16.610789+00:00
2022-12-09T13:34:16.610828+00:00
699
false
```\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n priority_queue<int>pq;\n \n for(int i=0;i<amount.size();i++){\n pq.push(amount[i]);\n }\n int ans=0;\n while(pq.top()!=0){\n\n int a=pq.top();\n pq.pop();\n int b=pq.top();\n pq.pop();\n a--;\n b--;\n pq.push(a);\n pq.push(b);\n ans++;\n \n }\n return ans;\n }\n};\n```
1
0
['C']
0
minimum-amount-of-time-to-fill-cups
c++ || Heap || easy
c-heap-easy-by-lord_yuvi-x52w
\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n int n=amount.size();\n int cnt=0;\n priority_queue<int>pq;\n
Lord_yuvi
NORMAL
2022-11-07T06:40:05.555733+00:00
2022-11-07T06:40:05.555771+00:00
788
false
```\nclass Solution {\npublic:\n int fillCups(vector<int>& amount) {\n int n=amount.size();\n int cnt=0;\n priority_queue<int>pq;\n if(amount[0]!=0)\n pq.push(amount[0]);\n if(amount[1]!=0)\n pq.push(amount[1]);\n if(amount[2]!=0)\n pq.push(amount[2]);\n while(pq.size()>0)\n {\n cnt++;\n cout<<cnt<<endl;\n int a=0,b=0;\n if(pq.size()!=0)\n { a=pq.top();\n pq.pop(); a=a-1;}\n if(pq.size()!=0)\n { b=pq.top();\n pq.pop(); b=b-1;}\n if(a>0)\n {\n pq.push(a);\n \n }\n if(b>0)\n {\n pq.push(b);\n }\n }\n return cnt;\n }\n};\n```
1
1
['C', 'Heap (Priority Queue)']
0
minimum-amount-of-time-to-fill-cups
JAVA most easiest solution for beginners
java-most-easiest-solution-for-beginners-ct2c
\'\'\'\nclass Solution {\n public int fillCups(int[] amount) {\n int count=0;\n while(amount[0]>0||amount[1]>0||amount[2]>0)\n {\n
12113099
NORMAL
2022-09-05T05:52:59.040334+00:00
2022-09-05T05:52:59.040373+00:00
69
false
\'\'\'\nclass Solution {\n public int fillCups(int[] amount) {\n int count=0;\n while(amount[0]>0||amount[1]>0||amount[2]>0)\n {\n if(amount[0]==0&&amount[1]==0)\n return count+amount[2];\n \n else if(amount[0]==0&&amount[2]==0)\n return count+amount[1];\n \n else if(amount[1]==0&&amount[2]==0)\n return count+amount[0];\n else if(amount[0]==0)\n {\n amount[1]-=1;\n amount[2]-=1;\n count++;\n }\n else if(amount[1]==0)\n {\n \n amount[0]-=1;\n amount[2]-=1;\n count++;\n }\n else if(amount[2]==0)\n {\n \n amount[1]-=1;\n amount[0]-=1;\n count++;\n }\n else \n {\n int i=maximum(amount);\n int j=max2(amount);\n amount[i]-=1;\n amount[j]-=1;\n count++;\n }\n }\n return count;\n }\n public int maximum(int[]array)\n {\n if(array[0]>=array[1] && array[0]>=array[2])\n return 0;\n\n else if(array[1]>=array[0] && array[1]>=array[2])\n return 1;\n\n else if(array[2]>=array[0] && array[2]>=array[1])\n return 2;\n return 0;\n\n }\n public int max2(int[]array)\n {\n if(array[0]>array[1] && array[0]>array[2])\n {\n if(array[1]>array[2])\n return 1;\n else return 2;\n }\n else if(array[1]>array[0] && array[1]>array[2])\n {\n if(array[0]>array[2])\n return 0;\n else return 2;\n }\n else \n {\n if(array[0]>array[1])\n return 0;\n else return 1;\n }\n }\n}\n\'\'\'
1
0
[]
0
find-the-value-of-the-partition
Python 3 || 2 lines, w/ explanation || T/S: 93% / 98%
python-3-2-lines-w-explanation-ts-93-98-1fltl
Here\'s the plan:\n\n- We sort the array to find the minimum difference between adjacent elements.\n\n- We calculate the minimum difference between adjacent ele
Spaulding_
NORMAL
2023-06-18T06:22:23.526197+00:00
2024-06-23T00:27:03.966924+00:00
785
false
Here\'s the plan:\n\n- We sort the array to find the minimum difference between adjacent elements.\n\n- We calculate the minimum difference between adjacent elements in the sorted nums array using a generator expression.\n- We find the least difference, which represents the minimum absolute difference between the maximum element of `nums1 `and the minimum element of `nums2`.\n- We return the minimum difference aas the answer to the problem. \n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n \n nums.sort()\n\n return min(nums[i] - nums[i-1] for i in range(1,len(nums)))\n```\n[https://leetcode.com/problems/find-the-value-of-the-partition/submissions/1297175458/](https://leetcode.com/problems/find-the-value-of-the-partition/submissions/1297175458/)\n\nI could be wrong, but I think that time complexity is *O*(*N* log *N*) and space complexity is *O*(1), in which *N* ~`len(nums)`.
15
0
['Python3']
2
find-the-value-of-the-partition
[Java/C++/Python] Sort
javacpython-sort-by-lee215-w2d1
Explanation\nSort the input A\nThe result must be the minimum difference of 2 adjacent elements.\n\nWe put A[0] ... A[i - 1] in array nums1\nWe put A[i] ... A[n
lee215
NORMAL
2023-06-18T04:01:58.730354+00:00
2023-06-18T04:01:58.730378+00:00
1,629
false
# **Explanation**\nSort the input `A`\nThe result must be the minimum difference of 2 adjacent elements.\n\nWe put `A[0] ... A[i - 1]` in array `nums1`\nWe put `A[i] ... A[n - 1]` in array `nums2`\n\nso `|max(nums1) - min(nums2)| = A[i] - A[i - 1]`,\nonly need to find out `min(A[i] - A[i - 1])`\n<br>\n\n# **Complexity**\nTime `O(sort)`\nSpace `O(sort)`\n<br>\n\n**Java**\n```java\n public int findValueOfPartition(int[] A) {\n Arrays.sort(A);\n int res = A[1] - A[0], n = A.length;\n for (int i = 2; i < n; i++)\n res = Math.min(res, A[i] - A[i - 1]);\n return res;\n }\n```\n\n**C++**\n```cpp\n int findValueOfPartition(vector<int>& A) {\n sort(A.begin(), A.end());\n int res = A[1] - A[0], n = A.size();\n for (int i = 2; i < n; i++)\n res = min(res, A[i] - A[i - 1]);\n return res;\n }\n```\n\n**Python**\n```py\n def findValueOfPartition(self, A: List[int]) -> int:\n A.sort()\n return min(A[i] - A[i - 1] for i in range(1, len(A)))\n```\n
12
0
['C', 'Python', 'Java']
1
find-the-value-of-the-partition
Very Simple and Beginner Friendly with Explanation | C++
very-simple-and-beginner-friendly-with-e-11d7
Intuition\n Describe your first thoughts on how to solve this problem. \nWe have to partition nums in such a max(nums1) - min(nums2) id minimum.\nWe know that i
Chanpreet3000
NORMAL
2023-06-18T04:02:39.393034+00:00
2023-06-18T04:02:39.393061+00:00
1,841
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe have to partition `nums` in such a `max(nums1)` - `min(nums2)` id minimum.\nWe know that in an `Sorted Array` the minimum difference between any two pairs `(i, j)` of the array would be minimum difference between `(i, i + 1)`.\nEx: `1,2,3,4,5` diff between `1 & 2` is always less than `1,3` & `1, 4` & `1,5`. Similarly for all adjacent pairs.\n\nAssume a Sorted array `....a,b,c,d.....` if we choose `c` to be minium of `nums2` and `b` to be maximum of `nums1`.\nWe can do this by partitioning `.....ab` & `cd.....`.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPartition at each index and find minimum.\n`....a` & `bcd...` (b - a)\n`....ab` & `cd...` (c - b)\n`....abc` & `d...` (d - c)\n\n# Complexity\n- Time complexity:`O(N * Log(N))`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(1)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n int ans = 1e9;\n sort(nums.begin(), nums.end());\n for(int i = 1; i < nums.size(); i++){\n ans = min(ans, nums[i] - nums[i - 1]);\n }\n return ans;\n }\n};\n```
11
1
['Array', 'Sorting', 'C++']
1
find-the-value-of-the-partition
Min consecutive value || Very simple and easy to understand solution
min-consecutive-value-very-simple-and-ea-gr1y
Up vote if you like the solution\n\n# Approach\n- Sort the array\n- Now we can split the array in to part from the point where the two consicutive elemnts have
kreakEmp
NORMAL
2023-06-18T04:35:05.556679+00:00
2023-06-18T05:53:34.900501+00:00
3,126
false
<b> Up vote if you like the solution</b>\n\n# Approach\n- Sort the array\n- Now we can split the array in to part from the point where the two consicutive elemnts have min difference. So the lower side array have max value and the next element is the min of the next upper side array section.\n- so keep iterating to get the min diff betteen two consicutive elements.\n\n# Code\n```\nint findValueOfPartition(vector<int>& nums) {\n int ans = INT_MAX;\n sort(nums.begin(), nums.end());\n for(int i = 1; i < nums.size(); ++i) ans = min(ans, nums[i] - nums[i-1]);\n return ans;\n}\n```\n<b>Here is an article of my recent interview experience at Amazon, you may like :\nhttps://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted
8
2
['C++']
2
find-the-value-of-the-partition
Adjacent Minimum
adjacent-minimum-by-votrubac-ys9i
Python 3\npython\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n return min(b - a for a, b in zip(nu
votrubac
NORMAL
2023-06-18T04:09:17.854866+00:00
2023-06-18T04:09:17.854898+00:00
968
false
**Python 3**\n```python\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n return min(b - a for a, b in zip(nums, nums[1:])) \n```
6
1
['Python']
0
find-the-value-of-the-partition
C++🔥||🔥 SORT🔥 ||🔥 and 🔥get adjacent minimum🔥
c-sort-and-get-adjacent-minimum-by-ganes-by30
if this code helps you, please upvote solution. \n# Code\n\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begi
ganeshkumawat8740
NORMAL
2023-06-18T04:01:31.919050+00:00
2023-06-18T04:08:30.625737+00:00
1,761
false
# if this code helps you, please upvote solution. \n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n int ans = nums[n-1];\n for(int i = 1; i < n; i++){\n ans = min(ans,nums[i]-nums[i-1]);\n }\n return ans;\n }\n};\n```
6
0
['Sorting', 'C++']
0
find-the-value-of-the-partition
Very Easy | C++ | 3 liner | Beginner Friendly
very-easy-c-3-liner-beginner-friendly-by-skil
\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n // there\'s no problem with the order of the elements\n // so sor
NextThread
NORMAL
2023-06-22T18:07:48.819031+00:00
2023-06-22T18:07:48.819054+00:00
22
false
```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n // there\'s no problem with the order of the elements\n // so sort them first\n sort(nums.begin(), nums.end());\n\t\t\n int res = nums[1]-nums[0];\n\t\t\n for(int i = 1 ; i < nums.size() ; i++) res = min(res, nums[i]-nums[i-1]);\n\t\t\n return res;\n }\n};\n```
4
0
['C']
0
find-the-value-of-the-partition
c++|| o(nlogn)
c-onlogn-by-vijay0109-c4lz
take the minimum between two adjacent after sorting\n\n# Code\n\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n \n
vijay0109
NORMAL
2023-06-18T04:07:19.910590+00:00
2023-06-18T09:12:16.232555+00:00
421
false
take the minimum between two adjacent after sorting\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n \n int ans=INT_MAX;\n for(int i=1;i<nums.size();i++)\n {\n ans=min(ans,nums[i]-nums[i-1]);\n }\n return ans;\n }\n};\n```
4
0
['Brainteaser', 'Sorting', 'C++']
1
find-the-value-of-the-partition
Java | Sorting | 5 lines | Clean code
java-sorting-5-lines-clean-code-by-judge-6qg4
Complexity\n- Time complexity: O(n*log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(log(n)) used by the sorting algorithm\n Add your
judgementdey
NORMAL
2023-06-18T04:01:36.076666+00:00
2023-06-18T04:03:57.146604+00:00
1,210
false
# Complexity\n- Time complexity: $$O(n*log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(log(n))$$ used by the sorting algorithm\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n int n = nums.length, ans = Integer.MAX_VALUE;\n Arrays.sort(nums);\n \n for (var i=0; i < n-1; i++)\n ans = Math.min(ans, nums[i+1] - nums[i]);\n \n return ans;\n }\n}\n```\nIf you like my solution, please upvote it!
4
0
['Array', 'Sorting', 'Java']
1
find-the-value-of-the-partition
simple and easy Python solution 😍❤️‍🔥
simple-and-easy-python-solution-by-shish-dwmt
\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook
shishirRsiam
NORMAL
2024-08-20T02:08:06.248860+00:00
2024-08-20T02:08:06.248906+00:00
105
false
\n# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python []\nclass Solution(object):\n def findValueOfPartition(self, nums):\n nums.sort()\n\n ans, n = 1e9, len(nums)\n for i in range(n-1):\n ans = min(ans, nums[i+1] - nums[i])\n return ans\n```
3
0
['Array', 'Sorting', 'Python', 'Python3']
4
find-the-value-of-the-partition
simple and easy C++ solution 😍❤️‍🔥
simple-and-easy-c-solution-by-shishirrsi-x0xm
if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) \n {\n so
shishirRsiam
NORMAL
2024-05-27T10:07:00.726657+00:00
2024-05-27T10:07:00.726676+00:00
34
false
# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) \n {\n sort(nums.begin(), nums.end());\n int ans = INT_MAX, n = nums.size();\n for(int i=0;i<n-1;i++)\n ans = min(ans, nums[i+1] - nums[i]);\n return ans;\n }\n};\n```
3
0
['Array', 'Sorting', 'C++']
4
find-the-value-of-the-partition
Simple JS solution O(n log(n))
simple-js-solution-on-logn-by-babec-a8qb
Intuition\nTo get the best result min value of first array should be as close as possible to max value of second array.\n\nSince we are free to adjust the order
babec
NORMAL
2023-06-18T04:08:26.215697+00:00
2023-06-18T04:11:58.865449+00:00
65
false
# Intuition\nTo get the best result min value of first array should be as close as possible to max value of second array.\n\nSince we are free to adjust the order, it\'s safe to assume that any number can be made either max of one array or min of another.\n\nKnowing that, we can check any possible pair.\n\nOut of all possible pairs, the most suitable ones are adjacent numbers of sorterd array.\n\n# Approach\nSort the array\nGet the smallest absolute difference between two adjacent numbers.\n\n# Complexity\n- Time complexity: O(n log(n))\n\n- Space complexity: O(1)\n\n# Code\n```\nvar findValueOfPartition = function(nums) {\n nums.sort((a,b) => a-b)\n let res = Infinity\n \n for (let i=0; i<nums.length-1; i++) {\n const diff = Math.abs(nums[i] - nums[i+1])\n if (diff < res) {\n res = diff\n }\n }\n \n return res\n};\n```
3
0
['Sorting', 'JavaScript']
0
find-the-value-of-the-partition
easy short efficient clean code
easy-short-efficient-clean-code-by-maver-9t23
The partitions are actually subsequences. Lets say we partition arr into :\npa = [x1, x2, .. xm]\npb = [y1, y2, .. yn]\nThe answer is abs(xm-y1);\nThe only choi
maverick09
NORMAL
2023-06-18T04:02:45.758369+00:00
2023-06-18T04:47:34.688420+00:00
241
false
The partitions are actually subsequences. Lets say we partition arr into :\npa = [x1, x2, .. xm]\npb = [y1, y2, .. yn]\nThe answer is abs(xm-y1);\nThe only choices that matter are those of xm and y1 ; rest do not.\nThus we need to check for every possible xi, the closest yj to form (xm, y1) = (xi, yj).\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>&v) {\n int n=v.size();\n sort(begin(v), end(v), greater<int>());\n int ans=INT_MAX;\n for(int i=0;i<n-1;++i){\n ans=min(ans, v[i]-v[i+1]);\n }\n return ans;\n }\n};\n```
3
0
['Greedy', 'C', 'Sorting']
0
find-the-value-of-the-partition
Simple Java O(nlogn) solution using sorting
simple-java-onlogn-solution-using-sortin-1wtf
Code\n\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n \n int minDiff = Integer.MAX_VALUE;\n
shashankbhat
NORMAL
2023-06-18T04:02:23.305202+00:00
2023-06-18T04:02:23.305227+00:00
231
false
# Code\n```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n \n int minDiff = Integer.MAX_VALUE;\n for(int i=nums.length-1; i>0; i--) {\n int diff = nums[i] - nums[i-1];\n minDiff = Math.min(diff, minDiff);\n }\n \n return minDiff;\n }\n}\n```
3
0
['Sorting', 'Java']
0
find-the-value-of-the-partition
Simple || Short || Clean || Java Solution
simple-short-clean-java-solution-by-hima-lczd
\njava []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int min = Integer.MAX_VALUE;\n for(in
HimanshuBhoir
NORMAL
2023-06-18T04:02:13.024824+00:00
2023-06-18T04:03:05.457443+00:00
194
false
\n```java []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int min = Integer.MAX_VALUE;\n for(int i=1; i<nums.length; i++){\n min = Math.min(min,Math.abs(nums[i]-nums[i-1]));\n }\n return min;\n }\n}\n```
3
0
['Java']
0
find-the-value-of-the-partition
Easy and Simple
easy-and-simple-by-anshikagoel11-xulq
IntuitionApproachComplexity Time complexity: Space complexity: Code
AnshikaGoel11
NORMAL
2025-02-01T13:51:56.862573+00:00
2025-02-01T13:51:56.862573+00:00
71
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(nums.begin(),nums.end()); int mini = INT_MAX; for(int i=0;i<nums.size()-1;i++){ mini = min(mini , abs(nums[i]-nums[i+1])); } return mini; } }; ```
2
0
['Array', 'Sorting', 'C++']
1
find-the-value-of-the-partition
[JAVA] easy solution explained
java-easy-solution-explained-by-jugantar-6ej5
Intuition\n Describe your first thoughts on how to solve this problem. \nThe solution must be the minimum difference between two adjacent elements after sortin
Jugantar2020
NORMAL
2023-07-18T17:29:00.534089+00:00
2023-07-18T17:29:00.534107+00:00
27
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe solution must be the minimum difference between two adjacent elements after sorting the array `nums`\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAfter sorting the array `nums` check for the minimum difference between adjacent elements and return the minimum difference\n\n# Complexity\n- Time complexity: O(nlogn) *for sorting*\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(logn) *used by sorting algorithm*\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int res = nums[1] - nums[0];\n for(int i = 2; i < nums.length; i ++) \n res = Math.min(res, nums[i] - nums[i - 1]);\n return res; \n }\n}\n```\n# PLEASE UPVOTE IF IT WAS HELPFULL
2
0
['Array', 'Sorting', 'Java']
0
find-the-value-of-the-partition
Easy Python Solution
easy-python-solution-by-vistrit-99zd
Code\n\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n m=nums[-1]\n for i in range(len(nums)-
vistrit
NORMAL
2023-06-27T18:23:05.786999+00:00
2023-06-27T18:23:05.787025+00:00
242
false
# Code\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n m=nums[-1]\n for i in range(len(nums)-1):\n m=min(m, abs(nums[i]-nums[i+1]))\n return m\n```
2
0
['Python3']
0
find-the-value-of-the-partition
Python Elegant & Short | One-Line | Pairwise + Sort
python-elegant-short-one-line-pairwise-s-ycob
Complexity\n- Time complexity: O(n * \log_2 {n})\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) ->
Kyrylo-Ktl
NORMAL
2023-06-19T11:51:16.751783+00:00
2023-06-19T11:51:16.751810+00:00
247
false
# Complexity\n- Time complexity: $$O(n * \\log_2 {n})$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n return min(y - x for x, y in pairwise(sorted(nums)))\n```
2
0
['Sorting', 'Python', 'Python3']
1
find-the-value-of-the-partition
easy python solution
easy-python-solution-by-maheshwer_3-nq4q
\n\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n res=1000000008\n for i in range(len(nums))
maheshwer_3
NORMAL
2023-06-19T06:42:03.561997+00:00
2023-06-19T06:42:03.562015+00:00
28
false
\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n res=1000000008\n for i in range(len(nums)):\n if res>nums[i]-nums[i-1]:\n res=abs(nums[i]-nums[i-1])\n return res\n```
2
0
['Python3']
0
find-the-value-of-the-partition
[Java] Sort
java-sort-by-xiangcan-kyz9
\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int res = nums[1] - nums[0];\n for (int i = 2;
xiangcan
NORMAL
2023-06-18T15:21:58.655569+00:00
2023-06-18T15:21:58.655586+00:00
73
false
```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int res = nums[1] - nums[0];\n for (int i = 2; i < nums.length; i++)\n res = Math.min(res, nums[i] - nums[i - 1]);\n return res;\n }\n}\n```
2
0
['Java']
0
find-the-value-of-the-partition
C++|| SORT|| EASY || WITH EXPLANATION
c-sort-easy-with-explanation-by-neha0312-91wd
Since we have to minimise the difference between max element of first array and min element of second array we have to find two consecutive element with least d
neha0312
NORMAL
2023-06-18T10:33:19.639037+00:00
2023-06-18T10:33:19.639054+00:00
161
false
Since we have to minimise the difference between max element of first array and min element of second array we have to find two consecutive element with least difference. when we find these two element it will always be possible to make nums1 and nums2 as the elements less than max element can be placed in nums1 and element greater than min of nums2 can be placed in nums2.\nSo sort array and find min difference.\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n int n= nums.size();\n sort(nums.begin(),nums.end());\n int mini= INT_MAX;\n for(int i=1; i<n; i++){\n mini= min(nums[i]-nums[i-1],mini);\n }\n return mini;\n \n }\n};
2
0
['C', 'Sorting']
0
find-the-value-of-the-partition
Easy O(n) Solution //Begginer Friendly;
easy-on-solution-begginer-friendly-by-vi-wt9f
Intuition\nJust use the max occuring diff and check if any less is present or not.\n\n# Approach\nSort the array and take the max difference and check while ite
vineet_kash
NORMAL
2023-06-18T08:26:57.526672+00:00
2023-06-18T08:26:57.526690+00:00
356
false
# Intuition\nJust use the max occuring diff and check if any less is present or not.\n\n# Approach\nSort the array and take the max difference and check while iterating over the loop.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int dif=nums[n-1]-nums[n-2];\n for(int i=1;i<n;i++){\n dif=min(dif,nums[i]-nums[i-1]);\n }\n return dif;\n }\n};\n```
2
0
['C++']
3
find-the-value-of-the-partition
☕Java☕ ✅✅simple solution🔥🔥;
java-simple-solution-by-saran456-qhri
\n\n# Approach\n Describe your approach to solving the problem. \n\n\n# Code\n\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n int
Saran456
NORMAL
2023-06-18T04:51:20.878248+00:00
2023-06-18T04:51:20.878265+00:00
15
false
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Code\n```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n int min = Integer.MAX_VALUE;\n Arrays.sort(nums);\n for(int i = 0; i < nums.length-1; i++){\n if(nums[i+1] - nums[i] < min) min = nums[i+1] - nums[i];\n }\n return min;\n }\n}\n```
2
0
['Java']
0
find-the-value-of-the-partition
✅Easy and simple solution ✅clean code
easy-and-simple-solution-clean-code-by-a-kp57
Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\nFoll
ayushluthra62
NORMAL
2024-07-25T21:12:59.667064+00:00
2024-07-25T21:12:59.667084+00:00
11
false
***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**\n\n# Approach\nwe need to find minimum difference between partition of 1 array into two parts such that we can only pic max element from left and min element from right \nor any two element \nfor example \nin this now we have to divide array such a way we got low differecne\n1245\ndiff 1 2 = 1 {1} , {2,4,5}\ndiff 2 4 = 2 {1, 2} , {4,5};\ndiff 4 5 = 1 {1,2,4} {5}\nso minimum difference is 1\n\nso you can easily from the example if we sort the array we will get our answer as left part will always contain maximum element and right part will always have minimum as possible \n \n\n# Complexity\n- Time complexity:\nO(NLogN)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int mini =INT_MAX;\n for(int i=0;i<nums.size()-1;i++) mini =min(mini,nums[i+1]-nums[i]);\n return mini;\n }\n};\n```\n***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**
1
0
['C++']
0
find-the-value-of-the-partition
Adjacent Minimum
adjacent-minimum-by-dhoni_0069-riam
Approach\nSort the array and return the minimum of difference of adjancents.\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(1)\n\n# Cod
dhoni_0069
NORMAL
2023-06-19T15:27:50.100757+00:00
2023-06-19T15:27:50.100792+00:00
12
false
# Approach\nSort the array and return the minimum of difference of adjancents.\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n int ans = 1e9;\n int n = nums.size();\n sort(begin(nums),end(nums));\n for(int i=0;i<n-1;i++){\n int val = nums[i+1] - nums[i];\n ans = min(ans,val);\n }\n \n return ans;\n }\n};\n```
1
0
['Greedy', 'Sorting', 'C++']
0
find-the-value-of-the-partition
C++ solution
c-solution-by-pradeepkumawat-c68z
\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int ans=INT_MAX;\n for(i
pradeepkumawat
NORMAL
2023-06-19T10:02:25.945732+00:00
2023-06-19T10:02:25.945756+00:00
15
false
```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int ans=INT_MAX;\n for(int i=1;i<nums.size();i++){\n ans= min(ans, nums[i]-nums[i-1]);\n}\n return ans;\n }\n};\n```
1
0
['C', 'Sorting']
0
find-the-value-of-the-partition
Python || Sorting || Easy Solution
python-sorting-easy-solution-by-sumedh07-ud8u
Code\n\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n minVal=max(nums)\n for i in range(len(
Sumedh0706
NORMAL
2023-06-19T05:32:53.622270+00:00
2023-06-19T05:32:53.622286+00:00
42
false
# Code\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n minVal=max(nums)\n for i in range(len(nums)-1):\n minVal=min(minVal,abs(nums[i]-nums[i+1]))\n return minVal\n```\n\n***Please Upvote***
1
0
['Python3']
0
find-the-value-of-the-partition
Easy c++ Solution
easy-c-solution-by-lakshita17-s9xo
\n\n# Complexity\n- Time complexity: O(n logn)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& num
Lakshita17
NORMAL
2023-06-18T18:44:16.423708+00:00
2023-06-18T18:44:16.423727+00:00
29
false
\n\n# Complexity\n- Time complexity: O(n logn)\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n\n int mini = INT_MAX;\n for(int i=0; i<nums.size()-1; i++){\n mini = min(mini,nums[i+1]-nums[i]);\n }\n\n return mini;\n }\n};\n```
1
0
['Array', 'C++']
0
find-the-value-of-the-partition
Python3 || Easy + Explained || nLogn Solution || 🚀
python3-easy-explained-nlogn-solution-by-1wpp
Intuition\n Describe your first thoughts on how to solve this problem. \n1. The problem tells us that we must make a partition where nums1 and nums2 are non emp
bhills0
NORMAL
2023-06-18T18:05:53.505456+00:00
2023-06-19T01:09:41.160223+00:00
195
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. The problem tells us that we must make a partition where nums1 and nums2 are non empty. \n\n2. If we sort the array, we can make a partition between each pair of adajacent elements where the left element would always be the max of nums1 and the right element in the pair will always be the min of nums2.\n3. In this way, we can check all possible partitions, save the min as we go, and return it once were through every pair\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. initialize a min variable to save the min partition value\n2. sort nums\n3. iterate over nums array from 1->len(nums)\n4. compare each adajacent pair with the calculation given in the problem: abs(nums[i] - nums[i-1])\n5. return the min diff\n\n~If this was helpful please upvote! \n~Thanks for reading :)\n\n# Complexity\n- Time complexity: O(NlogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nWe sort nums and then iterate over nums which is bounded by nlogn for sorting.\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nOur only additional space comes from min_diff\n# Code\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n \n nums.sort()\n min_diff = float(\'inf\')\n \n for i in range(1,len(nums)):\n min_diff = min(min_diff, abs(nums[i] - nums[i-1]))\n \n return min_diff\n```
1
0
['Array', 'Sorting', 'Python3']
1
find-the-value-of-the-partition
🔥🔥 Easy || java || c++ ||
easy-java-c-by-deveshpatel11-x6g4
Java O(N) Solution\n\nclass Solution {\n public static int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int ans=Integer.MAX_VALUE;\n
kanishkpatel1
NORMAL
2023-06-18T13:45:16.151339+00:00
2023-06-18T13:45:16.151367+00:00
119
false
Java O(N) Solution\n```\nclass Solution {\n public static int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int ans=Integer.MAX_VALUE;\n for(int i=1;i<nums.length;i++){\n ans=Math.min(ans,nums[i]-nums[i-1]);\n }\n return ans;\n }\n}\n```\n\nC++ O(N) Solution\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int res=INT_MAX;\n for(int i=1;i<nums.size();i++){\n res=min(res,nums[i]-nums[i-1]);\n }\n return res;\n }\n};\n```
1
0
['C', 'Sorting', 'Java']
0
find-the-value-of-the-partition
Java 100% faster Time Complexity O(n log n) Space Complexity O(1)
java-100-faster-time-complexity-on-log-n-yck7
Intuition\n Describe your first thoughts on how to solve this problem. \nsort and find the minimum difference of two consecutive number.\n\n# Approach\n Describ
AditiyaSharma
NORMAL
2023-06-18T09:46:55.171528+00:00
2023-06-18T09:46:55.171547+00:00
34
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsort and find the minimum difference of two consecutive number.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust Sort the array and then find the minimum difference between two consecutive number of an array.\n\n# Complexity\n- Time complexity: O(n log n) because of sorting of the array.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int m=Integer.MAX_VALUE;\n for(int i=1;i<nums.length;i++)\n m=Math.min(m,Math.abs(nums[i]-nums[i-1]));\n return m;\n }\n}\nfeel free to ask your doubt happy to help....\nIf it help then plz upvote it.....Thanks!!!!\n```
1
0
['Math', 'Greedy', 'Sliding Window', 'Sorting', 'Java']
0
find-the-value-of-the-partition
✅✔️Short and Easy || C++ Solution || 100% Beat ✈️✈️✈️✈️✈️
short-and-easy-c-solution-100-beat-by-aj-zhux
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ajay_1134
NORMAL
2023-06-18T07:38:49.556639+00:00
2023-06-18T07:38:49.556660+00:00
18
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int mn = INT_MAX;\n for(int i=1; i<nums.size(); i++){\n if(nums[i] != nums[i-1]);\n mn = min(mn, nums[i] - nums[i-1]);\n }\n return mn;\n }\n};\n```
1
0
['Sorting', 'C++']
0
find-the-value-of-the-partition
Java Solution
java-solution-by-tirth2742-0tb6
\n\n# Complexity\n- Time complexity: O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n
tirth2742
NORMAL
2023-06-18T05:47:57.803992+00:00
2023-06-18T05:49:14.946828+00:00
57
false
\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int val = Integer.MAX_VALUE;\n for(int i=0 ; i<nums.length-1 ; i++){\n val=Math.min(val,(nums[i+1]-nums[i]));\n }\n return val;\n }\n}\n```
1
0
['Array', 'Greedy', 'Sorting', 'Java']
0
find-the-value-of-the-partition
Easy 4 Line C++ Code
easy-4-line-c-code-by-gaurav_nikam-l6ws
\n\n\n# Approach\nFirst sort the array in accending order and then take the minimum of adjecent elements\n\nThe mininum is the answer\n\n# Complexity\n- Time co
gaurav_nikam
NORMAL
2023-06-18T05:09:48.561055+00:00
2023-06-18T05:09:48.561086+00:00
162
false
\n\n\n# Approach\nFirst sort the array in accending order and then take the minimum of adjecent elements\n\nThe mininum is the answer\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- $$O(nlog(n))$$\n\n- Space complexity:\n- As we are not using any additional space therefore $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int mn = INT_MAX; \n for(int i = 0; i < nums.size()-1; i++)\n {\n mn = min(mn, nums[i+1] - nums[i]);\n }\n return mn;\n }\n};\n```
1
0
['C++']
0
find-the-value-of-the-partition
[Python 3] [One Liner] The "Make You Feel Bad" One Liner Beats 11%
python-3-one-liner-the-make-you-feel-bad-knkj
Thank You to my friend itsjuj for coding this up and letting me use his code for the Post\n\n# Intuition\n Describe your first thoughts on how to solve this pro
Ocram_575
NORMAL
2023-06-18T04:54:23.623646+00:00
2023-06-18T04:57:36.329005+00:00
87
false
**Thank You to my friend itsjuj for coding this up and letting me use his code for the Post**\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI wanted to ruin everyones day, especially that of upcoming python programmers, I want the ones who struggle on this problem to know that I am better than them in all metrics, so how about I do this in one line. I\'m immediately thinking about my skill, and how much better I would be if I do this in one line. In fact, just the thought of writing this in one line, makes me thing about the endless leetcode groupies and 6 fi.. no 7 figure salary I will obtain.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI thought about my massive ego and my hate for readable code. I want my code to be the least simple thing in the file. I do not care at all about my space or time complexity only the fact that it is one line. I then...with all my might and graciousness, write up my solution in one line.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(I dont care)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(I also dont care)\n# Code\nDont Forget to Upvote for More One Liner Content \n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n return min(abs(a-b) for a,b in zip(sorted(nums),sorted(nums)[1:]))\n```
1
1
['Math', 'Dynamic Programming', 'Brainteaser', 'Iterator', 'Python3']
0
find-the-value-of-the-partition
Sorting solution for C# (explanation + complexity)
sorting-solution-for-c-explanation-compl-t843
\n# Approach\n \xA0 The partition will be minimized when the two consecutive elements in the source array have the minimum difference. This division will resul
deleted_user
NORMAL
2023-06-18T04:47:20.412753+00:00
2023-06-19T12:51:44.835870+00:00
41
false
\n# Approach\n \xA0 The partition will be minimized when the two consecutive elements in the source array have the minimum difference. This division will result in the first sub-array having the maximum value, and the following element will be the minimum of the next sub-array.\n\xA0 To apply this approach, we need to sort the source array first and then successively check two elements to find the minimum difference.\n\n# Complexity\n- Time complexity: O(n * log(n))\n- Space complexity: O(1)\n\n# Code\n```\npublic class Solution {\n public int MinPartitionValue(int[] nums)\n {\n System.Array.Sort(nums);\n\n var minValue = int.MaxValue;\n\n for (var i = 1; i < nums.Length; i++)\n {\n minValue = Math.Min(nums[i] - nums[i - 1], minValue);\n }\n\n return minValue;\n }\n}\n```
1
0
['C#']
1
find-the-value-of-the-partition
Python3 Solution
python3-solution-by-motaharozzaman1996-khpl
\n\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n return min(nums[i+1]-nums[i] for i in range(len(n
Motaharozzaman1996
NORMAL
2023-06-18T04:43:23.760002+00:00
2023-06-18T04:43:23.760019+00:00
195
false
\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n return min(nums[i+1]-nums[i] for i in range(len(nums)-1))\n```
1
0
['Python', 'Python3']
0
find-the-value-of-the-partition
5 lines python code | Simple method
5-lines-python-code-simple-method-by-m_m-j1jz
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
m_manish9177
NORMAL
2023-06-18T04:29:44.264788+00:00
2023-06-18T04:29:44.264806+00:00
32
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n n = len(nums)\n nums.sort()\n m=nums[-1]\n for i in range(n-1):\n m = min(nums[i+1]-nums[i],m)\n return m\n```
1
0
['Sorting', 'Python3']
0
find-the-value-of-the-partition
C++ | Adjacent Minimum
c-adjacent-minimum-by-msdarshan-ck6g
Complexity\n- Time complexity: O(nlog(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n
msdarshan
NORMAL
2023-06-18T04:21:18.649630+00:00
2023-06-18T04:21:18.649648+00:00
14
false
# Complexity\n- Time complexity: O(nlog(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n const int n = nums.size();\n int ans = INT_MAX;\n for(int i=1;i<n;++i){\n ans = min(ans,abs(nums[i]-nums[i-1]));\n }\n return ans;\n }\n};\n```
1
0
['Array', 'Greedy', 'Sorting', 'C++']
0
find-the-value-of-the-partition
C++ SIMPLE AND CRISP CODE
c-simple-and-crisp-code-by-arpiii_7474-w288
Code\n\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int ans=INT_MAX;\n
arpiii_7474
NORMAL
2023-06-18T04:11:56.268639+00:00
2023-06-18T04:11:56.268657+00:00
97
false
# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int ans=INT_MAX;\n for(int i=1;i<nums.size();i++){\n ans=min(ans,nums[i]-nums[i-1]);\n }\n return ans;\n }\n};\n```
1
0
['C++']
0
find-the-value-of-the-partition
C++ | | Easy Solution | | Sorting and finding the minimum difference
c-easy-solution-sorting-and-finding-the-6z2dz
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nSorting\n\n# Complexity
aadesh_nikhade
NORMAL
2023-06-18T04:04:02.604913+00:00
2023-06-18T04:04:02.604938+00:00
8
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSorting\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n \n int ans=INT_MAX;\n \n for(int i=0;i<nums.size()-1;i++){\n if(abs(nums[i] - nums[i+1]) < ans ){\n ans=abs(nums[i] - nums[i+1]);\n }\n }\n \n \n return ans;\n }\n};\n```
1
0
['C++']
0
find-the-value-of-the-partition
🚀✅ || Image Representation || Well Explained || JAVA || Sorting
image-representation-well-explained-java-wi24
Intuition\n Describe your first thoughts on how to solve this problem. \nGiven in the question, we need to partition the array into 2 sub arrays such that the a
aeroabrar_31
NORMAL
2023-06-18T04:03:15.936553+00:00
2023-06-18T04:03:44.257231+00:00
217
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGiven in the question, we need to partition the array into 2 sub arrays such that the absolute difference between the max element of first array and min element of second array.\n\nLet\'s think can we solve this by using Brute force approach as per given constraints?\nThe answer is no, absolutely it will be a TLE.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHow about using the sorting property as when the elements are in a particular order then their adjacent difference will be less right.\nIf we choose any inbetween index, the max element will be at leftmost of first array and min element will be at rightmost of second array.\nSo, by finding the adjacency difference between the elements, we can partition the array into two subarrays.\nSteps : \n1. Sort the array.\n2. Find the min adjacency difference between the elements.\n\nBelow example picture will give you the clear understanding.\n\n\n![leetcode_june_18.jpg](https://assets.leetcode.com/users/images/48b495ca-8f09-4198-ba04-09a88104ab5e_1687059909.3547559.jpeg)\n\n\n\n# Complexity\n- Time complexity: $$O(N*logN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Amortized $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![upvote cat.jpeg](https://assets.leetcode.com/users/images/cdfc2b6b-cf9a-4eac-a7f0-e055f86d1237_1687060624.0958745.jpeg)\n\n\n\n# Code\n```java []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n int min=Integer.MAX_VALUE;\n Arrays.sort(nums); //step-1\n \n for(int i=1;i<nums.length;i++)\n {\n if( (nums[i]-nums[i-1])<min ) //step-2\n {\n min=(nums[i]-nums[i-1]);\n }\n \n }\n \n return min;\n \n }\n}\n```\n\n
1
0
['Array', 'Sorting', 'Merge Sort', 'Java']
1
find-the-value-of-the-partition
Sort | Minimum Gap | DIRECT
sort-minimum-gap-direct-by-vinaygottipam-q2zg
Code\n\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n int mini=INT_MAX,n=nums.size();\n sort(nums.begin(),nums.en
vinaygottipamula
NORMAL
2023-06-18T04:02:25.896439+00:00
2023-06-18T04:02:25.896471+00:00
67
false
# Code\n```\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n int mini=INT_MAX,n=nums.size();\n sort(nums.begin(),nums.end());\n for(int i=1;i<n;i++){\n mini=min(mini,abs(nums[i]-nums[i-1]));\n }\n return mini; \n }\n};\n```
1
0
['C++']
0
find-the-value-of-the-partition
Easy solution in java (O(n))
easy-solution-in-java-on-by-kumarakash-mflf
IntuitionJust sort the element of array and check for i and i+1 th element in array. Whicheve is minimum return that.ApproachComplexity Time complexity: O(n) Sp
kumarakash
NORMAL
2025-04-03T11:40:51.601853+00:00
2025-04-03T11:40:51.601853+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Just sort the element of array and check for i and i+1 th element in array. Whicheve is minimum return that. # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> O(n) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> O(1) # Code ```java [] class Solution { public int findValueOfPartition(int[] nums) { Arrays.sort(nums); int min = Integer.MAX_VALUE; for(int i=0;i<nums.length-1;i++) { min=Math.min(min,Math.abs(nums[i]-nums[i+1])); } return min; } } ```
0
0
['Sorting', 'Java']
0
find-the-value-of-the-partition
Beats 100% Runtime Solution Simple Sorting Java
beats-100-runtime-solution-simple-sortin-ku6m
IntuitionApproachComplexity Time complexity: Space complexity: Code
ShDey7986
NORMAL
2025-03-31T14:27:05.378983+00:00
2025-03-31T14:27:05.378983+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int findValueOfPartition(int[] nums) { int n=nums.length; Arrays.sort(nums); int minDiff=Integer.MAX_VALUE; for(int i=0;i<n-1;i++){ minDiff=Math.min((nums[i+1]-nums[i]),minDiff); } return minDiff; } } ```
0
0
['Java']
0
find-the-value-of-the-partition
value of partition || java
value-of-partition-java-by-ayushigupta36-10qj
Complexity Time complexity: O(nlogn) Space complexity: O(1) Code
ayushigupta36881
NORMAL
2025-03-31T10:05:50.896378+00:00
2025-03-31T10:05:50.896378+00:00
2
false
# Complexity - Time complexity: $$O(nlogn)$$ - Space complexity: $$O(1)$$ # Code ```java [] class Solution { public int findValueOfPartition(int[] nums) { Arrays.sort(nums); int minDiff = Integer.MAX_VALUE; for(int i = nums.length - 1; i > 0; i--){ minDiff = Math.min(minDiff, nums[i] - nums[i - 1]); } return minDiff; } } ```
0
0
['Java']
0
find-the-value-of-the-partition
Easy | Beginner friendly | 4 lines code🤯 | Full explanation | Well commented | Line by line exp🔥
easy-beginner-friendly-4-lines-code-full-fm9e
IntuitionApproachComplexity Time complexity: Space complexity: Code
Mohitbeswan
NORMAL
2025-03-31T08:35:58.042250+00:00
2025-03-31T08:35:58.042250+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(nums.begin(),nums.end()); // sort the array int ans = INT_MAX; // set ans to max bcz we have to find min for(int i=1;i<nums.size();i++) ans=min(ans, nums[i]-nums[i-1]); // In a sorted array, the minimum possible partition difference will always be between two consecutive elements. return ans ; } }; ```
0
0
['Greedy', 'Sorting', 'C++']
0
find-the-value-of-the-partition
(Sort --> Adjacent Diff) ==>Optimal Solution
sort-adjacent-diff-optimal-solution-by-r-th5a
ApproachSuppose arr[]={a,c,d,b,e,g,h,i,f,i}; Sort the element then it will look like this. arr[]= {a,b,c,d,e,f,g,h,i,i};CodeComplexity Analysis Time comple
Rahul_Me_Gupta
NORMAL
2025-03-31T08:16:41.609568+00:00
2025-03-31T08:16:41.609568+00:00
4
false
# Approach **Suppose arr[]={a,c,d,b,e,g,h,i,f,i};** **Sort the element then it will look like this.** *arr[]= {a,b,c,d,e,f,g,h,i,i};* ```[] arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (b-a) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (c-b) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (d-c) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (e-d) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (f-e) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (g-f) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (h-g) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (h-i) arr[]= {a,b,c,d,e,f,g,h,i,i}; partition | (i-i) take minimum from this partitions. ``` # Code ```java [] class Solution { private void print(int[] arr){ for(int it:arr){ System.out.print(it+" "); } System.out.println(""); } public int findValueOfPartition(int[] nums){ Arrays.sort(nums); //Uncomment if you want to understand the code better. //print(nums); int mindiff=Integer.MAX_VALUE; int n=nums.length; for(int i=0;i+1<n;i++){ int diff=nums[i+1]-nums[i]; if(diff<mindiff){ mindiff=diff; } } return mindiff; } } ``` # Complexity Analysis - Time complexity: $$O(nlog(n))$$ - Space complexity: $$O(1)$$ # Do Upvote⬆️⬆️⬆️. # Keep Hustling,Keep Coding!!!
0
0
['Array', 'Sorting', 'C++', 'Java']
0
find-the-value-of-the-partition
sort and then check the consecutive diffs
sort-and-then-check-the-consecutive-diff-coog
The key point is that the minimum partition value is simply the smallest difference between any two elements. Checking all possible pairs is nonsense and takes
farhnag
NORMAL
2025-03-23T22:27:00.963008+00:00
2025-03-23T22:27:00.963008+00:00
6
false
The key point is that the minimum partition value is simply the smallest difference between any two elements. Checking all possible pairs is nonsense and takes `O(N^2)`, if we first sort it, then we need to only compare consecutive diffs, reducing the complexity to: `O(NlogN)` - because of sort!, the single pass takes `O(n)` ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(nums.begin(), nums.end()); int res = INT32_MAX; for (int i = 1; i < nums.size(); i++) res = min(res, nums[i] - nums[i - 1]); return res; } }; ```
0
0
['C++']
0
find-the-value-of-the-partition
in O(n logn) by simple sorting only
in-on-logn-by-simple-sorting-only-by-ana-icqs
IntuitionApproachComplexity Time complexity: Space complexity: Code
anant1947x
NORMAL
2025-03-09T18:56:56.479525+00:00
2025-03-09T18:56:56.479525+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(nums.begin(),nums.end()); int x=INT_MAX; if (nums.size()==2) return abs(nums[0]-nums[1]); if (nums.size()==1) return nums[0]; int y=0; for (int i=0; i<nums.size()-1; i++){ y=abs(nums[i]-nums[i+1]); x=min(y,x); } return x; } }; ```
0
0
['C++']
0
find-the-value-of-the-partition
Beats 91% - Simple sorting || CPP || JAVA || PYTHON
beats-91-simple-sorting-cpp-java-python-8ddmq
IntuitionApproachSimple Sort operation and just finding the minimum abs value of diffrence between two number.Complexity Time complexity: O(nlogn) --for sortin
prashantmahawar
NORMAL
2025-02-14T18:30:31.788686+00:00
2025-02-14T18:30:31.788686+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> Simple Sort operation and just finding the minimum abs value of diffrence between two number. # Complexity - Time complexity: $$O(nlogn)$$ --for sorting +$$O(nlogn)$$ --traversal - Space complexity:$$O(1)$$ <!-- Add your space complexity here, e.g. --> # Code ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(begin(nums),end(nums)); int mini=INT_MAX; for(int i=0;i<nums.size()-1;i++){ mini=min(mini,abs(nums[i]-nums[i+1])); } return mini; } }; ``` ```java [] import java.util.Arrays; class Solution { public int findValueOfPartition(int[] nums) { Arrays.sort(nums); int mini = Integer.MAX_VALUE; for (int i = 0; i < nums.length - 1; i++) { mini = Math.min(mini, Math.abs(nums[i] - nums[i + 1])); } return mini; } } ``` ```py [] class Solution: def findValueOfPartition(self, nums): nums.sort() mini = float('inf') for i in range(len(nums) - 1): mini = min(mini, abs(nums[i] - nums[i + 1])) return mini ```
0
0
['Array', 'Sorting', 'C++', 'Java', 'Python3']
0
find-the-value-of-the-partition
Beats 100% of solutions in TC
beats-100-of-solutions-in-tc-by-shashank-eg0t
IntuitionSo we need to minimize max in num1 and min in num2. So the gap should be small. We can find this out by first sorting out the numbers and then finding
shashankkandaala25
NORMAL
2025-02-06T03:37:30.756691+00:00
2025-02-06T03:37:30.756691+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> So we need to minimize max in num1 and min in num2. So the gap should be small. We can find this out by first sorting out the numbers and then finding out gaps in between them, and get minimum gap. The logic here is that based on the gap the larger among two would be the max in num1 and smaller among two will be the min in num2, i.e in that way num1 and num2 construction is possible. Hence, there is no reason for us to actually buld those two arrays # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> O(logn) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> 0(1) # Code ```java [] class Solution { public int findValueOfPartition(int[] nums) { Arrays.sort(nums); int ans = nums[nums.length-1] - nums[nums.length-2]; for(int i = nums.length-2; i >=1; i--) { ans = Math.min(ans,nums[i] - nums[i-1]); } return ans; } } ```
0
0
['Java']
0
find-the-value-of-the-partition
Python3 O(NlogN) Solution with sorting (100.00% Runtime)
python3-onlogn-solution-with-sorting-100-h46j
IntuitionApproach Get two elements of minimum differences by sorting. Once you get those two elements, you can always form partitions based on those two numbers
missingdlls
NORMAL
2025-01-20T15:13:37.540064+00:00
2025-01-20T15:13:37.540064+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> ![image.png](https://assets.leetcode.com/users/images/192f16e2-2940-46f8-a61b-4694b9279af7_1737385870.0794377.png) # Approach <!-- Describe your approach to solving the problem. --> - Get two elements of minimum differences by sorting. - Once you get those two elements, you can always form partitions based on those two numbers. # Complexity - Time complexity: O(NlogN) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code If this solution is similar to yours or helpful, upvote me if you don't mind ```python3 [] class Solution: def findValueOfPartition(self, nums: List[int]) -> int: nums.sort() mn=2*10**9 p=nums[0] for n in nums[1:]: d=n-p if d<mn: mn=d p=n return mn ```
0
0
['Array', 'Math', 'Greedy', 'Brainteaser', 'Sorting', 'Python', 'Python3']
0
find-the-value-of-the-partition
2740. Find the Value of the Partition
2740-find-the-value-of-the-partition-by-9pz3x
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-20T00:17:45.605404+00:00
2025-01-20T00:17:45.605404+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(nums.begin(), nums.end()); int minDiff = INT_MAX; for (int i = 1; i < nums.size(); ++i) { minDiff = min(minDiff, nums[i] - nums[i - 1]); } return minDiff; } }; ```
0
0
['C++']
0
find-the-value-of-the-partition
Easy Solution
easy-solution-by-salvatore_diprima-s8iw
Complexity Time complexity: O(nlog(n)) Space complexity: O(1)Code
salvatore_diprima
NORMAL
2025-01-18T20:05:52.682514+00:00
2025-01-18T20:05:52.682514+00:00
2
false
# Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> $$O(nlog(n))$$ - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> $$O(1)$$ # Code ```python3 [] class Solution: def findValueOfPartition(self, nums: List[int]) -> int: nums.sort() delta = float('inf') for i in range(len(nums)-1): if nums[i+1]-nums[i] < delta: delta = nums[i+1]-nums[i] return delta ```
0
0
['Python3']
0
find-the-value-of-the-partition
Sorting | Simple solution with 100% beaten
sorting-simple-solution-with-100-beaten-3dly1
IntuitionTo minimize the value of the partition ∣max(nums1) − min(nums2)∣, the key is to ensure that the difference between max(nums1) and min(nums2) is as smal
Takaaki_Morofushi
NORMAL
2025-01-15T09:04:07.775247+00:00
2025-01-15T09:04:07.775247+00:00
2
false
# Intuition To minimize the value of the partition `∣max(nums1) − min(nums2)∣`, the key is to ensure that the difference between `max(nums1)` and `min(nums2)` is as small as possible. Sorting the array helps to achieve this because the closest pair of elements in the sorted array forms the boundary between the two partitions. # Approach - Sort the array - Iterate Over Possible Partitions # Complexity - Time complexity: O(nlogn) - Space complexity: O(n) # Code ```cpp [] class Solution { public: int findValueOfPartition(vector<int>& nums) { sort(nums.begin(), nums.end()); int minimum = INT_MAX; for (int i = 1; i < nums.size(); i++){ minimum = min(minimum, nums[i] - nums[i - 1]); } return minimum; } }; ```
0
0
['C++']
0
find-the-value-of-the-partition
Sort - Java O(N*logN) | O(1)
sort-java-onlogn-o1-by-wangcai20-9omb
IntuitionSort then go over every two consecutive values, the left value is the max of left partition, the right value is the min of the right partition.Approach
wangcai20
NORMAL
2024-12-17T00:12:41.223198+00:00
2024-12-17T00:13:44.438904+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort then go over every two consecutive values, the left value is the max of left partition, the right value is the min of the right partition.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N*logN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int res = Integer.MAX_VALUE;\n for (int i = 1; i < nums.length; i++)\n res = Math.min(res, nums[i] - nums[i - 1]);\n return res;\n }\n}\n```
0
0
['Java']
0
find-the-value-of-the-partition
Java Solution || Beats 100%
java-solution-beats-100-by-mudit28-uv69
null
Mudit28
NORMAL
2024-12-11T10:06:36.015599+00:00
2024-12-11T10:06:36.015599+00:00
2
false
# Code\n```java []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int min = Integer.MAX_VALUE;\n for(int i = 1;i<nums.length;i++){\n int dif = nums[i]-nums[i-1];\n if(dif<min){\n min = dif;\n }\n }\n return min;\n }\n}\n```
0
0
['Java']
0
find-the-value-of-the-partition
find the smallest absolute difference between two numbers in the input
find-the-smallest-absolute-difference-be-663m
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
owenwu4
NORMAL
2024-11-27T17:41:45.540799+00:00
2024-11-27T17:41:45.540834+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort() \n res = float(\'inf\')\n for i in range(1, len(nums)):\n res = min(res, abs(nums[i] - nums[i - 1]))\n return res\n \n```
0
0
['Python3']
0
find-the-value-of-the-partition
Super Easy and Short solution C#
super-easy-and-short-solution-c-by-bogda-sxg3
\n# Complexity\n- Time complexity: O(N log N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n
bogdanonline444
NORMAL
2024-11-15T13:32:20.848404+00:00
2024-11-15T13:32:20.848451+00:00
0
false
\n# Complexity\n- Time complexity: O(N log N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```csharp []\npublic class Solution {\n public int FindValueOfPartition(int[] nums) {\n Array.Sort(nums);\n int min = int.MaxValue;\n for(int i = 1; i < nums.Length; i++)\n {\n min = Math.Min(nums[i] - nums[i - 1], min);\n }\n return min;\n }\n}\n```\n![89f26eaf70fa927a79d4793441425859.jpg](https://assets.leetcode.com/users/images/3a039bea-35d8-4f67-90bf-09feae96e736_1731677534.3016534.jpeg)\n
0
0
['C#']
0
find-the-value-of-the-partition
Solution
solution-by-suyash1987-lswi
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Suyash1987
NORMAL
2024-10-31T11:09:31.967034+00:00
2024-10-31T11:09:31.967065+00:00
0
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int ans = nums[nums.size() - 1];\n for (int i = 0; i < nums.size() - 1; i++) {\n ans = min(ans, nums[i + 1] - nums[i]);\n }\n return ans;\n }\n};\n\n```
0
0
['C++']
0
find-the-value-of-the-partition
Sorting and min neighbor difference
sorting-and-min-neighbor-difference-by-s-869e
Approach\nSorting and min neighbor difference\n# Complexity\n\n# Code\nkotlin []\nclass Solution {\n fun findValueOfPartition(nums: IntArray): Int {\n
sav20011962
NORMAL
2024-10-29T11:08:21.237087+00:00
2024-10-29T11:08:31.986964+00:00
0
false
# Approach\nSorting and min neighbor difference\n# Complexity\n![image.png](https://assets.leetcode.com/users/images/2a07cf6f-a82a-43eb-83cc-c0bb7f4291b2_1730199995.549498.png)\n# Code\n```kotlin []\nclass Solution {\n fun findValueOfPartition(nums: IntArray): Int {\n Arrays.sort(nums)\n var min = Int.MAX_VALUE\n for (i in 1 until nums.size) {\n min = Math.min(min,nums[i]-nums[i-1])\n if (min == 0) break\n }\n return min\n }\n}\n```
0
0
['Kotlin']
0
find-the-value-of-the-partition
Java
java-by-alexander_sergeev-4vks
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
alexander_sergeev
NORMAL
2024-10-21T19:05:34.235416+00:00
2024-10-21T19:05:34.235442+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int diff = Integer.MAX_VALUE;\n for (int i = 0; i < nums.length - 1; i++) {\n diff = Math.min(diff, nums[i + 1] - nums[i]);\n }\n return Math.abs(diff);\n }\n}\n```
0
0
['Java']
0
find-the-value-of-the-partition
Java
java-by-alexander_sergeev-dob0
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
alexander_sergeev
NORMAL
2024-10-21T19:03:26.875934+00:00
2024-10-21T19:03:26.875966+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n public int findValueOfPartition(int[] nums) {\n Arrays.sort(nums);\n int diff = Integer.MAX_VALUE;\n for (int i = 0; i < nums.length - 1; i++) {\n diff = Math.min(diff, Math.abs(nums[i] - nums[i + 1]));\n }\n return diff;\n }\n}\n```
0
0
['Java']
0
find-the-value-of-the-partition
Easiest solution ever
easiest-solution-ever-by-codewithdubey-ery9
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
codewithdubey
NORMAL
2024-10-16T12:09:28.533075+00:00
2024-10-16T12:09:28.533110+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int findValueOfPartition(vector<int>& nums) {\n sort(nums.begin(),nums.end(),greater<int>());\n int mini=INT_MAX;\n for(int i=0;i<nums.size()-1;i++)\n {\n mini=min(mini,nums[i]-nums[i+1]);\n }\n return mini;\n \n }\n};\n```
0
0
['C++']
0
find-the-value-of-the-partition
Easiest Python Solution | Beats 100% | 5 line solution
easiest-python-solution-beats-100-5-line-0itj
Intuition\n Describe your first thoughts on how to solve this problem. \nAlthough the problem wants us to partition the list nums into two lists and make it suc
karanshxh
NORMAL
2024-10-14T23:18:44.678943+00:00
2024-10-14T23:18:44.678977+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAlthough the problem wants us to partition the list nums into two lists and make it such that the difference between the max of one list and the min of the other list is the least possible, we can simplify this problem by realizing all we need is the smallest difference between two values in the list. We could hypothetically partition the list there, although the problem just requires us to return this difference.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe easiest way to find where the smallest difference between two numbers is to sort the list and go through all adjacent values and keep track of the smallest difference.\n1. Create variable to keep track of the smallestDiff (currently max value)\n2. Sort the list (helps calculate the differences between all values)\n3. Iterate through the list (one less than length of nums)\n4. Check the difference between the next value and current value. If its less than the current smallest different, update our tracker for smallest difference\n\nNow, the problem wants us ideally to partition the lists and then calculate the highest value of the first list and the smallest value of the second list and find the difference of the two. But we\'ve already calculated the smallest difference. Our hypothetical partition, which we don\'t need to actually carry out, would be at the place of the smallest difference we calculated.\n \nInstead, we just return the smallest difference.\n\nOur time complexity if O(nlogn) because we sorted the list using the inbuilt sort algorithm from Python. Our space complexity is O(1) because we do not create any additional memory relative to input size growth.\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n- Space complexity:\n$$O(1)$$\n\n# Code\n```python3 []\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n minD = float(\'inf\')\n for i in range(len(nums) - 1):\n if nums[i+1] - nums[i] < minD:\n minD = nums[i+1] - nums[i]\n return minD\n```\n\n![Screenshot 2024-10-14 at 6.17.41\u202FPM.png](https://assets.leetcode.com/users/images/858a3463-5fb9-4f32-ad88-b084958b04b0_1728947879.8979623.png)\n
0
0
['Python3']
0
find-the-value-of-the-partition
Python Solution
python-solution-by-deepanjal-uoz5
\n# Code\npython3 []\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n res = float(\'inf\')\n\n
Deepanjal
NORMAL
2024-10-10T19:15:29.363787+00:00
2024-10-10T19:15:29.363819+00:00
0
false
\n# Code\n```python3 []\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n res = float(\'inf\')\n\n for i in range(1, len(nums)):\n res = min(res, nums[i] - nums[i - 1])\n\n return res\n```
0
0
['Python3']
0
find-the-value-of-the-partition
Simple sorting N*log(N), ==> [C]
simple-sorting-nlogn-c-by-user0490hi-kh8a
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
user0490hI
NORMAL
2024-10-09T16:06:26.155843+00:00
2024-10-09T16:06:26.155876+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```c []\nint com_pare(const void *a , const void *b)\n{\n return *(int *)a - *(int *)b;\n}\n\nint findValueOfPartition(int* nums, int numsSize){\n\nqsort(nums, numsSize , sizeof(int ) , com_pare);\n\nint min = 1100000000;\n\nfor(int i = 0 ; i < numsSize-1 ; i++)\n{\n if(abs(nums[i]-nums[i+1]) < min)\n {\n min = abs(nums[i]-nums[i+1]);\n }\n}\n\nreturn min; \n}\n```
0
0
['C']
0
find-the-value-of-the-partition
Python O(nlogn) Time, O(n) Spacea
python-onlogn-time-on-spacea-by-johnmull-xi8i
Complexity\n- Time complexity: O(nlogn) \n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\
JohnMullan
NORMAL
2024-10-02T12:13:09.266826+00:00
2024-10-02T12:13:09.266860+00:00
2
false
# Complexity\n- Time complexity: $$O(nlogn)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python []\nclass Solution(object):\n def findValueOfPartition(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n nums.sort()\n return min( nums[idx]-nums[idx-1] for idx in range(1,len(nums)))\n```
0
0
['Python']
0
find-the-value-of-the-partition
Javascript w/ detailed explanation
javascript-w-detailed-explanation-by-rs-sqozu
Intuition\nConsider an example nums=[23, 13, 8, 16, 5, 11], and suppose we\'re looking at the element 11 to play the role of max(nums1). For now, we don\'t know
RS-Raksa
NORMAL
2024-09-26T02:14:05.869828+00:00
2024-09-26T02:14:05.869850+00:00
2
false
# Intuition\nConsider an example `nums=[23, 13, 8, 16, 5, 11]`, and suppose we\'re looking at the element `11` to play the role of `max(nums1)`. For now, we don\'t know if it is indeed `max(nums1)`, we\'re just assuming for now. \n\nWe can see that to minimize the partition value, `min(nums2)` should be `13`, which would yield a partition value of `2`. We can see this by individually looking at every element apart from `11` and calculating the partition value by hand. However, we can do this more efficiently by looking at the sorted version: `nums=[5, 8, 11, 13, 16, 23]`. Notice that partition value gets larger as the element we choose to play the role of `min(nums2)` is further away from `11` in the sorted array. For example, choosing `5` to be `min(nums2)` would yield a partition value of `6`, and choosing `16` would yield a partition value of `5`. So, to find the minimal partition value given that `11` plays the role of `max(nums1)`, we only need to consider the partition value when `11`\'s adjacent elements (in the sorted array) to play the role as `min(nums2)`. In our example, the `min(nums2)` is to the right adjacent element.\n\nKnowing this, to solve the problem, we can start by sorting the array first. Then, iterate over each element `ei` and consider it to play the role of `max(nums1)`. `min(nums2)` could either be its left adjacent element or right adjacent element. \n`e1,e2,e3, ..., e_(i-1), ei, e_(i+1), ..., en`\n\nIf `min(nums2)` is its right adjacent element, then the array can be partitioned as \n``nums1=[e1,e2,e3,...,ei], \nnums2=[e_(e+1), e_(i+2), ... en]``\n\nIf `min(nums2)` is its left adjacent element, then the array can be partitioned as \n``nums1=[e1,e2,e3,...,e_(i-2),ei], \nnums2=[e_(i-1), e_(e+1), e_(i+2), ... en]``\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findValueOfPartition = function(nums) {\n // Javascript\'s default sorting converts the elements to strings first\n // . For example, if nums was [3, 2, 10], simply calling nums.sort()\n // would give you [10, 2, 3]\n nums.sort((a,b) => a-b);\n\n let minDiff = 1000000000;\n for (let i = 0; i < nums.length; i++) {\n if (i > 0)\n minDiff = Math.min(minDiff, nums[i] - nums[i-1]);\n if (i < nums.length-1)\n minDiff = Math.min(minDiff, nums[i+1] - nums[i]);\n }\n\n return minDiff;\n};\n```
0
0
['JavaScript']
0
find-the-value-of-the-partition
Simple Python Solution
simple-python-solution-by-venkatreddyatt-34sx
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n1. Sort the array in
venkatreddyattala12345
NORMAL
2024-09-21T22:48:36.541960+00:00
2024-09-21T22:48:36.541986+00:00
0
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n1. Sort the array in incrasing order\n2. calculate absolute difference between two numbers\n3. find the min of all the abs values\n\n# Complexity\n- Time complexity: O(N LogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n def findValueOfPartition(self, nums: List[int]) -> int:\n nums.sort()\n result = float(\'inf\')\n for i in range(1,len(nums)):\n result = min(result,nums[i]-nums[i-1])\n \n return result\n\n \n```
0
0
['Python3']
0