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-difference-between-largest-and-smallest-value-in-three-moves
Python Solution | Explained | O(n) time, O(1) space complexity
python-solution-explained-on-time-o1-spa-kc7s
Python Solution | Explained | O(n) time, O(1) space complexity\n\nThe current problem can be easily solved after observing the following:\n\n1. Only the largest
aragorn_
NORMAL
2020-07-31T01:47:51.523275+00:00
2020-07-31T01:58:16.061769+00:00
950
false
**Python Solution | Explained | O(n) time, O(1) space complexity**\n\nThe current problem can be easily solved after observing the following:\n\n1. Only the largest and smallest values found in the array affect the solution, since they cause the greatest differences. For example, if we imagine the sorted array [a, b, c...
6
0
['Python', 'Python3']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Python Complete Explanation (Prefix+suffix =3 elements)
python-complete-explanation-prefixsuffix-50fi
1)Sort the array so we have a window with indicess of [0,n-1] represent [min,max].\n2)Now,changing either the left or right results in the change in the answer
akhil_ak
NORMAL
2020-07-11T17:32:06.662761+00:00
2020-07-12T02:41:50.851293+00:00
553
false
1)Sort the array so we have a window with indicess of [0,n-1] represent [min,max].\n2)Now,changing either the left or right results in the change in the answer .so,changing just means removing a number and adding a new number.We are asked change a total of 3 elements here.\n3) number of elements that can be removed fro...
6
2
['Python', 'Python3']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
C++ | O(nlogn)
c-onlogn-by-di_b-562o
```\nint minDifference(vector& nums) {\n int n = nums.size();\n if(n < 5)\n return 0;\n sort(nums.begin(), nums.end());\n
di_b
NORMAL
2020-07-11T16:04:28.131538+00:00
2020-07-11T16:04:28.131569+00:00
923
false
```\nint minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n < 5)\n return 0;\n sort(nums.begin(), nums.end());\n int res = min({nums[n-4]-nums[0], nums[n-1]-nums[3], nums[n-3]-nums[1], nums[n-2]-nums[2]});\n return res;\n }
6
1
['C']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
✅Simple and Clear Python3 Code✅
simple-and-clear-python3-code-by-moazmar-pr12
\n### Explanation\n\nIntuition\nIf the length of nums is 4 or less, we can make all elements equal by removing up to three elements, resulting in a difference o
moazmar
NORMAL
2024-07-03T20:16:08.558077+00:00
2024-07-03T20:16:08.558099+00:00
4
false
\n### Explanation\n\n**Intuition**\nIf the length of `nums` is 4 or less, we can make all elements equal by removing up to three elements, resulting in a difference of 0.\n\n**Approach**\n1. **Edge Case Handling**: If the length of `nums` is less than or equal to 4, return 0 immediately since we can remove enough eleme...
5
0
['Python3']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
solved with just basics(noobie technique)
solved-with-just-basicsnoobie-technique-dn2uc
Intuition\n Describe your first thoughts on how to solve this problem. \nThe key observation is that by removing three elements from the array, we can only remo
utkarsh_the_co
NORMAL
2024-07-03T17:32:35.536638+00:00
2024-07-03T17:32:35.536668+00:00
79
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key observation is that by removing three elements from the array, we can only remove elements from either the start (smallest elements) or the end (largest elements) of the sorted array. This is because removing elements from anywher...
5
0
['Array', 'Sorting', 'C++']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Easy Way
easy-way-by-layan_am-3yrb
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
layan_am
NORMAL
2024-07-03T14:46:13.966940+00:00
2024-07-03T14:46:13.966959+00:00
459
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)$$ --...
5
0
['Java']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
💠 Ruby one-liner solution
ruby-one-liner-solution-by-lowie-oty8
Intuition\n\nIf the length of the array is $4$ or less, we could easily see that the answer is $0$, because we have enough operations to turn all elements of th
lowie_
NORMAL
2024-07-03T04:18:27.521337+00:00
2024-07-03T04:18:27.521372+00:00
64
false
# Intuition\n\nIf the length of the array is $4$ or less, we could easily see that the answer is $0$, because we have enough operations to turn all elements of the array to the same number.\n\nOtherwise, we can see that to achieve the best answer, we would have to remove some largest, or some smallest numbers, or both,...
5
0
['Ruby']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
simple approach | JAVA
simple-approach-java-by-sukritisinha0717-0opf
\n\n# Approach\n Describe your approach to solving the problem. \n1. Begin the minDifference method which takes an array of integers as input.\n2. Calculate the
sukritisinha0717
NORMAL
2024-07-03T03:21:01.959761+00:00
2024-07-03T03:21:01.959792+00:00
11
false
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Begin the minDifference method which takes an array of integers as input.\n2. Calculate the length of the input array and store it in numsSize.\n3. If the numsSize is less than or equal to 4, return 0 as there are not enough numbers to form a d...
5
0
['Java']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Easy C++ solution using deque
easy-c-solution-using-deque-by-manan14-8e9u
\nclass Solution {\npublic:\n int ans=INT_MAX;\n void solve(deque<int> &dq,int cnt)\n {\n if(cnt==3)\n {\n ans=min(ans,dq.back
Manan14
NORMAL
2022-07-04T10:32:27.620889+00:00
2022-07-04T10:32:27.620931+00:00
337
false
```\nclass Solution {\npublic:\n int ans=INT_MAX;\n void solve(deque<int> &dq,int cnt)\n {\n if(cnt==3)\n {\n ans=min(ans,dq.back()-dq.front());\n return;\n }\n int temp=dq.front();\n dq.pop_front();\n solve(dq,cnt+1);\n dq.push_front(temp)...
5
0
['Queue']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Javascript Easy to understand
javascript-easy-to-understand-by-louisve-zmcv
This solutions is so easy, it doesn\'t need explaining.\n\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minDifference = function(nums) {\n
louisvelz
NORMAL
2021-04-14T13:37:04.633476+00:00
2021-04-14T13:37:04.633508+00:00
679
false
This solutions is so easy, it doesn\'t need explaining.\n\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minDifference = function(nums) {\n if (nums.length <= 4) return 0\n nums.sort((a,b) => a-b)\n \n let i = 0;\n let j = nums.length - 4\n let min = Infinity\n \n while(i <=...
5
0
['Sorting', 'JavaScript']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Short Easy Java
short-easy-java-by-branmazz-pla2
Any array that has 4 numbers, you can change any 3 of the numbers to the remaining so it will always be 0.\nOtherwise, sort the array.\n\nNow the distance betwe
branmazz
NORMAL
2020-12-24T22:36:56.413196+00:00
2020-12-24T22:36:56.413236+00:00
483
false
Any array that has 4 numbers, you can change any 3 of the numbers to the remaining so it will always be 0.\nOtherwise, sort the array.\n\nNow the distance between the min and max is the distance between the first element and the last element.\nCheck all the combos for min distance and return.\n\nCombos are:\nchange the...
5
0
[]
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
[JAVA] Generalized solution for K moves
java-generalized-solution-for-k-moves-by-iv6d
\tpublic int minDifference(int[] nums) {\n \n int k = 3;\n int n = nums.length;\n \n if(n < k + 2)\n return 0;\n
pikapikaa
NORMAL
2020-08-09T17:26:11.318528+00:00
2020-08-09T17:26:23.995097+00:00
366
false
\tpublic int minDifference(int[] nums) {\n \n int k = 3;\n int n = nums.length;\n \n if(n < k + 2)\n return 0;\n \n Arrays.sort(nums);\n \n int min = Integer.MAX_VALUE;\n \n for(int i = 0; i <= k; i++){\n min = Math.min(n...
5
1
['Sorting', 'Java']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Python | Greedy
python-greedy-by-khosiyat-lrdc
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums) <= 4:\n
Khosiyat
NORMAL
2024-07-03T08:28:02.229333+00:00
2024-07-03T08:28:02.229368+00:00
197
false
[see the Successfully Accepted Submission](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/submissions/1308006366/?envType=daily-question&envId=2024-07-03)\n\n# Code\n```\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums) <= 4:...
4
0
['Python3']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Easy Java Code
easy-java-code-by-kundan25-p28h
Intuition\n- The task is to minimize the difference between the maximum and minimum values in an array after removing up to three elements. This can be effectiv
kundan25
NORMAL
2024-07-03T02:53:15.906562+00:00
2024-07-03T02:53:15.906596+00:00
506
false
# Intuition\n- The task is to minimize the difference between the maximum and minimum values in an array after removing up to three elements. This can be effectively approached by considering the smallest and largest elements in a sorted array.\n\n# Approach\n1. If the length of the array is less than or equal to 4, th...
4
0
['Java']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Simple Code C++
simple-code-c-by-agam_swarup-g0yj
Approach and Intuition\nProblem Understanding:\nThe problem asks for the minimum difference between the largest and smallest numbers in the array after making a
agam_swarup
NORMAL
2024-07-03T02:40:35.314889+00:00
2024-07-03T02:40:35.314920+00:00
782
false
# Approach and Intuition\nProblem Understanding:\nThe problem asks for the minimum difference between the largest and smallest numbers in the array after making at most three changes to the array. The changes are essentially removing up to three elements from the array to minimize the difference between the remaining e...
4
0
['Array', 'Greedy', 'Sorting', 'C++']
4
minimum-difference-between-largest-and-smallest-value-in-three-moves
JAVA EASIEST SOLUTION
java-easiest-solution-by-anurag015-ll37
A = [1,5,6,13,14,15,16,17]\nn = 8\n\nCase 1: kill 3 biggest elements\n\nAll three biggest elements can be replaced with 14\n[1,5,6,13,14,15,16,17] -> [1,5,6,13,
anurag015
NORMAL
2022-06-02T05:33:52.674517+00:00
2022-06-02T05:38:25.047441+00:00
329
false
A = [1,5,6,13,14,15,16,17]\nn = 8\n\nCase 1: kill 3 biggest elements\n\nAll three biggest elements can be replaced with 14\n[1,5,6,13,14,15,16,17] -> [1,5,6,13,14,14,14,14] == can be written as A[n-4] - A[0] == (14-1 = 13)\n\nCase 2: kill 2 biggest elements + 1 smallest elements\n\n[1,5,6,13,14,15,16,17] -> [5,5,6,13,1...
4
0
['Sorting', 'Java']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
C++, sort + sliding window, time: O(nlogn), space: O(n + logn)
c-sort-sliding-window-time-onlogn-space-a82bt
\nclass Solution {\npublic:\n \n // sorting + sliding window\n int minDifference(vector<int>& nums) {\n \n if (nums.size() < 5) {\n
hsuedw
NORMAL
2021-10-03T00:44:42.806465+00:00
2022-11-19T10:22:37.225274+00:00
332
false
```\nclass Solution {\npublic:\n \n // sorting + sliding window\n int minDifference(vector<int>& nums) {\n \n if (nums.size() < 5) {\n // If the number of elements is less than or equal to four, \n // we can always adjust the values and let the minimum difference\n ...
4
0
['C++']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
[Python] straightforward solution with 2 heaps
python-straightforward-solution-with-2-h-ud6p
\nfrom heapq import *\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums) <= 4:\n return 0\n \n
jyung616
NORMAL
2021-08-24T21:24:22.592756+00:00
2021-08-25T02:08:56.907497+00:00
585
false
```\nfrom heapq import *\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums) <= 4:\n return 0\n \n maxHeap, minHeap = [], []\n \n for n in nums:\n heappush(maxHeap, -n)\n heappush(minHeap, n)\n if len(maxHea...
4
0
['Heap (Priority Queue)', 'Python', 'Python3']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Simple Python3 with Detailed Explanation
simple-python3-with-detailed-explanation-kz1p
First, we eliminate the simple case of arrays with less than 5 elements. If an array has less than 5 elements, we can change all the elements to match. For exam
gillcmc2342
NORMAL
2021-08-18T20:07:27.176465+00:00
2021-08-18T20:07:27.176522+00:00
277
false
First, we eliminate the simple case of arrays with less than 5 elements. If an array has less than 5 elements, we can change all the elements to match. For example [1,2,3,4] could be changed to [1,1,1,1]. Thus any array with less than 5 elements will always return 0. \n\nNext, we sort the array. With a sorted array, th...
4
0
[]
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
4 lines C++ code, runtime beats: 93.86%
4-lines-c-code-runtime-beats-9386-by-pus-0fzc
\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n<=4) return 0;\n \n sort(nums.b
push_pop_top
NORMAL
2021-08-17T19:27:33.701746+00:00
2021-08-17T19:27:33.701791+00:00
251
false
```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n<=4) return 0;\n \n sort(nums.begin(), nums.end());\n return min({nums[n-4] - nums[0],\n nums[n-3] - nums[1],\n nums[n-2] - nums[2],\n ...
4
0
['Sorting']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Straight forward Java Solution: O(nlogn) time O(1) space
straight-forward-java-solution-onlogn-ti-7lzu
\nclass Solution {\n public int minDifference(int[] nums) {\n int length = nums.length;\n if (length <= 4) {\n return 0;\n }\n Arrays.sort(num
supunwijerathne
NORMAL
2021-08-02T18:47:37.985616+00:00
2021-08-02T18:47:58.517175+00:00
598
false
```\nclass Solution {\n public int minDifference(int[] nums) {\n int length = nums.length;\n if (length <= 4) {\n return 0;\n }\n Arrays.sort(nums);\n int min = Integer.MAX_VALUE;\n min = Math.min(min, nums[length - 1] - nums[3]);\n min = Math.min(min, nums[length - 2] - nums[2]);\n min = ...
4
0
['Java']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
A/C Python 3 solution, easy to understand
ac-python-3-solution-easy-to-understand-lhs1b
\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n nums.sort()\n n = len(nums)\n if (n <= 4 ):\n return 0
willysde
NORMAL
2021-06-27T21:52:14.072587+00:00
2021-06-27T21:52:14.072630+00:00
256
false
```\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n nums.sort()\n n = len(nums)\n if (n <= 4 ):\n return 0\n \n res = nums[-1] - nums[0]\n # kill 3 biggest elements\n res = min(res, nums[-4] - nums[0])\n # kill 2 biggest element...
4
1
[]
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Python Simplest 4 line solution
python-simplest-4-line-solution-by-gsgup-hj22
\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums)<=4:\n return 0\n nums.sort()\n return min
gsgupta11
NORMAL
2020-11-20T18:38:23.100533+00:00
2020-11-20T18:38:23.100571+00:00
380
false
```\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums)<=4:\n return 0\n nums.sort()\n return min(nums[-3]-nums[1],nums[-4]-nums[0],nums[-1]-nums[3],nums[-2]-nums[2])\n```
4
0
[]
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
C# Solution - 2 Lines
c-solution-2-lines-by-leonhard_euler-7ujh
\npublic class Solution \n{\n public int MinDifference(int[] A) \n {\n Array.Sort(A);\n return A.Length <= 4 ? 0 : new int[] { A[^1] - A[3],
Leonhard_Euler
NORMAL
2020-07-11T18:19:15.081217+00:00
2020-07-11T18:25:04.996448+00:00
118
false
```\npublic class Solution \n{\n public int MinDifference(int[] A) \n {\n Array.Sort(A);\n return A.Length <= 4 ? 0 : new int[] { A[^1] - A[3], A[^2] - A[2], A[^3] - A[1], A[^4] - A[0] }.Min();\n }\n}\n```
4
0
[]
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Ugly O(n) or Simple and Sweet O(n *log n) [Java]
ugly-on-or-simple-and-sweet-on-log-n-jav-7pny
Either \na) the array is short (4 or less elements) and you can affort in 3 move to change values, such the array has only 1 value\nb) for a longer array , if y
florin5
NORMAL
2020-07-11T16:01:26.636118+00:00
2020-07-11T16:20:16.043148+00:00
814
false
Either \na) the array is short (4 or less elements) and you can affort in 3 move to change values, such the array has only 1 value\nb) for a longer array , if you have it sorted :** [m-1][m-2] [m-3] [m-4]**[ middle of the array] **[M-4][M-3] [M-2][M-1]** and you will replace some of the lower side of the array m-1 :m ...
4
0
[]
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
99% Running time | SLIDING WINDOW | Easy to understand
99-running-time-sliding-window-easy-to-u-mdv2
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks to minimize the difference between the maximum and minimum values of a
LinhNguyen310
NORMAL
2024-07-04T14:20:35.598347+00:00
2024-07-04T14:20:35.598395+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks to minimize the difference between the maximum and minimum values of an array after making at most three moves. Each move can change any one element to any other value. If we can make at most three moves, the optimal stra...
3
0
['Python']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
TC: O(n) | without STL | Simple Intuition | Recursion
tc-on-without-stl-simple-intuition-recur-xz9z
Intuition\nYou don\'t need to sort entire array.\nJust 4 smallest and 4 biggest elements are required.\n\nThen Apply recursion or iteration to get minDifference
AnishDhomase
NORMAL
2024-07-03T17:16:35.677582+00:00
2024-07-03T17:16:35.677604+00:00
10
false
# Intuition\nYou don\'t need to sort entire array.\nJust 4 smallest and 4 biggest elements are required.\n\nThen Apply recursion or iteration to get minDifference.\n change last 3 elements\n change last 2 elements & first 1 element\n change last 1 element & first 2 element\n change first 3 elements\nchangin...
3
0
['C++']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
General solution for k moves using recursion and dp
general-solution-for-k-moves-using-recur-39kr
Intuition\nWe are Supposed to return difference(minimum) between smallest and largest number. It immediately strikes sorting! After sorting we will be able to g
Aditya_Garg17
NORMAL
2024-07-03T11:52:38.895010+00:00
2024-07-03T11:52:38.895043+00:00
4
false
# Intuition\nWe are Supposed to return difference(minimum) between smallest and largest number. It immediately strikes sorting! After sorting we will be able to get minimum and maximum number without traversing. To lower the difference we have to either increase the minimum number or decrease the maximum element. And a...
3
0
['C++']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Greedy Case Work | Java | C++
greedy-case-work-java-c-by-lazy_potato-j03u
Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/xEPTygm6rdI\n\n# Code\nJava\n\nclass Solution {\n public int minD
Lazy_Potato_
NORMAL
2024-07-03T07:21:33.083727+00:00
2024-07-03T07:21:33.083759+00:00
258
false
# Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/xEPTygm6rdI\n\n# Code\nJava\n```\nclass Solution {\n public int minDifference(int[] nums) {\n int size = nums.length;\n if (size <= 4) {\n return 0;\n }\n PriorityQueue<Integer> minHea...
3
0
['Array', 'Greedy', 'C++', 'Java']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Simple and Beginner-Friendly Solution w/ Sorting and Greedy Method 😊😊
simple-and-beginner-friendly-solution-w-jsnb5
Intuition\nThe problem asks us to find the minimum difference between three numbers from a given list. The key is to realize that we can achieve the smallest di
briancode99
NORMAL
2024-07-03T06:23:24.459424+00:00
2024-07-29T06:24:46.393569+00:00
20
false
# Intuition\nThe problem asks us to find the minimum difference between three numbers from a given list. The key is to realize that we can achieve the smallest difference by focusing on the extremes of the sorted list. If we pick three numbers from the extremes (smallest and largest), we are likely to find the smallest...
3
0
['Array', 'Greedy', 'Sorting', 'JavaScript']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
🥷🏻✔️ Time: O(nlogn), Space: O(1): Go, Javascript, PHP, Typescript 🔥🥷🏻
time-onlogn-space-o1-go-javascript-php-t-exbf
javascript []\nfunction minDifference(nums) {\n if (nums.length <= 4) return 0;\n\n nums.sort((a,b)=>a-b);\n\n let result = Number.MAX_VALUE;\n let
samandareshmamatov
NORMAL
2024-07-03T05:37:02.501781+00:00
2024-07-03T05:37:02.501816+00:00
90
false
```javascript []\nfunction minDifference(nums) {\n if (nums.length <= 4) return 0;\n\n nums.sort((a,b)=>a-b);\n\n let result = Number.MAX_VALUE;\n let n = nums.length;\n let i = 0;\n\n while (i <= 3) {\n result = Math.min(result, nums[n - 4 + i] - nums[i]);\n i++;\n }\n\n return re...
3
0
['Go']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Simple solution along with Follow up for 'K' | Java | C++ | Python
simple-solution-along-with-follow-up-for-3uhy
Intuition\nFirst lets understand for k = 3\nYou can remove in this manner \n1. Remove first three and last zero elements (3,0) --> nums[n-1] - nums[3]\n2. Remov
androiprogrammers
NORMAL
2024-07-03T05:11:29.060993+00:00
2024-07-03T05:11:29.061026+00:00
205
false
# Intuition\nFirst lets understand for k = 3\nYou can remove in this manner \n1. Remove first three and last zero elements (3,0) --> nums[n-1] - nums[3]\n2. Remove first two and last one (2,1) --> nums[n-2] - nums[2]\n3. Remove first one and last two (1,2) --> nums[n-3] - nums[1]\n4. Remove first zero and last three el...
3
0
['Array', 'Two Pointers', 'Greedy', 'Sliding Window', 'Sorting', 'Python', 'C++', 'Java', 'Python3']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Solution for Leetcode#1509
solution-for-leetcode1509-by-samir023041-kmhp
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nStep-01: At first
samir023041
NORMAL
2024-07-03T05:08:09.098433+00:00
2024-07-03T05:08:09.098465+00:00
85
false
![image.png](https://assets.leetcode.com/users/images/f24de383-3c4d-4dfa-81b0-b2dff6fd6acf_1719982788.297745.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep-01: At first, need to sort the arrray\nStep-0...
3
0
['Java']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Beats 96% | Best Solution | Explained💯
beats-96-best-solution-explained-by-sury-3htz
Intuition\n\nThoughts:\n1. Two pointer : Failed when realised you can\'t make more than 3 moves\n2. Recursion : As there were 4 possibilites strinking, but migh
suryanshnevercodes
NORMAL
2024-07-03T03:48:52.655662+00:00
2024-07-03T05:33:33.819341+00:00
346
false
# Intuition\n\nThoughts:\n1. Two pointer : Failed when realised you can\'t make more than 3 moves\n2. Recursion : As there were 4 possibilites strinking, but might give TLE\n3. Sorting and Greedy : THIS WORKS!\n\n# Approach\n\nSo I realised that if we can sort the array we just have to deal with the maximum and minimum...
3
0
['Array', 'Greedy', 'Sorting', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
{C++} Sliding Window, 7 LOC, clean & concise.
c-sliding-window-7-loc-clean-concise-by-1to8e
3 Moves 3rd of July \u2B50\n\n## Intuition\n \nSince It is a greedy problem we can easily solve it through sorting \u2705.\n\n## Approach\n Describe your approa
Ashmit_Mehta
NORMAL
2024-07-03T02:58:59.486238+00:00
2024-07-12T03:18:09.695775+00:00
145
false
> ***3 Moves 3rd of July \u2B50***\n\n## Intuition\n \nSince It is a **greedy problem** we can easily solve it through **sorting** \u2705.\n\n## Approach\n<!-- Describe your approach to solving the problem. -->\n- Firstly handle the edge cases where `n<=4` as the `ans` will always be `0` for them. \n\n- Sort the vector...
3
0
['Array', 'Greedy', 'Sliding Window', 'Sorting', 'C++']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
simple and easy Python solution with explanation 😍❤️‍🔥
simple-and-easy-python-solution-with-exp-op8h
if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution(object):\n def minDifference(self, nums):\n if len(nums) <= 3:\n
shishirRsiam
NORMAL
2024-07-03T01:32:31.374674+00:00
2024-07-03T01:32:31.374705+00:00
590
false
# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution(object):\n def minDifference(self, nums):\n if len(nums) <= 3:\n return 0\n \n nums.sort()\n ans = float(\'inf\')\n \n # frist three remove\n ans = min(ans, nums[-1] -...
3
0
['Array', 'Greedy', 'Sorting', 'Python', 'Python3']
6
minimum-difference-between-largest-and-smallest-value-in-three-moves
[Python3] ✅✅✅ Easy Solution Beats 98.82% 🔥🔥 -> O(1) Space ✅✅✅
python3-easy-solution-beats-9882-o1-spac-8lpp
\n\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.
OsamaAlhasanat
NORMAL
2024-07-03T01:13:32.048826+00:00
2024-07-03T08:25:36.013581+00:00
234
false
# \n![image.png](https://assets.leetcode.com/users/images/300bd5a9-5b36-4725-a474-c51a3282896a_1719969162.9070873.png)\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```\n...
3
0
['Array', 'Greedy', 'Sorting', 'Python', 'Python3']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Minimum Difference After Changing Four Elements
minimum-difference-after-changing-four-e-kpz2
Intuition\n- The goal of this function is to minimize the difference between the largest and smallest elements in the array after changing at most four elements
logusivam
NORMAL
2024-05-09T08:20:33.703852+00:00
2024-05-09T08:20:33.703883+00:00
155
false
# Intuition\n- The goal of this function is to minimize the difference between the largest and smallest elements in the array after changing at most four elements. To do this, the function sorts the array and considers four different cases of which elements to change to minimize the difference.\n\n# Approach\n1. Check ...
3
0
['JavaScript']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Sorting ||| Greedy
sorting-greedy-by-seal541-ijlc
Cover all the cases:\n\n- If\n - The number of elements are $\u2264 4$ then we can simply make largest 3 equal to smallest\n- Else\n - Return the minimum
seal541
NORMAL
2024-01-26T13:02:07.185549+00:00
2024-01-26T13:02:07.185569+00:00
606
false
# Cover all the cases:\n\n- If\n - The number of elements are $\u2264 4$ then we can simply make largest 3 equal to smallest\n- Else\n - Return the minimum of converting smallest 3 to 4th smallest\n - smallest $2$ elements to $3^{rd}$ smallest, and largest to $2^{nd}$ largest\n - smallest $1$ to $2^{nd}$ sm...
3
0
['Array', 'Greedy', 'Sorting', 'C++']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Only 4 cases possible||Beats 91%
only-4-cases-possiblebeats-91-by-vikalp_-ftgb
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
vikalp_07
NORMAL
2023-08-13T14:23:06.645639+00:00
2023-08-13T14:23:06.645660+00:00
531
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)$$ --...
3
0
['C++']
3
minimum-difference-between-largest-and-smallest-value-in-three-moves
5 Lines Code || DP || Easy C++ || Beats 100% ✅✅
5-lines-code-dp-easy-c-beats-100-by-deep-rg5e
Approach\n Describe your approach to solving the problem. \nWe have to remove three numbers from 3 minimum + 3 maximum but which three elements will we choose..
Deepak_5910
NORMAL
2023-08-06T10:41:40.993981+00:00
2023-08-06T16:19:33.605189+00:00
493
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe have to **remove three number**s from **3 minimum + 3 maximum** but which three elements will we **choose**.........\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\nHere I used **dp concept** to select three elements so as to **reduce the differen...
3
0
['Array', 'Dynamic Programming', 'C++']
4
minimum-difference-between-largest-and-smallest-value-in-three-moves
c++ | easy | short
c-easy-short-by-venomhighs7-ppik
\n# Code\n\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n\tint n = nums.size();\n if(n < 5)\n\t\treturn 0;\n\tpartial_sort(nums.begin
venomhighs7
NORMAL
2022-10-11T04:01:24.377648+00:00
2022-10-11T04:01:24.377698+00:00
882
false
\n# Code\n```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n\tint n = nums.size();\n if(n < 5)\n\t\treturn 0;\n\tpartial_sort(nums.begin(), nums.begin() + 4, nums.end());\n partial_sort(nums.rbegin(), nums.rbegin() + 4, nums.rend(), greater<int>());\n\t\n\tint min_diff = INT_MAX;\n\tfor(in...
3
0
['C++']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
C++ || EASY TO UNDERSTAND || Simple Solution || Commented
c-easy-to-understand-simple-solution-com-ikzo
\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(n<=4)\n return 0;\n sort(nums.begi
aarindey
NORMAL
2022-04-17T21:17:43.876532+00:00
2022-04-17T21:17:43.876577+00:00
114
false
```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n=nums.size();\n if(n<=4)\n return 0;\n sort(nums.begin(),nums.end());\n //changing first second and third smallest to next smallest\n int res=nums[n-1]-nums[3];\n //changing last three grea...
3
0
[]
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
✔️[C++] || optimized Simple Code || Explained || TC: O( n ) , SC: O( 1 )
c-optimized-simple-code-explained-tc-o-n-y11i
Please Upvote if it helps\u2B06\uFE0F\nWhy we will go for priority queue not for sorting ?\n--> Because this method only takes O( n ) time complexity and O( 1 )
anant_0059
NORMAL
2022-03-26T11:51:20.213571+00:00
2022-03-26T17:23:25.108755+00:00
213
false
#### *Please Upvote if it helps\u2B06\uFE0F*\n**Why we will go for priority queue not for sorting ?**\n*--> Because this method only takes O( n ) time complexity and O( 1 ) space complexity. But in sorting takes O( n log(n) ) time complexity. \nThe time comlexity for using priority queue is O( n ) because we restricted...
3
0
['C']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Explanation of intuition
explanation-of-intuition-by-abhinav_sing-2oa9
\n\n\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n // If size is 4 then we can make 3 elements e
abhinav_singh22
NORMAL
2022-03-15T08:16:59.098519+00:00
2022-03-15T08:16:59.098552+00:00
144
false
![image](https://assets.leetcode.com/users/images/185ce06a-c2ce-4ffe-8425-02ccce33edbe_1647332123.6982954.png)\n\n```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n // If size is 4 then we can make 3 elements equal to the\n // 4th element and the dif...
3
0
['Greedy']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Python solution in O(n) and O(1) extra memory
python-solution-in-on-and-o1-extra-memor-n0rz
\ndef minDifference(self, nums: List[int]) -> int:\n """\n Runtime O(n) and O(1) extra memory. One pass the collect 4 smallest and largest elements. \n
ozymandiaz147
NORMAL
2022-02-06T17:14:12.313270+00:00
2022-02-06T17:14:12.313308+00:00
239
false
```\ndef minDifference(self, nums: List[int]) -> int:\n """\n Runtime O(n) and O(1) extra memory. One pass the collect 4 smallest and largest elements. \n Then 4 comparisons of endpoints.\n """\n n = len(nums)\n if n <= 4:\n return 0\n min4 = nums[:4]\n max4 = nu...
3
0
[]
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Java | O(n) with explanation using priorityQueues WITHOUT SORTING THE WHOLE ARRAY
java-on-with-explanation-using-priorityq-qgsc
We only need the 4 (3 possible changes plus 1) highest and 4 lowest numbers, as in case we take the 3 lowest numbers and convert them into the 4th (let\'s call
eldavimost
NORMAL
2021-09-29T20:32:42.239314+00:00
2021-09-29T20:32:42.239365+00:00
439
false
We only need the 4 (3 possible changes plus 1) highest and 4 lowest numbers, as in case we take the 3 lowest numbers and convert them into the 4th (let\'s call it the minNumberInRangeIndex), the difference would be the max number(nums[maxNumberInRangeIndex]) minus the nums[minNumberInRangeIndex].\nWe use a sliding wind...
3
1
['Heap (Priority Queue)', 'Java']
2
minimum-difference-between-largest-and-smallest-value-in-three-moves
Simplest C++ Solution | Explanation | Clean Code |
simplest-c-solution-explanation-clean-co-brvx
We had to replace three element in the array to make the amplitude (difference between max and min) minimum.\nWe can choose these elements from anywhere but to
yash2711
NORMAL
2021-09-23T04:36:03.634672+00:00
2021-09-23T04:36:03.634710+00:00
422
false
We had to replace three element in the array to make the amplitude (difference between max and min) minimum.\nWe can choose these elements from anywhere but to minimize the amplitude, we have to choose them from either ends of the array.\nSo we have following possiblities:\n1. 0 start + 3 end\n2. 1 start + 2 end\n3. 2 ...
3
1
['C', 'Sorting']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Sort array and quickly check 3 cases | Time Complexity O(nlogn)
sort-array-and-quickly-check-3-cases-tim-ribs
just sort the array.\n\nnow we have 4 possible combinations of cases:\n1. we can change first 3 elemenet with 4th element of array.\n2. we can change Last 3 el
codeankit
NORMAL
2021-08-28T19:08:02.983900+00:00
2021-08-28T19:08:02.983929+00:00
307
false
just **sort** the array.\n\n**now we have 4 possible combinations of cases**:\n1. we can change first 3 elemenet with 4th element of array.\n2. we can change Last 3 elemenet with 4th last element.\n3. we can change First 2 element with with 3rd element and last element with 2nd last element.\n4. we can change Last 2 e...
3
1
['C', 'Sorting']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Javascript Simple With explanation
javascript-simple-with-explanation-by-ba-zewb
\nvar minDifference = function(nums) {\n let len = nums.length;\n if (len < 5) return 0;\n\n nums.sort((a,b) => a-b)\n \n return Math.min(\n
back_to_basics
NORMAL
2021-07-30T16:29:56.412681+00:00
2021-07-30T16:30:20.334801+00:00
269
false
```\nvar minDifference = function(nums) {\n let len = nums.length;\n if (len < 5) return 0;\n\n nums.sort((a,b) => a-b)\n \n return Math.min(\n \n ( nums[len-1] - nums[3] ), // 3 elements removed from start 0 from end\n ( nums[len-4] - nums[0] ), // 3 elements removed from end 0 from start...
3
0
['JavaScript']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
C++ Solution || Using Sorting || Clear Code
c-solution-using-sorting-clear-code-by-k-mug7
Using Bubble and Selection Sort\n\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n <= 3) retur
kannu_priya
NORMAL
2021-07-07T18:48:48.173597+00:00
2021-07-07T18:51:30.048183+00:00
395
false
**Using Bubble and Selection Sort**\n```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n int n = nums.size();\n if(n <= 3) return 0;\n \n //using bubble sort (4 greatest elements will go at its right position)\n for(int i = 0; i < 4; i++)\n for(int ...
3
0
['C', 'Sorting', 'C++']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
Java based solution using Sliding Window O(nLogn)
java-based-solution-using-sliding-window-p6db
Intuition\nHere you have to find the minumum difference between the largest and the smallest number by making/considering any other three numbers in the array e
azmishra
NORMAL
2021-07-04T18:14:05.035404+00:00
2021-07-04T18:14:05.035446+00:00
341
false
**Intuition**\nHere you have to find the minumum difference between the largest and the smallest number by making/considering any other three numbers in the array equal to whatever number from the same array. Confused? I was too . \n\nIt\'s actually simple, all you have to do is to see this problem in a different way. ...
3
0
['Sliding Window', 'Sorting', 'Java']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
just Follow pattern Runtime: 72 ms, faster than 95.87%
just-follow-pattern-runtime-72-ms-faster-bgk1
\nstatic auto speedup = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\nclas
cs_balotiya
NORMAL
2021-06-11T10:36:08.695461+00:00
2021-06-11T10:36:08.695506+00:00
98
false
```\nstatic auto speedup = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n \n\t\t int n = nums.size();\n\t\t\t\t\n\t\t if(n <= 3)\n return 0;\n...
3
1
[]
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
O(N) find 4 smallest and 4 largest, 82% speed
on-find-4-smallest-and-4-largest-82-spee-ikm9
Runtime: 332 ms, faster than 81.63% of Python3 online submissions for Minimum Difference Between Largest and Smallest Value in Three Moves.\nMemory Usage: 24.1
evgenysh
NORMAL
2021-04-28T12:59:00.029835+00:00
2021-04-28T12:59:00.029864+00:00
670
false
Runtime: 332 ms, faster than 81.63% of Python3 online submissions for Minimum Difference Between Largest and Smallest Value in Three Moves.\nMemory Usage: 24.1 MB, less than 75.23% of Python3 online submissions for Minimum Difference Between Largest and Smallest Value in Three Moves.\n```\nclass Solution:\n def minD...
3
1
['Python', 'Python3']
1
minimum-difference-between-largest-and-smallest-value-in-three-moves
C++ sort and recursion with explanation
c-sort-and-recursion-with-explanation-by-9rqo
\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n // Sort the array first. Then for each move we have 2 options:\n // 1) M
chase1991
NORMAL
2021-02-26T03:30:38.528927+00:00
2021-02-26T03:30:38.528983+00:00
181
false
```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n // Sort the array first. Then for each move we have 2 options:\n // 1) Move the smallest number to the next larger number, OR\n // 2) Move the largest number to the next smaller number.\n // We need to compare the d...
3
0
[]
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
Simple C++ Solution
simple-c-solution-by-indrajohn-quk7
\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int count = 0;\n if (nums.size(
indrajohn
NORMAL
2021-02-15T11:12:15.851263+00:00
2021-02-15T11:12:15.851297+00:00
279
false
```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int count = 0;\n if (nums.size() <= 4) return 0;\n \n int n = nums.size();\n int a = nums[n - 1] - nums[3], b = nums[n - 2] - nums[2], \n c = nums[n - 3] ...
3
0
[]
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
C# - Simple Solution Easy to Understand
c-simple-solution-easy-to-understand-by-nqr72
\npublic class Solution {\n public int MinDifference(int[] nums) {\n \n if(nums.Length<=4)\n return 0;\n Array.Sort(nums);\n
karanverma39
NORMAL
2021-02-15T07:08:42.178296+00:00
2021-02-15T07:08:42.178340+00:00
169
false
```\npublic class Solution {\n public int MinDifference(int[] nums) {\n \n if(nums.Length<=4)\n return 0;\n Array.Sort(nums);\n \n int result = int.MaxValue;\n \n for(int i = 0; i < 4; i++){\n result = Math.Min(result,(nums[nums.Length-1-3+i]-num...
3
0
['Sorting']
0
minimum-difference-between-largest-and-smallest-value-in-three-moves
My Java Solution
my-java-solution-by-vrohith-ko4y
\nclass Solution {\n public int minDifference(int[] nums) {\n if (nums.length < 5)\n return 0;\n Arrays.sort(nums);\n int res
vrohith
NORMAL
2020-09-05T06:36:34.755621+00:00
2020-09-05T06:36:34.755657+00:00
518
false
```\nclass Solution {\n public int minDifference(int[] nums) {\n if (nums.length < 5)\n return 0;\n Arrays.sort(nums);\n int result = Integer.MAX_VALUE;\n for (int i=0; i<4; i++) {\n result = Math.min(result, nums[nums.length-4+i] - nums[i]);\n }\n retu...
3
0
['Array', 'Sorting', 'Java']
2
split-message-based-on-limit
[Python] Find the number of substrings
python-find-the-number-of-substrings-by-kp24z
Explanation\nThe key question is to find out the number of split parts k.\n\ncur is the total string length of all indices,\nlike the string length for "123" is
lee215
NORMAL
2022-11-12T17:07:32.123238+00:00
2022-11-13T04:01:05.578380+00:00
6,441
false
# **Explanation**\nThe key question is to find out the number of split parts `k`.\n\n`cur` is the total string length of all indices,\nlike the string length for "123" is 3.\n`</>` takes 3 characters.\nThe number `k` takes `len(str(k))` characters.\n\nIf `cur + len(s) + (3 + len(str(k))) * k > limit * k`,\nmeans not en...
71
1
['Python']
14
split-message-based-on-limit
✅ [Python] binary search is redundant, just brute force it (explained)
python-binary-search-is-redundant-just-b-jbq4
\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs a brute force approach to find the minimal number of parts needed to split the string
stanislav-iablokov
NORMAL
2022-11-12T18:12:19.821564+00:00
2022-11-12T18:34:18.502193+00:00
3,023
false
**\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs a brute force approach to find the minimal number of parts needed to split the string into parts of limited length with appended suffixes. Time complexity is linear: **O(N)**. Space complexity is linear: **O(N)**.\n\n**Comment.** Given th...
43
0
[]
8
split-message-based-on-limit
✔✔✔ Brute Force ⁉ || Simple Approach || C++ || Explained
brute-force-simple-approach-c-explained-1jb02
As the problem required to find minimum number of parts, Let us traverse from 1 to see if we can divide our message with current number of parts.\n\nLet us do s
brehampie
NORMAL
2022-11-12T16:01:40.297319+00:00
2022-11-13T12:31:24.286042+00:00
2,235
false
As the problem required to find minimum number of parts, Let us traverse from 1 to see if we can divide our message with current number of parts.\n\nLet us do some calculation now.\n\n<b>What will be the length of the string after we attach the extra info "<a/b>" with each part?</b>\n\nLet the number of parts = <b>N</...
32
8
['C']
8
split-message-based-on-limit
Binary search does not work - counterexample added
binary-search-does-not-work-counterexamp-i1eo
Counter example\n\n"abbababbbaaa aabaa a"\n8\n\n\nThe above test can be split into 7 tokens, can\'t be split into 10 tokens and it can be split again into 11 to
przemysaw2
NORMAL
2022-11-16T02:59:18.485281+00:00
2022-11-28T17:27:15.557413+00:00
1,400
false
# Counter example\n```\n"abbababbbaaa aabaa a"\n8\n```\n\nThe above test can be split into 7 tokens, can\'t be split into 10 tokens and it can be split again into 11 tokens. This problem does not have the BS property.\n\nSome of the incorrect BS solutions passed these tests, because of the order in which they check the...
21
0
['C++']
8
split-message-based-on-limit
✅ Most Descriptive Solution So Far
most-descriptive-solution-so-far-by-hrid-n3qu
\u2705 It surprises me how posts with absolutely no explanation receive so many upvotes!!\n\n# Code\nJava []\nclass Solution {\n // returns the number of cha
hridoy100
NORMAL
2024-08-09T01:19:37.957279+00:00
2024-08-09T01:21:22.369186+00:00
1,571
false
### \u2705 It surprises me how posts with absolutely no explanation receive so many upvotes!!\n\n# Code\n``` Java []\nclass Solution {\n // returns the number of characters in an integer\n int charLen(int value) {\n int len = 0;\n while(value!=0) {\n len++;\n value /=10;\n ...
14
0
['String', 'Binary Search', 'Java']
0
split-message-based-on-limit
💥💥 O(n) on runtime and memory [EXPLAINED]
on-on-runtime-and-memory-explained-by-r9-jb20
IntuitionSplit a long message into smaller parts, each with a specific length, and append a suffix showing its index and total number of parts. The suffix must
r9n
NORMAL
2024-12-26T05:39:53.235782+00:00
2024-12-26T05:39:53.235782+00:00
303
false
# Intuition Split a long message into smaller parts, each with a specific length, and append a suffix showing its index and total number of parts. The suffix must fit within the given length limit, and we need to minimize the number of parts while ensuring all parts, when combined, reconstruct the original message. # ...
11
0
['String', 'Binary Search', 'Rust']
0
split-message-based-on-limit
Java divide stage solution
java-divide-stage-solution-by-wts2accura-8rba
\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n int[] stgTable = {\n (limit - 5) * 9,\n
david_chiang_job
NORMAL
2022-11-12T16:13:06.018526+00:00
2022-11-12T16:13:06.018564+00:00
1,409
false
```\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n int[] stgTable = {\n (limit - 5) * 9,\n (limit - 6) * 9 + (limit - 7) * 90,\n (limit - 7) * 9 + (limit - 8) * 90 + (limit - 9) * 900,\n (limit - 8) * 9 + (limit - 9) ...
10
0
['Java']
2
split-message-based-on-limit
[Python] Simple dumb O(N) solution, no binary search needed
python-simple-dumb-on-solution-no-binary-ejv5
Intuition\nThe idea is to figure out how many characters the parts count take up. Once we know that, generating all the parts is trivial.\n\n# Approach\nSimply
vu-dinh-hung
NORMAL
2022-11-12T17:01:28.669676+00:00
2023-01-01T04:16:16.905877+00:00
1,633
false
# Intuition\nThe idea is to figure out how many characters the parts count take up. Once we know that, generating all the parts is trivial.\n\n# Approach\nSimply check if 9, 99, 999, or 9999 parts are enough to split the whole message, since 9, 99, 999, or 9999 are the maximum possible parts count for 1, 2, 3, or 4 cha...
9
0
['Python3']
1
split-message-based-on-limit
Java Easy to Understand Code
java-easy-to-understand-code-by-sajedjal-2oxu
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
sajedjalil
NORMAL
2024-02-05T03:18:06.543536+00:00
2024-02-05T03:18:06.543570+00:00
928
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: O(n log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, ...
7
0
['Java']
2
split-message-based-on-limit
Java || concise and clear solution
java-concise-and-clear-solution-by-chris-2lkc
\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n int size = message.length();\n int lenOfIndice = 1, total = 1;
Chris___Yang
NORMAL
2022-11-17T21:37:18.269940+00:00
2022-11-17T21:37:18.269968+00:00
1,054
false
```\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n int size = message.length();\n int lenOfIndice = 1, total = 1;\n while (size + (3 + len(total)) * total + lenOfIndice > limit * total) {\n if (3 + len(total) * 2 >= limit) return new String[0];\n ...
7
0
['Java']
1
split-message-based-on-limit
C++ Solution with explanation
c-solution-with-explanation-by-rac101ran-3dai
\n// First I thought of binary search , but realised soon , I can iterate over all the b\'s.\n// Let\'s say answer is of size x , We know x-1 words will have le
rac101ran
NORMAL
2022-11-14T19:01:35.124502+00:00
2022-11-30T07:03:57.660849+00:00
684
false
```\n// First I thought of binary search , but realised soon , I can iterate over all the b\'s.\n// Let\'s say answer is of size x , We know x-1 words will have length limit & last word should be <=limit\n// Validate the last word , picking b greedily :)\nclass Solution {\npublic:\n vector<string> splitMessage(stri...
7
0
['Math', 'C']
3
split-message-based-on-limit
Python, Go | Simple solution with explanation | O(N)
python-go-simple-solution-with-explanati-zjjt
Intuition\n Describe your first thoughts on how to solve this problem. \nLet\'s consider a scenario where we merge the split string back without excluding the s
globaldjs
NORMAL
2024-02-04T04:18:16.698154+00:00
2024-02-04T04:18:16.698183+00:00
1,242
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s consider a scenario where we merge the split string back without excluding the suffixes. Knowing the **original size** of the string and the **number** of its parts, we can calculate the overall size of this combined string.\n\nExa...
6
0
['Go', 'Python3']
2
split-message-based-on-limit
Binary Search
binary-search-by-votrubac-bls0
This is an old problem known as SMS split (SMS messages are limited to 160 characters).\n\nWe can use a binary search to find out the number of messages. We jus
votrubac
NORMAL
2022-11-13T23:07:28.969901+00:00
2022-11-16T06:30:12.204191+00:00
1,357
false
This is an old problem known as SMS split (SMS messages are limited to 160 characters).\n\nWe can use a binary search to find out the number of messages. We just need to make this search efficient (e.g. no string creation).\n\n> Note that first we need to find the smallest number of digits in `b`, e.g. 1 (up to 9 parts...
6
0
['C']
2
split-message-based-on-limit
C++ | Try to find the optimal b, since it is affecting suffix length
c-try-to-find-the-optimal-b-since-it-is-by80r
we know that the <a/b> suffix is dependent on b and a goes till b, so if we can somehow try to find the optimal b, we should be able to get the answer.\n\nHow
ajay_5097
NORMAL
2022-11-13T06:33:58.802082+00:00
2022-11-13T06:35:03.741186+00:00
320
false
we know that the `<a/b>` suffix is dependent on `b` and `a` goes till `b`, so if we can somehow try to find the optimal `b`, we should be able to get the answer.\n\nHow to find optimal `b` - \n\nWe know that exact `b` does not matter, the only thing that matters is the length of `b`. Since the length of the input stri...
5
0
[]
1
split-message-based-on-limit
Simple Approach || C++ || Check For every Number of Spilit
simple-approach-c-check-for-every-number-ngjz
\nclass Solution {\npublic:\n string getSuffix(int a,int b){\n string suffix = "<" + to_string(a) + "/" + to_string(b) + ">";\n return suffix;
PRINCE_____RAJ
NORMAL
2022-11-12T17:42:40.488492+00:00
2022-11-13T10:36:48.043066+00:00
483
false
```\nclass Solution {\npublic:\n string getSuffix(int a,int b){\n string suffix = "<" + to_string(a) + "/" + to_string(b) + ">";\n return suffix; \n }\n vector<string> splitMessage(string s, int limit) {\n if(limit < 6)\n return {};\n int sum = 0;\n int i;\n ...
5
1
[]
2
split-message-based-on-limit
Python tricky solution
python-tricky-solution-by-faceplant-v9a6
python\nr = -1\nn = len(message)\ns = (limit - 5) * 9\nif s >= n:\n\tr = 9 - (s - n) // (limit - 5)\nelse:\n\ts = (limit - 6) * 9 + (limit - 7) * 90\n\tif s >=
FACEPLANT
NORMAL
2022-11-12T16:11:04.181944+00:00
2022-11-12T16:20:29.649480+00:00
1,083
false
```python\nr = -1\nn = len(message)\ns = (limit - 5) * 9\nif s >= n:\n\tr = 9 - (s - n) // (limit - 5)\nelse:\n\ts = (limit - 6) * 9 + (limit - 7) * 90\n\tif s >= n:\n\t\tr = 99 - (s - n) // (limit - 7)\n\telse:\n\t\ts = (limit - 7) * 9 + (limit - 8) * 90 + (limit - 9) * 900\n\t\tif s >= n:\n\t\t\tr = 999 - (s - n) // ...
5
1
[]
1
split-message-based-on-limit
Binary search for optimal split
binary-search-for-optimal-split-by-theab-ltfj
\nclass Solution:\n def getsuffixes(self, n):\n return [f"<{i}/{n}>" for i in range(1, n + 1)]\n \n def splitMessage(self, message: str, limit:
theabbie
NORMAL
2022-11-12T16:00:40.868219+00:00
2022-11-12T16:00:40.868251+00:00
1,164
false
```\nclass Solution:\n def getsuffixes(self, n):\n return [f"<{i}/{n}>" for i in range(1, n + 1)]\n \n def splitMessage(self, message: str, limit: int) -> List[str]:\n n = len(message)\n if n + 5 <= limit:\n return [f"{message}<1/1>"]\n beg = 1\n end = n\n f...
5
2
['Python']
4
split-message-based-on-limit
Binary Search || Simple Approach || C++ || Explaination || Clear Code
binary-search-simple-approach-c-explaina-nsfo
In this problem, we are sure that if we give 1 token to every element we get the one possible distribution but it is not the ans, but if we take it as one possi
Sriyansh2001
NORMAL
2022-11-12T19:52:47.203943+00:00
2022-11-12T19:56:13.803563+00:00
979
false
In this problem, we are sure that if we give 1 token to every element we get the one possible distribution but it is not the ans, but if we take it as one possible chance of answer so our distribution will be from 1 to n (length of the string). \nNow first we check for the middle one. If the answer is possible we can r...
4
0
['Binary Search', 'C++']
2
split-message-based-on-limit
Straightforward solution
straightforward-solution-by-xiangthepooh-csyj
Code\npy\nclass Solution:\n def splitMessage(self, message: str, limit: int) -> List[str]:\n def mysum(parts):\n if parts < 10: return part
Xiangthepoohead
NORMAL
2024-08-17T03:10:04.366474+00:00
2024-08-17T03:10:04.366514+00:00
523
false
# Code\n```py\nclass Solution:\n def splitMessage(self, message: str, limit: int) -> List[str]:\n def mysum(parts):\n if parts < 10: return parts\n if parts < 100: return 2*(parts-9) + mysum(9)\n if parts < 1000: return 3*(parts-99) + mysum(99)\n if parts < 10000: r...
3
0
['Python3']
0
split-message-based-on-limit
Detailed explanation with code | Both O(n) and Binary Search solution | C++
detailed-explanation-with-code-both-on-a-xfsm
Intuition\n Describe your first thoughts on how to solve this problem. \nIt\'s pretty obvious from the question that the key thing we need to find out is minimu
ayan_27
NORMAL
2024-05-02T07:28:00.442291+00:00
2024-05-02T07:30:28.859782+00:00
272
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt\'s pretty obvious from the question that the key thing we need to find out is **minimum number of total splits**. If we know in how many parts we can split the message so that every part except the last one satisfying the limit conditi...
3
0
['Binary Search', 'C++']
1
split-message-based-on-limit
JAVA soln with explanation
java-soln-with-explanation-by-vibh04-ehf3
The basic idea for this problem is to determine the appropriate number of parts to divide our input string to, such that each part length is within limit define
Vibh04
NORMAL
2022-11-12T18:35:57.228921+00:00
2022-11-12T18:35:57.228959+00:00
285
false
The basic idea for this problem is to determine the appropriate number of parts to divide our input string to, such that each part length is within limit defined. One way to determine it is to loop on possible part values and then divide the modified string (containing original string plus all instances of <a/part>) by...
3
0
['Java']
0
split-message-based-on-limit
Java check all possible suffix lengths
java-check-all-possible-suffix-lengths-b-lz53
\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n // since message length can be at most 10^4, we cant\n // poss
zadeluca
NORMAL
2022-11-12T16:06:00.307232+00:00
2022-11-12T16:06:00.307273+00:00
429
false
```\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n // since message length can be at most 10^4, we cant\n // possibly have more than 10^5-1 parts, or 5 digits in length\n for (int numDigits = 1; numDigits <= 5; numDigits++) {\n int maxParts = (int)Math...
3
0
[]
1
split-message-based-on-limit
Java - Binary search fails. Simple brute force works like charm.
java-binary-search-fails-simple-brute-fo-x5kx
My inital thought was to find the y in . Basically how many parts. I tried binary search and almost 91/94 test cases passed then. I will my binary search code b
vijaygtav
NORMAL
2024-03-10T01:31:42.650782+00:00
2024-03-10T01:31:42.650805+00:00
193
false
My inital thought was to find the y in <x/y>. Basically how many parts. I tried binary search and almost 91/94 test cases passed then. I will my binary search code below, very stright forward binary search. Later with the failed example, i realized that if we find some number is failing, doesn\'t mean all the number be...
2
0
['Java']
0
split-message-based-on-limit
[Python] Easy Pattern Detection with thought process when being asked during interviews
python-easy-pattern-detection-with-thoug-cuhg
Pattern Detection\nThe difficulty of this problem come from 2 parts. For the sake of eay understanding, let\'s use i as the index of each part and X as the tota
jandk
NORMAL
2023-12-10T19:49:09.628608+00:00
2023-12-10T19:49:53.161862+00:00
115
false
### Pattern Detection\nThe difficulty of this problem come from 2 parts. For the sake of eay understanding, let\'s use `i` as the index of each part and `X` as the total number of parts.\n1. The total number of parts `X` is determined by the number of characters each part can hold which is various as index `i` increase...
2
0
[]
0
split-message-based-on-limit
Java || 99.02% fast || Simple & Easy to Understand
java-9902-fast-simple-easy-to-understand-tszj
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nAssume 1 <= num(page) <
x1x2x3xzzz
NORMAL
2023-08-21T20:20:10.122256+00:00
2023-08-21T20:20:10.122275+00:00
282
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAssume $$1 <= num(page) <= 9$$, confirm whether there is enough space for current message to be stored.\n\nIf so, compute the exact $$num(page)$$.\nIf not, assume $$10...
2
0
['Java']
2
split-message-based-on-limit
Binary Search solution with digit-count check(It passes "abbababbbaaa aabaa a" test case )
binary-search-solution-with-digit-count-u4spx
Approach\nBinary Search is not very necessary for this problem. just increase b one by one and check whether there are remain message. It takes O(n) so still ac
qian48
NORMAL
2022-11-24T01:38:52.402710+00:00
2022-11-24T01:56:22.768572+00:00
297
false
# Approach\nBinary Search is not very necessary for this problem. just increase `b` one by one and check whether there are remain message. It takes O(n) so still acceptable.\n\nFor binary search solution, one important thing to notice is that `b` is not monotone for different digit-count.\n\nExample:\nmessage = "abbaba...
2
0
['Python3']
0
split-message-based-on-limit
C++ O(n) simple solution
c-on-simple-solution-by-shashankzobb-yoke
Let the total number of part is total_num.\nLet\'s see. Every part is in the form of "_". The "<", ">", "/" are constant. The value of index does not depend on
ShashankZobb
NORMAL
2022-11-15T19:11:37.970703+00:00
2022-11-15T19:13:31.165746+00:00
280
false
Let the total number of part is total_num.\nLet\'s see. Every part is in the form of "_<index/total_num>". The "<", ">", "/" are constant. The value of index does not depend on our choice so we can treat it as constant. So the only remaining variables are **no of digit** in total_num and no of characters. Since there i...
2
0
['C']
0
split-message-based-on-limit
C++| Simple Linear Search + Maths | O(N)
c-simple-linear-search-maths-on-by-kumar-89hy
\nclass Solution {\npublic:\n int find(int n){\n int re = 0;\n while(n){re++;n/=10;}\n return re;\n }\n void dopart(vector<string>
kumarabhi98
NORMAL
2022-11-15T13:11:37.605594+00:00
2022-11-15T13:11:37.605632+00:00
115
false
```\nclass Solution {\npublic:\n int find(int n){\n int re = 0;\n while(n){re++;n/=10;}\n return re;\n }\n void dopart(vector<string>& re,string s,int limit,int n){\n int j = 0;\n string k = to_string(n);\n for(int i = 1; i<=n;++i){\n int size = limit-(3+fin...
2
0
['Math', 'C']
0
split-message-based-on-limit
[C++] Direct search for minimum target part number
c-direct-search-for-minimum-target-part-dxkc2
Think of the string "xxxx<a/b>" where b is a fixed upper bound with a < b.\nGiven a limit, one must reserve 3 characters for < / >.\nThe spaces allowed for putt
hy0913
NORMAL
2022-11-12T17:40:02.138332+00:00
2022-11-13T04:16:44.542659+00:00
307
false
Think of the string `"xxxx<a/b>"` where b is a fixed upper bound with `a < b`.\nGiven a limit, one must reserve 3 characters for `<` `/` `>`.\nThe spaces allowed for putting characters would be `limit - 3 - len(b) - len(a)`.\n![image](https://assets.leetcode.com/users/images/54b6dc8c-e784-41a9-9d56-311dd02f6021_1668274...
2
0
['C']
0
split-message-based-on-limit
Java solution using simple Math
java-solution-using-simple-math-by-kriti-vut1
\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n try{\n for(int parts=1;parts<=100000;parts++)\n
kritikmodi
NORMAL
2022-11-12T16:26:02.451715+00:00
2022-11-12T16:26:02.451754+00:00
1,104
false
```\nclass Solution {\n public String[] splitMessage(String message, int limit) {\n try{\n for(int parts=1;parts<=100000;parts++)\n {\n int extralen=(3+Integer.toString(parts).length())*parts;\n int extra=0;\n if(parts>=10000)\n ...
2
0
['Math', 'String', 'Java']
0
split-message-based-on-limit
[Python] Easy to understand O(N) solution with clear explanations
on-python-solution-with-clear-explanatio-wtpm
IntuitionThis is a hard problem at first glance. You need to know total number of parts (which we call N) the message will be broken into to start breaking down
ashkankzme
NORMAL
2025-04-10T16:48:44.554284+00:00
2025-04-10T19:18:02.305385+00:00
12
false
# Intuition This is a hard problem at first glance. You need to know total number of parts (which we call N) the message will be broken into to start breaking down the message, but you won't have that number until you have actually split the message. So what can be done? # Approach The key idea here is that you'll onl...
1
0
['Python3']
0
split-message-based-on-limit
Java | Binary Search
java-binary-search-by-wa11ace-zzc8
Intuition\nOnce the number of parts is decided, the problem can be solved easily.\nTo determine the number of parts, first decide the length this number has, an
wa11ace
NORMAL
2024-03-12T19:28:14.220438+00:00
2024-03-12T19:28:14.220473+00:00
93
false
# Intuition\nOnce the number of parts is decided, the problem can be solved easily.\nTo determine the number of parts, first decide the length this number has, and run binary search over all numbers of this length to find the minimum number.\n\n# Complexity\n- Time complexity:\n$$O(n)$$, given $$1 <= \\text{message.len...
1
0
['Java']
0
split-message-based-on-limit
Why not just simply counting from 1 to 4?
why-not-just-simply-counting-from-1-to-4-xzsi
Intuition\nThe only thing unknown is how many parts will be there. However, we don\'t need to know that ahead of time. The only reason we cannot determine the h
shawn996
NORMAL
2024-03-09T02:19:36.035454+00:00
2024-03-09T02:20:21.921839+00:00
298
false
# Intuition\nThe only thing unknown is how many parts will be there. However, we don\'t need to know that ahead of time. The only reason we cannot determine the how many non-suffix space a part could take is unknown of the LENGTH of total parts, but we can use placeholder for this unknown. Since the message length is l...
1
0
['Python3']
1
split-message-based-on-limit
O(n) solution with O(1) space with "simple" math and problem constraints analysis
on-solution-with-o1-space-with-simple-ma-16v9
Intuition\nThe intuition is that no matter how many parts you have, they will always follow a pattern of digits. Any number between 100 and 999, for example, wi
vtfr
NORMAL
2023-12-13T20:08:31.934519+00:00
2023-12-13T20:17:15.605980+00:00
175
false
# Intuition\nThe intuition is that no matter how many parts you have, they will always follow a pattern of digits. Any number between 100 and 999, for example, will always have 3 digits. So instead of combining everything and seeing if it magically works (I\'m looking at you brute-forcers), we can calculate how many pa...
1
0
['Python3']
0
split-message-based-on-limit
Modified binary search
modified-binary-search-by-demon_code-led1
as it says make minimum splits as much as u can...\nso first try 1 to 9 , 10 to 99 , 100 to 999 , then 1000 to 9999 that\'s it\nso why doing this insted o
demon_code
NORMAL
2023-08-17T04:52:40.654902+00:00
2024-10-22T11:26:22.013488+00:00
734
false
as it says make minimum splits as much as u can...\nso first try 1 to 9 , 10 to 99 , 100 to 999 , then 1000 to 9999 that\'s it\nso why doing this insted of making low=1 and high=10000 and apply once the problem here is the binary search solution works for numbers which have same digit count \neg: \n"abbababbbaaa...
1
0
['Greedy', 'Binary Search Tree', 'C']
1
split-message-based-on-limit
Kotlin Solution with Math
kotlin-solution-with-math-by-lararicardo-c84c
Approach\nWe can solve this problem doing pure math calculations.\n\n1. We first try to split it with at most 9 copies. We know the suffix will be of the form "
lararicardo386
NORMAL
2023-07-30T05:48:27.291016+00:00
2023-07-30T05:48:27.291034+00:00
20
false
# Approach\nWe can solve this problem doing pure math calculations.\n\n1. We first try to split it with at most 9 copies. We know the suffix will be of the form "<1/9>", which will always have 5 chars. This means that we have only (limit -5) chars that we can extract from the original string. Therefore we would need (M...
1
0
['Kotlin']
0
split-message-based-on-limit
Golang solution with explanation
golang-solution-with-explanation-by-msfs-aalf
Intuition\nThe length of the suffix (<x/y>) determines everything else. Since the constraints say that that the length of the message is <= 10^4, that means tha
msfspinolo
NORMAL
2023-02-14T16:52:26.254269+00:00
2023-02-14T16:52:26.254318+00:00
60
false
# Intuition\nThe length of the suffix (`<x/y>`) determines everything else. Since the constraints say that that the length of the message is <= 10^4, that means that the mesage can be split into at most 10^4 parts, which means that the length of `y` in our suffix is at most 4.\n\n# Approach\nTry to split the message as...
1
0
['Go']
1
split-message-based-on-limit
2 steps solution - easy understanding
2-steps-solution-easy-understanding-by-g-sgdt
Intuition\n 2 steps to split message\n\n# Approach\n Step 1: calculate an array whose item is the chars amount that can be spliited at a specific suffix l
Gang-Li
NORMAL
2022-12-26T00:09:41.755157+00:00
2022-12-26T00:09:41.755189+00:00
202
false
# Intuition\n 2 steps to split message\n\n# Approach\n Step 1: calculate an array whose item is the chars amount that can be spliited at a specific suffix length.\n Step 2: calcuate the total number of splitted message. Based on the array from step 1, copy meessage into final answer array.\n \n\n# Complexity\...
1
0
['JavaScript']
0
split-message-based-on-limit
[Python3] linear search
python3-linear-search-by-ye15-4l0f
Please pull this commit for solutions of biweekly 91. \n\n\nclass Solution:\n def splitMessage(self, message: str, limit: int) -> List[str]:\n prefix
ye15
NORMAL
2022-11-19T19:37:29.416866+00:00
2022-11-19T19:37:29.416894+00:00
182
false
Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/e8b87d04cc192c5227286692921910fe93fee05d) for solutions of biweekly 91. \n\n```\nclass Solution:\n def splitMessage(self, message: str, limit: int) -> List[str]:\n prefix = b = 0 \n while 3 + len(str(b))*2 < limit and len(message) ...
1
0
['Python3']
1
split-message-based-on-limit
Golang 87 ms 7.3 MB
golang-87-ms-73-mb-by-maxhero90-c8nw
\nfunc max(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n\nfunc splitMessage(message string, limit int) []string {\n\tfor totalDigitCount :=
maxhero90
NORMAL
2022-11-14T23:00:29.462194+00:00
2022-11-14T23:00:29.462229+00:00
239
false
```\nfunc max(a, b int) int {\n\tif a >= b {\n\t\treturn a\n\t}\n\treturn b\n}\n\nfunc splitMessage(message string, limit int) []string {\n\tfor totalDigitCount := 1; totalDigitCount < 5; totalDigitCount++ {\n\t\tprevMaxPayload, maxPayload := 0, 0\n\t\tmultiplier := 1\n\t\tfor curDigitCount := 1; curDigitCount <= total...
1
0
['Go']
0
split-message-based-on-limit
[Golang] Brute Force 🤝💪✅✅✅ || Runtime = 142 ms || Memory = 7.4 MB
golang-brute-force-runtime-142-ms-memory-it8j
\nfunc splitMessage(message string, limit int) []string {\n\tp := 1\n\ta := 1\n\n\tfor p*(size(p)+3)+a+len(message) > p*limit {\n\t\tif 3+size(p)*2 >= limit {\n
a-n-k-r
NORMAL
2022-11-14T09:29:44.788071+00:00
2022-11-14T09:31:02.935511+00:00
47
false
```\nfunc splitMessage(message string, limit int) []string {\n\tp := 1\n\ta := 1\n\n\tfor p*(size(p)+3)+a+len(message) > p*limit {\n\t\tif 3+size(p)*2 >= limit {\n\t\t\treturn []string{}\n\t\t}\n\t\tp += 1\n\t\ta += size(p)\n\t}\n\n\tparts := make([]string, 0)\n\n\tfor i := 1; i < p+1; i++ {\n\t\tj := Min(limit - (size...
1
0
['Go']
0
split-message-based-on-limit
[C++] Brute force with O(N) time complexity
c-brute-force-with-on-time-complexity-by-ystx
\nclass Solution {\npublic:\n int digits(int n) {\n int cnt = 0;\n while (n) {\n n /= 10;\n cnt++;\n }\n re
kaminyou
NORMAL
2022-11-13T07:56:45.289834+00:00
2022-11-18T18:10:54.348436+00:00
310
false
```\nclass Solution {\npublic:\n int digits(int n) {\n int cnt = 0;\n while (n) {\n n /= 10;\n cnt++;\n }\n return cnt;\n }\n vector<string> splitMessage(string message, int limit) {\n int n = message.size();\n for (int length = 1; length * 2 + 3 ...
1
0
['C', 'Binary Tree']
2