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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
abbreviating-the-product-of-a-range | C++ Solution | Using logarithm property | c-solution-using-logarithm-property-by-k-gtaa | Approach\n1. remove all 2\'s and 5\'s while multiplying numbers and count how many times 2\'s and 5\'s appear\n2. number of zeros will be equal to min(two,five) | Kartikey_1109 | NORMAL | 2021-12-25T20:57:46.251712+00:00 | 2021-12-26T14:26:08.895574+00:00 | 556 | false | **Approach**\n1. remove all 2\'s and 5\'s while multiplying numbers and count how many times 2\'s and 5\'s appear\n2. number of zeros will be equal to ```min(two,five)```\n3. get original number back by multiplying extra occurence of two or five\n4. we maintain two numbers ```original``` and ```suffix``` by taking modu... | 6 | 0 | [] | 3 |
abbreviating-the-product-of-a-range | Java Solution - Brute Force | java-solution-brute-force-by-extremania-i283 | \nclass Solution {\n public String abbreviateProduct(int left, int right) {\n double a = 1L; // for first 5 digits\n long b = 1L; // for last 5 | extremania | NORMAL | 2021-12-28T03:46:23.786595+00:00 | 2021-12-28T03:46:23.786628+00:00 | 250 | false | ```\nclass Solution {\n public String abbreviateProduct(int left, int right) {\n double a = 1L; // for first 5 digits\n long b = 1L; // for last 5 digits\n long c = 1L; // for small result\n int zn = 0; // zero count\n for(int i=left; i<=right; i++){\n a*=i;\n ... | 4 | 2 | [] | 1 |
abbreviating-the-product-of-a-range | C++ | Pure math, no algorithm | c-pure-math-no-algorithm-by-changkunli-h1mi | \nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n int num_2 = 0, num_5 = 0;\n vector<int> arr;\n for(int i | changkunli | NORMAL | 2021-12-25T17:12:00.148927+00:00 | 2021-12-25T17:12:00.148965+00:00 | 723 | false | ```\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n int num_2 = 0, num_5 = 0;\n vector<int> arr;\n for(int i=left; i<=right; i++) {\n int num = i;\n while(!(num % 2)) {\n num_2 += 1;\n num /= 2;\n }\n ... | 4 | 1 | ['C'] | 2 |
abbreviating-the-product-of-a-range | [Java] Keep track of the product start and end | java-keep-track-of-the-product-start-and-sh8e | We can separately compute the start and end part of the number (as well as the number of trailing zeros).\nExample (with smaller numbers):\n\n 999[999]999 * | tobias2code | NORMAL | 2021-12-25T16:30:57.789873+00:00 | 2022-01-11T07:34:51.158654+00:00 | 722 | false | We can separately compute the start and end part of the number (as well as the number of trailing zeros).\nExample (with smaller numbers):\n```\n 999[999]999 * 99 // start = 999, end = 999\n = 989[99999]901 // start = 989, end = 901 => same as computing separately with 999 * 99 = 98901\n```\n\nUsing `long` provides... | 4 | 0 | ['Math', 'Java'] | 3 |
abbreviating-the-product-of-a-range | Python Straightforward | python-straightforward-by-lz2657-bsg9 | Track the head, tail and trailing zero when passing through the range.\nFor trailing zero, we need to count the number of 2 and 5 within the range.\nFor the hea | lz2657 | NORMAL | 2021-12-25T16:01:44.516125+00:00 | 2021-12-25T16:01:44.516167+00:00 | 366 | false | Track the head, tail and trailing zero when passing through the range.\nFor trailing zero, we need to count the number of 2 and 5 within the range.\nFor the head, as 1 <= left <= right <= 10^6, the top 5 digits can be calculated with the 1st ~ 12th digits, so we track top 12 digits.\nFor the tail, if we track the last ... | 4 | 1 | ['Python'] | 1 |
abbreviating-the-product-of-a-range | Basic Maths Shortest C++ Cleanest Solution | Easy to Understand | | basic-maths-shortest-c-cleanest-solution-x93n | The Solution basically consists of 3 things \n\n1. Counting Zeroes \n2. Getting Suffix\n3. Getting Prefix\n\nCounting Zeroes and Suffix can be done easily by | 1806manan | NORMAL | 2023-05-11T14:19:08.231793+00:00 | 2023-05-11T14:28:37.930469+00:00 | 322 | false | The Solution basically consists of 3 things \n\n1. Counting Zeroes \n2. Getting Suffix\n3. Getting Prefix\n\nCounting Zeroes and Suffix can be done easily by extracting only last 10-12 digits of the answer after every multiplication and counting and removing zeroes as soon as we found them.\n\nNow is the time tricky... | 3 | 0 | ['Math', 'C'] | 0 |
abbreviating-the-product-of-a-range | (C++) 2117. Abbreviating the Product of a Range | c-2117-abbreviating-the-product-of-a-ran-gqph | \n\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n int highest = 0, trailing = 0; \n long prefix = 1, suffix = 1 | qeetcode | NORMAL | 2021-12-25T17:57:57.562419+00:00 | 2021-12-25T17:57:57.562480+00:00 | 537 | false | \n```\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n int highest = 0, trailing = 0; \n long prefix = 1, suffix = 1; \n \n for (int x = left; x <= right; ++x) {\n prefix *= x; \n suffix *= x; \n for (; prefix >= 1e12; ++highe... | 3 | 0 | ['C'] | 1 |
abbreviating-the-product-of-a-range | Python (Simple Maths) | python-simple-maths-by-rnotappl-hz8h | 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 | rnotappl | NORMAL | 2023-04-14T18:00:38.535025+00:00 | 2023-04-14T18:00:38.535070+00:00 | 242 | 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)$$ --... | 2 | 1 | ['Python3'] | 1 |
abbreviating-the-product-of-a-range | Java : precision... precision... precision... | java-precision-precision-precision-by-di-fz2s | \n public String abbreviateProduct(int left, int right) {\n final long threshold0 = 100_000_000_000_000L,threshold1 = 10_000_000_000L,threshold2 = 100 | dimitr | NORMAL | 2022-01-11T07:15:54.722118+00:00 | 2022-01-11T07:45:31.896513+00:00 | 268 | false | ```\n public String abbreviateProduct(int left, int right) {\n final long threshold0 = 100_000_000_000_000L,threshold1 = 10_000_000_000L,threshold2 = 100_000;\n long curr=1;\n int i, zerosCount = 0;\n for(i=left;i<=right && curr<threshold0;i++){\n curr *= i;\n while(... | 2 | 0 | [] | 1 |
abbreviating-the-product-of-a-range | straight forward, brute force | straight-forward-brute-force-by-platinum-ufg5 | \nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n num = 1\n while left<=right:\n num *= left\n | platinum_s | NORMAL | 2021-12-30T19:32:42.231150+00:00 | 2022-01-03T05:40:38.842272+00:00 | 211 | false | ```\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n num = 1\n while left<=right:\n num *= left\n left+= 1\n a = str(num)\n b = a.rstrip("0")\n e = len(a)-len(b)\n if len(b) > 10:\n b = b[:5]+"..."+b[-5:]\n ... | 2 | 0 | ['Python'] | 2 |
abbreviating-the-product-of-a-range | Python, almost brute force | python-almost-brute-force-by-kryuki-hq7d | There are 2 steps:\nStep1: Calculate the number of trailing zeros\nStep2: Multiply & Keep track of the first 12 numbers and the last 5 numbers\n\nFor step1, we | kryuki | NORMAL | 2021-12-25T16:40:21.747835+00:00 | 2021-12-25T16:51:03.583773+00:00 | 278 | false | There are 2 steps:\nStep1: Calculate the number of trailing zeros\nStep2: Multiply & Keep track of the first 12 numbers and the last 5 numbers\n\nFor step1, we need to know the number of factors 2 and 5 in [right, left], because 10 = 2 * 5. The minimum of the two will be the number of trailing zeros.\n\nFor step2, If t... | 2 | 0 | ['Python', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | [Python] Short, contest-oriented solution | python-short-contest-oriented-solution-b-2z7f | Multiply all the numbers within the range but only keep track of the # of trailing zeros and the last 10 digits before that. Set the flag if the product ever gr | chuan-chih | NORMAL | 2021-12-25T16:26:36.402304+00:00 | 2021-12-27T22:02:31.891311+00:00 | 226 | false | Multiply all the numbers within the range but only keep track of the # of trailing zeros and the last 10 digits before that. Set the flag if the product ever grows above what `mod` can express. If it does, use the sum of `math.log10()` to calculate the leading 5 digits.\n\nI can probably use the sum of `math.log10()` t... | 2 | 0 | ['Python'] | 0 |
abbreviating-the-product-of-a-range | [Python3] Just Working Code - 27.09.2024 | python3-just-working-code-27092024-by-pi-9407 | \npython3 []\nimport math\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n last = 1\n modulo = 10 ** 5\n\n | Piotr_Maminski | NORMAL | 2024-09-27T14:39:54.844775+00:00 | 2024-09-27T14:40:32.379676+00:00 | 37 | false | \n```python3 []\nimport math\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n last = 1\n modulo = 10 ** 5\n\n twosCount = 0\n fivesCount = 0\n\n sumLog10 = 0\n maxBufferValue = 10 ** 1200\n bufferProduct = 1\n \n for x in... | 1 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | Simple (5-line) Python solution beats 100% || 5 line solution || beats 100% | simple-5-line-python-solution-beats-100-ya0zy | \n Describe your first thoughts on how to solve this problem. \n\n# Approach: Simple and step by step approach as mentiones in problem description \nstep 1: cal | s1ttu | NORMAL | 2023-01-03T14:47:16.517580+00:00 | 2023-01-03T14:47:16.517628+00:00 | 221 | false | \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach: Simple and step by step approach as mentiones in problem description \nstep 1: calculate the product of the given range (left, right)\nrange(left, right+1) will give us a range object or the range which is converted into list by list()... | 1 | 0 | ['Python3'] | 1 |
abbreviating-the-product-of-a-range | python soln | python-soln-by-kumarambuj-0br7 | \nclass Solution:\n def abbreviateProduct(self, l: int, r: int) -> str:\n \n num=1\n for i in range(l,r+1):\n num=num*i\n | kumarambuj | NORMAL | 2022-06-10T07:42:00.997809+00:00 | 2022-06-10T07:42:00.997851+00:00 | 110 | false | ```\nclass Solution:\n def abbreviateProduct(self, l: int, r: int) -> str:\n \n num=1\n for i in range(l,r+1):\n num=num*i\n \n c=0\n while(num>0 and num%10==0):\n c+=1\n num=num//10\n \n s=str(num)\n res=s\n i... | 1 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | C++ Math Solution | c-math-solution-by-ahsan83-02bl | \n1. We can always store first 12 digits of and last 12 digits of the multiplication as upper and lower\n2. We can count the number of digits in final product u | ahsan83 | NORMAL | 2022-05-18T08:59:01.376688+00:00 | 2022-05-18T08:59:01.376728+00:00 | 267 | false | ```\n1. We can always store first 12 digits of and last 12 digits of the multiplication as upper and lower\n2. We can count the number of digits in final product using Log formula\n3. We can count number of trailing zero by incrementing counter when lower digit is 0\n4. We can get first and last 5 digits of upper and l... | 1 | 0 | ['Math', 'C'] | 0 |
abbreviating-the-product-of-a-range | Python Solution Brute Force | python-solution-brute-force-by-reahaansh-jpvt | Upvote if you like the solution\n\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n value = 1\n count = 0\n | ReahaanSheriff | NORMAL | 2022-01-18T13:57:49.786503+00:00 | 2022-01-18T13:57:49.786531+00:00 | 130 | false | **Upvote if you like the solution**\n```\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n value = 1\n count = 0\n for i in range(left,right+1):\n value*=i # calculation of product value from left to right\n string = str(value)\n ... | 1 | 0 | ['Python'] | 0 |
abbreviating-the-product-of-a-range | Brute Force (Python) | brute-force-python-by-rishav_1999-f1ap | \tclass Solution:\n\t\tdef abbreviateProduct(self, left: int, right: int) -> str:\n\t\t\tans=1\n\t\t\tfor i in range(left,right+1):\n\t\t\t\tans*=i\n\t\t\tst=st | Rishav_1999 | NORMAL | 2021-12-31T08:57:50.479897+00:00 | 2021-12-31T08:57:50.479925+00:00 | 98 | false | \tclass Solution:\n\t\tdef abbreviateProduct(self, left: int, right: int) -> str:\n\t\t\tans=1\n\t\t\tfor i in range(left,right+1):\n\t\t\t\tans*=i\n\t\t\tst=str(ans)\n\t\t\tcnt=0\n\t\t\ti=len(st)-1\n\t\t\twhile st[i]=="0":\n\t\t\t\tcnt+=1\n\t\t\t\ti-=1\n\t\t\tst=st[:i+1]+"e"+str(cnt)\n\t\t\tif len(st)-cnt>10:\n\t\t\t\... | 1 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | Two working solutions, easy python solution. | two-working-solutions-easy-python-soluti-humg | Intuitionjust obtain the product of range value and convert it into string, check number of '0' in the string , and return the output as per condition.Complexit | ukmh02 | NORMAL | 2025-03-25T06:20:23.903369+00:00 | 2025-03-25T06:20:23.903369+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
just obtain the product of range value and convert it into string, check number of '0' in the string , and return the output as per condition.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(Right−Le... | 0 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | Abbreviate Product | O(B−A) | 100% Optimized C# | abbreviate-product-ob-a-100-optimized-c-7o1kf | IntuitionThe product grows too large for direct computation, so we track only the leading and trailing digits while counting trailing zeros.Approach
Leading dig | Gustavo_Mariano | NORMAL | 2025-02-10T13:08:53.285676+00:00 | 2025-02-10T13:08:53.285676+00:00 | 6 | false | # Intuition
The product grows too large for direct computation, so we track only the leading and trailing digits while counting trailing zeros.
# Approach
1. Leading digits (value): Multiply and normalize to keep only the first few significant digits while counting shifts (digitShift).
2. Trailing digits (remainder): ... | 0 | 0 | ['Math', 'C#'] | 0 |
abbreviating-the-product-of-a-range | 2117. Abbreviating the Product of a Range | 2117-abbreviating-the-product-of-a-range-a37p | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-18T02:59:29.993096+00:00 | 2025-01-18T02:59:29.993096+00:00 | 6 | 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
`... | 0 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | C++ mini BigInt implementation | c-mini-bigint-implementation-by-ivangnil-5s38 | IntuitionThe key is to handle large products by tracking both leading and trailing digits separately while counting trailing zeros.Approach
Use BigInt class to | ivangnilomedov | NORMAL | 2025-01-17T13:17:37.273834+00:00 | 2025-01-17T13:17:37.273834+00:00 | 20 | false | # Intuition
The key is to handle large products by tracking both leading and trailing digits separately while counting trailing zeros.
# Approach
1. Use BigInt class to store large numbers in base 10^13 chunks for leading digits
2. Track trailing digits separately modulo 10^10 to prevent overflow
3. Count trailing zer... | 0 | 0 | ['C++'] | 0 |
abbreviating-the-product-of-a-range | Python (Simple Maths) | python-simple-maths-by-rnotappl-bphz | 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 | rnotappl | NORMAL | 2024-11-01T16:54:07.647437+00:00 | 2024-11-01T16:54:07.647471+00:00 | 4 | 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)$$ --... | 0 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | 2117. Abbreviating the Product of a Range.cpp | 2117-abbreviating-the-product-of-a-range-x0o1 | Code\n\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n double upper = 1;\n long long lower = 1L;\n long l | 202021ganesh | NORMAL | 2024-11-01T10:52:15.216026+00:00 | 2024-11-01T10:52:15.216056+00:00 | 1 | false | **Code**\n```\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n double upper = 1;\n long long lower = 1L;\n long long Offset = 1e12;\n long long cutOffset = 1e5; \n double product = 0.0;\n int trailing = 0;\n \n for(int i=left;i... | 0 | 0 | ['C'] | 0 |
abbreviating-the-product-of-a-range | Python 3: TC O((right-left)*log(right)) SC O(1): Tricks for First and Last Five Digits | python-3-tc-oright-leftlogright-sc-o1-tr-kpfw | Intuition\n\nThe easy case is when the explicit product is less than a few thousand digits, in which case we can use Python\'s arbitrary precision math. Unfortu | biggestchungus | NORMAL | 2024-09-09T02:06:05.297854+00:00 | 2024-09-09T02:06:05.297878+00:00 | 2 | false | # Intuition\n\nThe easy case is when the explicit product is less than a few thousand digits, in which case we can use Python\'s arbitrary precision math. Unfortunately there\'s a limit of 4300 digits and we can easily hit that because we\'re basically computing factorials.\n\n## Counting Trailing Zeros\n\nIf there\'s ... | 0 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | Python3 Easy || O(N) | python3-easy-on-by-yangzen09-gjyd | Intuition:- Computing the product of all integers in a specified range and in a compact format, handling large numbers by using scientific notation and suppress | YangZen09 | NORMAL | 2024-08-08T05:22:55.956559+00:00 | 2024-08-08T05:22:55.956591+00:00 | 12 | false | **Intuition:-** *Computing the product of all integers in a specified range and in a compact format, handling large numbers by using scientific notation and suppressing trailing zeros.*\n**It also provides utility functions for calculating factorials and checking if a product exceeds a given threshold.**\n\n# Approach-... | 0 | 0 | ['Math', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | Best Performing Solution | Simple Python | Math | Very Detailed Explanation | Scientific Notation ✨ | best-performing-solution-simple-python-m-8cpf | UPVOTE is Highly Appreciated\n\n# Intuition\nUsing float or double to record prefix, inspired by scientific notation\n\n# Approach\n1. keep 0.1 <= prod < 1.0, s | Sci-fi-vy | NORMAL | 2024-05-25T10:40:24.762427+00:00 | 2024-05-25T10:40:24.762463+00:00 | 9 | false | **UPVOTE is Highly Appreciated**\n\n# Intuition\nUsing float or double to record prefix, inspired by scientific notation\n\n# Approach\n1. keep `0.1 <= prod < 1.0`, so len(str`(int(product * 100000))) == 5`, just like scientific notation\n\n2. so we can easily get `prefix` via `prefix = str(int(product * 100000))`\n\n3... | 0 | 0 | ['Math', 'Brainteaser', 'Python', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | The worst solution I've ever written (this is horrible). | the-worst-solution-ive-ever-written-this-1858 | 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 | NickUlman | NORMAL | 2024-03-25T17:55:39.817465+00:00 | 2024-03-25T17:55:39.817531+00:00 | 28 | 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)$$ --... | 0 | 0 | ['Java'] | 0 |
abbreviating-the-product-of-a-range | Python optimized long arithmetics (beats 96%) | python-optimized-long-arithmetics-beats-706ie | Intuition\nLet Product=L\cdot(L+1)\cdot...\cdot R.\nWhen the Product is small, we can handle it easily.\nOtherwise, the problems of finding first digits, last d | kapart | NORMAL | 2024-03-10T21:44:00.764922+00:00 | 2024-03-11T15:10:33.702790+00:00 | 19 | false | # Intuition\nLet $$Product=L\\cdot(L+1)\\cdot...\\cdot R$$.\nWhen the $$Product$$ is small, we can handle it easily.\nOtherwise, the problems of finding first digits, last digits and zeros count are solved independently.\n\n# Approach\n\n\n1. Represent the $$Product$$ in exponential form:\n$$Product=\\overline{a_1,a_2a... | 0 | 0 | ['Number Theory', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | Abbreviation of Product of a Range with Trailing Zeros | abbreviation-of-product-of-a-range-with-04zpq | Intuition\nThe code calculates the product of integers in a given range while removing trailing zeros. It then abbreviates the product and counts the number of | Gheshu | NORMAL | 2023-10-19T13:58:15.786601+00:00 | 2023-10-19T13:58:15.786626+00:00 | 12 | false | # Intuition\nThe code calculates the product of integers in a given range while removing trailing zeros. It then abbreviates the product and counts the number of removed zeros if the product is greater than a certain length. The goal is to make the code more efficient and optimized\n\n# Approach\n1. Initialize a count ... | 0 | 0 | ['Math', 'JavaScript'] | 0 |
abbreviating-the-product-of-a-range | [Python] 5 lines- only by '0' count for beginner | python-5-lines-only-by-0-count-for-begin-94cy | Time complexity: O(n)\n- Space complexity: O(1)\n\nclass Solution(object):\n def abbreviateProduct(self, left, right):\n t, k = str(reduce(operator.mu | hanifvub | NORMAL | 2023-09-10T13:16:20.414089+00:00 | 2023-09-10T13:16:20.414110+00:00 | 5 | false | - Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n```\nclass Solution(object):\n def abbreviateProduct(self, left, right):\n t, k = str(reduce(operator.mul,range(left,right+1))), 0\n while t[-k-1]==\'0\': k +=1\n if k: t=t[:-k]\n if len(t)>10: t=t[:5]+\'...\'+t[-5:]\n retu... | 0 | 0 | ['Python'] | 0 |
abbreviating-the-product-of-a-range | Very straightforward completely beginner friendly Python solution | very-straightforward-completely-beginner-171u | Intuition\n Describe your first thoughts on how to solve this problem. \nFairly easy. Just find the product and convert it to str\n\n# Approach\n Describe your | farhad_zada | NORMAL | 2023-08-27T11:40:14.555344+00:00 | 2023-08-27T11:40:14.555366+00:00 | 17 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFairly easy. Just find the product and convert it to str\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nYou just find the product and convert to string to slice it\n\n# Complexity\n- Time complexity: 51%\n<!-- Add... | 0 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | Easy to understand Python solution for Abbreviating the Product of a Range , | easy-to-understand-python-solution-for-a-imel | Intuition\n Describe your first thoughts on how to solve this problem. \nGood challenging problem \n\n# Approach\n Describe your approach to solving the problem | amaroww_0603 | NORMAL | 2023-06-16T16:48:04.466053+00:00 | 2023-06-16T16:48:04.466073+00:00 | 30 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGood challenging problem \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nnormal method , solution is easy to understand just used simple string slicing methods to solve it \n\n# Complexity\n- Time complexity:\n<!-... | 0 | 0 | ['Python'] | 0 |
abbreviating-the-product-of-a-range | Just a runnable solution | just-a-runnable-solution-by-ssrlive-dk63 | Code\n\nimpl Solution {\n pub fn abbreviate_product(left: i32, right: i32) -> String {\n let (mut suff, mut c, mut total, max_suff) = (1, 0, 0, 100_00 | ssrlive | NORMAL | 2023-03-04T02:26:54.393425+00:00 | 2023-03-04T02:26:54.393458+00:00 | 19 | false | # Code\n```\nimpl Solution {\n pub fn abbreviate_product(left: i32, right: i32) -> String {\n let (mut suff, mut c, mut total, max_suff) = (1, 0, 0, 100_000_000_000);\n let mut pref = 1.0;\n for i in left..=right {\n pref *= i as f64;\n suff *= i as i64;\n while ... | 0 | 0 | ['Rust'] | 0 |
abbreviating-the-product-of-a-range | Understandable Python Solution with linear time complexity | understandable-python-solution-with-line-blk7 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the above code is to efficiently calculate and represent the produ | udaykiran_3 | NORMAL | 2023-01-11T14:06:13.861139+00:00 | 2023-01-11T14:06:13.861184+00:00 | 89 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the above code is to efficiently calculate and represent the product of all integers in the given range in a human-readable format. The product can be very large and contain many trailing zeros, which can make it diff... | 0 | 0 | ['Python3'] | 0 |
abbreviating-the-product-of-a-range | I strive for the simple things LOL | Python TRULY SIMPLE solution | i-strive-for-the-simple-things-lol-pytho-gbr9 | The longest it took for me: https://leetcode.com/submissions/detail/852714885/\n\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> s | hemantdhamija | NORMAL | 2022-12-01T06:49:43.390152+00:00 | 2022-12-01T06:49:43.390189+00:00 | 111 | false | The longest it took for me: https://leetcode.com/submissions/detail/852714885/\n\n```\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n product, numZeros = factorial(right) // factorial(left - 1), 0\n while not product % 10:\n product //= 10\n numZero... | 0 | 0 | ['Math', 'Python'] | 0 |
abbreviating-the-product-of-a-range | Python Easy Solution | python-easy-solution-by-user7457rv-e3z0 | \nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n prod = left\n for i in range(prod+1,right+1):\n pro | user7457RV | NORMAL | 2022-10-28T18:41:19.129955+00:00 | 2022-10-28T18:41:19.129988+00:00 | 69 | false | ```\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n prod = left\n for i in range(prod+1,right+1):\n prod *= i\n \n prod = str(prod)\n prod = [prod[i] for i in range(len(prod))]\n pos = len(prod)-1\n count = 0\n for j i... | 0 | 0 | ['Python'] | 0 |
abbreviating-the-product-of-a-range | python solution (faster 90%) | python-solution-faster-90-by-dugu0607-w6gm | \tclass Solution:\n\t\tdef abbreviateProduct(self, l: int, r: int) -> str:\n\n\t\t\tnum=1\n\t\t\tfor i in range(l,r+1):\n\t\t\t\tnum=num*i\n\n\t\t\tc=0\n\t\t\tw | Dugu0607 | NORMAL | 2022-10-05T07:10:41.814533+00:00 | 2022-10-05T07:10:41.814573+00:00 | 39 | false | \tclass Solution:\n\t\tdef abbreviateProduct(self, l: int, r: int) -> str:\n\n\t\t\tnum=1\n\t\t\tfor i in range(l,r+1):\n\t\t\t\tnum=num*i\n\n\t\t\tc=0\n\t\t\twhile(num>0 and num%10==0):\n\t\t\t\tc+=1\n\t\t\t\tnum=num//10\n\n\t\t\ts=str(num)\n\t\t\tres=s\n\t\t\tif len(s)>10:\n\t\t\t\tres=s[:5]+\'...\'+s[-5:]\n\t\t\tres... | 0 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | Non-bruteforce algorithm in Python3 with numpy | non-bruteforce-algorithm-in-python3-with-xjc4 | As suggested in the hints, the three parts are calculated separately. The precision issue in the Python built-in floating numbers happen, so I use numpy.float1 | metaphysicalist | NORMAL | 2022-07-23T19:18:30.310585+00:00 | 2022-07-23T19:18:30.310618+00:00 | 100 | false | As suggested in the hints, the three parts are calculated separately. The precision issue in the Python built-in floating numbers happen, so I use numpy.float128 instead of the built-in floats. \n\n```\nimport numpy\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n log_prod = ... | 0 | 0 | ['Python', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | fast O(polylog n) time algorithm, C++ 0ms 100% | fast-opolylog-n-time-algorithm-c-0ms-100-kd5d | An algorithmic math problem.\nFirst 5 digits: numerical analysis.\nLast 5 digits: number theory.\n\n#define double long double\nconst double PI=atan((double)1)* | hqztrue | NORMAL | 2022-07-04T10:21:33.489804+00:00 | 2022-07-17T08:42:32.760413+00:00 | 112 | false | An algorithmic math problem.\nFirst 5 digits: numerical analysis.\nLast 5 digits: number theory.\n```\n#define double long double\nconst double PI=atan((double)1)*4,E=exp((double)1),\n B[]={1,1./2,1./6,0,-1./30,0,1./42,0,-1./30,0,5./66,0,-691./2730,0,7./6,0,-3617./510,0,43867./798,0,-174611./330};\nconst int M=10;\ndo... | 0 | 0 | ['Math'] | 0 |
abbreviating-the-product-of-a-range | Go | Golang | Prefix | Suffix | TotalDigits Count | TrailingZeroes | Math | go-golang-prefix-suffix-totaldigits-coun-sssk | ```\nfunc abbreviateProduct(left int, right int) string {\n product, trailingZeros, totalDigitsInProduct := 1, 0, 0.0\n maxSuffix:=100000000000\n maxPr | camusabsurdo | NORMAL | 2022-06-18T16:21:48.573395+00:00 | 2022-06-18T16:34:18.329026+00:00 | 106 | false | ```\nfunc abbreviateProduct(left int, right int) string {\n product, trailingZeros, totalDigitsInProduct := 1, 0, 0.0\n maxSuffix:=100000000000\n maxPrefix:=100000\n\tprefix := 1.0\n\n\tfor i := left; i <= right; i++ {\n\t\tproduct *= i\n totalDigitsInProduct += math.Log10(float64(i))\n prefix *=... | 0 | 0 | ['Math', 'Go'] | 0 |
abbreviating-the-product-of-a-range | Modulo and Double. | modulo-and-double-by-baba_dro-u5eq | Go version of the solution:\nhttps://leetcode.com/problems/abbreviating-the-product-of-a-range/discuss/1647115/Modulo-and-Double\n\n\nfunc abbreviateProduct(lef | baba_dro | NORMAL | 2022-03-22T05:50:25.446849+00:00 | 2022-03-22T05:50:25.446889+00:00 | 105 | false | Go version of the solution:\nhttps://leetcode.com/problems/abbreviating-the-product-of-a-range/discuss/1647115/Modulo-and-Double\n\n```\nfunc abbreviateProduct(left int, right int) string {\n\tstuff, c, total, maxStuff := 1, 0, 0, 100000000000\n\tpref := 1.0\n\n\tfor i := left; i <= right; i++ {\n\t\tpref *= float64(i)... | 0 | 0 | ['Go'] | 0 |
abbreviating-the-product-of-a-range | Python3 accepted solution (using rstrip) | python3-accepted-solution-using-rstrip-b-0y91 | \n class Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n product=1\n for i in range(left,right+1):\n produ | sreeleetcode19 | NORMAL | 2022-02-22T16:14:56.426812+00:00 | 2022-02-22T16:18:04.047106+00:00 | 182 | false | ```\n class Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n product=1\n for i in range(left,right+1):\n product *= i\n if(len(str(product).rstrip("0"))<=10):\n return str(product).rstrip("0") + "e" + str(len(str(product)) - len(str(product).rstrip(... | 0 | 0 | ['String', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | Straightforward Python 3 solution (beats 98.29% on memory) | straightforward-python-3-solution-beats-y18rr | Hope this helps...\n\n\'\'\'\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n\t\n product = 1\n \n #Since | tianxiaozhang | NORMAL | 2022-02-02T05:20:34.370438+00:00 | 2022-02-02T05:20:34.370473+00:00 | 125 | false | Hope this helps...\n\n\'\'\'\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n\t\n product = 1\n \n #Since trailing zeros come from 2*5 ultimately...\n two_count = 0\n five_count = 0\n\n for i in range(left, right+1):\n \n ... | 0 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | C math solution | c-math-solution-by-oryliavner-rrdr | See problem hints for why this works.\n\n#define MAX_CONTIGUOUS 10000000000ULL\n\nchar *abbreviateProduct(int left, int right){\n // Max size: #####...#####e | oryliavner | NORMAL | 2022-01-13T08:26:21.851937+00:00 | 2022-01-13T08:29:57.372868+00:00 | 151 | false | See problem hints for why this works.\n```\n#define MAX_CONTIGUOUS 10000000000ULL\n\nchar *abbreviateProduct(int left, int right){\n // Max size: #####...#####e####\n char* ret = calloc(19, sizeof(char));\n \n uint64_t product = 0;\n uint32_t top = 0;\n uint32_t bottom = 0;\n // 10000! has 2499 tra... | 0 | 0 | ['Math', 'C'] | 0 |
abbreviating-the-product-of-a-range | Clean and fast Java solution | clean-and-fast-java-solution-by-programw-f9j9 | \n\tprivate static final long MAX_SUFFIX = 1000000000000L;\n private static final int MAX_PREFIX = 100000;\n \n public String abbreviateProduct(int lef | programwithsai | NORMAL | 2022-01-06T11:46:27.611183+00:00 | 2022-01-06T11:46:27.611230+00:00 | 178 | false | ```\n\tprivate static final long MAX_SUFFIX = 1000000000000L;\n private static final int MAX_PREFIX = 100000;\n \n public String abbreviateProduct(int left, int right) {\n long product = 1;\n int trailingZeros = 0;\n double prefix = 1.0;\n \n for (int num = left; num <= right... | 0 | 0 | [] | 1 |
abbreviating-the-product-of-a-range | [Python] easy to read | python-easy-to-read-by-gusghrlrl101-1vde | \n\ndef abbreviateProduct(self, left: int, right: int) -> str:\n\tpre, suf, cnt = 1, 1, 0\n\tthreshold, pre_precision, suf_precision = int(1e14), int(1e5), (1e1 | gusghrlrl101 | NORMAL | 2022-01-01T16:57:14.343597+00:00 | 2022-01-01T16:57:14.343635+00:00 | 154 | false | \n```\ndef abbreviateProduct(self, left: int, right: int) -> str:\n\tpre, suf, cnt = 1, 1, 0\n\tthreshold, pre_precision, suf_precision = int(1e14), int(1e5), (1e10)\n\n\tfor num in range(left, right + 1):\n\t\tpre *= num\n\t\tsuf *= num\n\n\t\twhile pre >= pre_precision:\n\t\t\tpre /= 10\n\n\t\twhile suf % 10 == 0:\n\... | 0 | 0 | ['Python'] | 0 |
abbreviating-the-product-of-a-range | Brute Force Approach Python3 (Accepted) (Commented) | brute-force-approach-python3-accepted-co-eex5 | \nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n ans = 1 | sdasstriver9 | NORMAL | 2021-12-30T07:48:40.537649+00:00 | 2021-12-30T07:48:40.537705+00:00 | 108 | false | ```\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n ans = 1 //Initialise the product with 1\n while left <= right: // Start the multiplying numbers in\n ... | 0 | 0 | ['Python', 'Python3'] | 0 |
abbreviating-the-product-of-a-range | Python 3, math solution that follows hints | python-3-math-solution-that-follows-hint-box0 | Hints followed\n\n\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n # hints followed\n left = max(2, left)\n | huangshan01 | NORMAL | 2021-12-28T16:07:50.867212+00:00 | 2021-12-28T17:36:45.959773+00:00 | 123 | false | Hints followed\n\n```\nclass Solution:\n def abbreviateProduct(self, left: int, right: int) -> str:\n # hints followed\n left = max(2, left)\n mod = 10 ** 5\n p = 1 # 10**5 modulo of the product to represent the lowest 5 digits\n lg = 0 # cumulates log10 of each number left to righ... | 0 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | Java | Handwritten Illustrations | Very Easy to understand | java-handwritten-illustrations-very-easy-8km5 | \nAny corrections, suggestions or optimizations to code are welcomed. :)\nIf you found this post helpful then please like and comment to increase it\'s reach. : | Fly_ing__Rhi_no | NORMAL | 2021-12-28T09:51:05.878967+00:00 | 2021-12-28T09:51:05.879014+00:00 | 136 | false | \nAny corrections, suggestions or optimizations to code are welcomed. :)\nIf you found this post helpful then please like and comment to increase it\'s reach. :) | 0 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | [Java] Follow hints 275ms Two-Pass Solution | java-follow-hints-275ms-two-pass-solutio-vqdg | Use module to get last 5 digits in first pass\n* Use log10 to get first 5 digits in second pass\n\n\nclass Solution {\n public String abbreviateProduct(int l | 1v9n418vn51 | NORMAL | 2021-12-27T15:39:38.397861+00:00 | 2021-12-27T15:41:55.488610+00:00 | 255 | false | * Use module to get last 5 digits in first pass\n* Use log10 to get first 5 digits in second pass\n\n```\nclass Solution {\n public String abbreviateProduct(int left, int right) {\n int zero = 0;\n boolean mod = false;\n \n long val = 1L;\n for (int i = left; i <= right; i++) {\n ... | 0 | 0 | ['Java'] | 1 |
abbreviating-the-product-of-a-range | I just followed the hints | i-just-followed-the-hints-by-relentless1-etfw | https://anothercasualcoder.blogspot.com/2021/12/lc-hard-problem-follow-hints.html | relentless123 | NORMAL | 2021-12-27T06:47:21.444553+00:00 | 2021-12-27T06:47:21.444583+00:00 | 86 | false | [https://anothercasualcoder.blogspot.com/2021/12/lc-hard-problem-follow-hints.html](http://) | 0 | 2 | [] | 0 |
abbreviating-the-product-of-a-range | [C++] solution | c-solution-by-lovejavaee-7a8z | \npublic:\n int calcBas(int x, int y, int bas){\n int ret = 0;\n -- x;\n while(x)\n ret -= (x /= bas);\n while(y)\n | lovejavaee | NORMAL | 2021-12-25T22:55:08.948641+00:00 | 2021-12-26T05:42:31.167364+00:00 | 141 | false | ```\npublic:\n int calcBas(int x, int y, int bas){\n int ret = 0;\n -- x;\n while(x)\n ret -= (x /= bas);\n while(y)\n ret += (y /= bas);\n return ret;\n }\n int calcZeros(int x, int y){\n return min(calcBas(x, y, 2), calcBas(x, y, 5));\n }\n ... | 0 | 0 | ['C'] | 0 |
abbreviating-the-product-of-a-range | [C++] Linear scan, modulo, trailing zero counting, log10, etc... | c-linear-scan-modulo-trailing-zero-count-cvzo | \nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n // Find trailing zeros.\n int five_cnts = 0, two_cnts = 0;\n | phi9t | NORMAL | 2021-12-25T22:53:07.236785+00:00 | 2021-12-25T22:53:36.681903+00:00 | 73 | false | ```\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n // Find trailing zeros.\n int five_cnts = 0, two_cnts = 0;\n for (int d = left; d <= right; ++d) {\n int val = d; \n while ((val % 5) == 0) {\n val /= 5;\n ... | 0 | 0 | [] | 0 |
abbreviating-the-product-of-a-range | javascript math 1948ms | javascript-math-1948ms-by-henrychen222-1g7j | \nconst ll = BigInt;\n\nconst abbreviateProduct = (l, r) => {\n let p = 1n, e = 0, over10 = false, prePow = 1;\n for (let x = l; x <= r; x++) {\n p | henrychen222 | NORMAL | 2021-12-25T21:21:42.728999+00:00 | 2021-12-25T21:21:42.729024+00:00 | 128 | false | ```\nconst ll = BigInt;\n\nconst abbreviateProduct = (l, r) => {\n let p = 1n, e = 0, over10 = false, prePow = 1;\n for (let x = l; x <= r; x++) {\n p *= ll(x);\n while (p % 10n == 0) {\n p /= 10n;\n e++;\n }\n prePow += Math.log10(x);\n while (prePow > 100... | 0 | 0 | ['Math', 'JavaScript'] | 0 |
abbreviating-the-product-of-a-range | [Kotlin] 200 ms. One pass | kotlin-200-ms-one-pass-by-atrubin-shgh | \nclass Solution {\n fun abbreviateProduct(left: Int, right: Int): String {\n val eps = 1_000_000_000_000L\n\n var pre = 1L\n var suf = | atrubin | NORMAL | 2021-12-25T17:21:47.357793+00:00 | 2021-12-25T17:25:16.380486+00:00 | 91 | false | ```\nclass Solution {\n fun abbreviateProduct(left: Int, right: Int): String {\n val eps = 1_000_000_000_000L\n\n var pre = 1L\n var suf = 1L\n\n var zeroCount = 0\n\n (left.toLong()..right.toLong()).forEach {\n pre *= it\n suf *= it\n\n while (pre ... | 0 | 0 | ['Kotlin'] | 0 |
abbreviating-the-product-of-a-range | c++, 56ms | c-56ms-by-jamieyang-9asa | \nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n long long t1=1; // 5 digits, <100000\n long long t2=0; // 5+6 | jamieyang | NORMAL | 2021-12-25T17:02:40.386190+00:00 | 2021-12-25T17:03:49.102537+00:00 | 108 | false | ```\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n long long t1=1; // 5 digits, <100000\n long long t2=0; // 5+6 digits, <100000000000\n // t1,t2 ... t3\n unsigned long long e=0;\n int i;\n // very small\n for(i=right; i>=left; i--) {... | 0 | 0 | ['Math'] | 0 |
abbreviating-the-product-of-a-range | [C++] Brute Force | c-brute-force-by-ericyxing-ksys | Thanks for @linfq\'s solution, here is the C++ version. \n\n\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n int c = 0; | EricYXing | NORMAL | 2021-12-25T16:59:07.982143+00:00 | 2021-12-25T17:03:16.743761+00:00 | 133 | false | Thanks for <code>@linfq</code>\'s solution, here is the C++ version. \n\n```\nclass Solution {\npublic:\n string abbreviateProduct(int left, int right) {\n int c = 0;\n long long pre = 1, suf = 1, mod = 1e12;\n for (int i = left; i <= right; i++)\n {\n long long cur(i);\n ... | 0 | 1 | ['C'] | 0 |
abbreviating-the-product-of-a-range | C++ | Getting Runtime Error | Same Code working in VS | c-getting-runtime-error-same-code-workin-ivt0 | Can anyone help me - why i\'m getting runtime error in this one\nLine no - if i\'m commenting from \nint m = up.length() to st.pop();\nMy code is running on LC | kumarvoman | NORMAL | 2021-12-25T16:45:38.634709+00:00 | 2021-12-25T16:45:38.634734+00:00 | 181 | false | Can anyone help me - why i\'m getting runtime error in this one\nLine no - if i\'m commenting from \nint m = up.length() to st.pop();\nMy code is running on LC... and without commenting that part i\'m getting correct ouput in VS.\nAny suggestions ?\n\n```\nstring abbreviateProduct(int left, int right) {\n long ... | 0 | 0 | ['C'] | 2 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [Java/C++/Python] Straight Forward | javacpython-straight-forward-by-lee215-j11s | Intuition\nIf we can do 0 move, return max(A) - min(A)\nIf we can do 1 move, return min(the second max(A) - min(A), the max(A) - second min(A))\nand so on.\n\n | lee215 | NORMAL | 2020-07-11T16:04:35.062467+00:00 | 2020-07-16T16:46:56.090842+00:00 | 48,630 | false | # Intuition\nIf we can do 0 move, return max(A) - min(A)\nIf we can do 1 move, return min(the second max(A) - min(A), the max(A) - second min(A))\nand so on.\n<br>\n\n# **Explanation**\nWe have 4 plans:\n1. kill 3 biggest elements\n2. kill 2 biggest elements + 1 smallest elements\n3. kill 1 biggest elements + 2 smalle... | 597 | 7 | [] | 58 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | a few solutions | a-few-solutions-by-claytonjwong-gdn7 | Sort A, then perform a brute-force search of all posibilities using a sliding window of size 3 similar to 1423. Maximum Points You Can Obtain from Cards. Initi | claytonjwong | NORMAL | 2020-07-11T22:18:02.852116+00:00 | 2022-03-20T00:04:52.694278+00:00 | 10,313 | false | Sort `A`, then perform a brute-force search of all posibilities using a sliding window of size 3 similar to [1423. Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/discuss/597883/Javascript-and-C%2B%2B-solutions). Initially set the disclude window of size... | 124 | 1 | ['Sliding Window'] | 16 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [3 Solutions Tutorial O(n) Included] Minimum Difference Between Largest and Smallest Value | 3-solutions-tutorial-on-included-minimum-co78 | Topic : Greedy, Sort\n\nI remember solving this Google OA problem three years ago.\n___\n\n## Solution 1\nIf the length of the input array is 4 or fewer, the a | never_get_piped | NORMAL | 2024-07-03T00:19:17.307711+00:00 | 2024-07-03T20:12:40.894727+00:00 | 29,495 | false | **Topic** : Greedy, Sort\n\n**I remember solving this Google OA problem three years ago.**\n___\n\n## Solution 1\nIf the length of the input array is 4 or fewer, the answer is 0 because we can make all numbers equal with up to 3 moves.\n\nThree moves means that **we can remove 3 numbers from the input array to make th... | 106 | 1 | ['C', 'PHP', 'Python', 'Java', 'Go', 'JavaScript'] | 26 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Python, 3 lines, well explained, Greedy O(nlogn) | python-3-lines-well-explained-greedy-onl-qk1j | If the size <= 4, then just delete all the elements and either no or one element would be left giving the answer 0.\nelse sort the array\nthere are 4 possibilit | abhinavbajpai2012 | NORMAL | 2020-08-20T14:58:26.490133+00:00 | 2020-08-20T14:58:26.490182+00:00 | 9,434 | false | If the size <= 4, then just delete all the elements and either no or one element would be left giving the answer 0.\nelse sort the array\nthere are 4 possibilities now:-\n1. delete 3 elements from left and none from right\n2. delete 2 elements from left and one from right\nand so on.. now just print the minima.\n```\nc... | 89 | 1 | ['Python', 'Python3'] | 10 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Optimal + Easy sol | Time - o(nlogn) | Easy Vid Explanation also | optimal-easy-sol-time-onlogn-easy-vid-ex-ei0i | https://youtu.be/wQUB0lhYK6Y\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to minimize the difference between the maxi | Atharav_s | NORMAL | 2024-07-03T01:48:07.208417+00:00 | 2024-07-03T01:48:07.208436+00:00 | 15,868 | false | https://youtu.be/wQUB0lhYK6Y\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to minimize the difference between the maximum and minimum values in the array after making at most 3 moves. Since we can make up to 3 changes, effectively we can remove up to 3 elements from eith... | 53 | 3 | ['C++'] | 13 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Java straightforward heap O(N) | java-straightforward-heap-on-by-hobiter-93u1 | Time: \nO(N * lg4 * 2) == O(N), if N > 8;\nO(NlgN) if N <= 8;\nspace: O(1);\nJust calculate smallest 4 numbers and largest 4 numbers, and compare the difference | hobiter | NORMAL | 2020-07-11T20:27:50.862984+00:00 | 2020-07-12T21:07:39.697939+00:00 | 7,378 | false | Time: \nO(N * lg4 * 2) == O(N), if N > 8;\nO(NlgN) if N <= 8;\nspace: O(1);\nJust calculate smallest 4 numbers and largest 4 numbers, and compare the differences (see getDiff for detail.\n```\nclass Solution {\n public int minDifference(int[] nums) {\n if (nums.length < 5) return 0;\n if (nums.length <... | 41 | 4 | [] | 8 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Simple Greedy Approach | My screen recording | simple-greedy-approach-my-screen-recordi-vh04 | \nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n \n // if the size is smaller than 4 than we can easily make each of them | rachilies | NORMAL | 2020-07-11T16:02:16.680934+00:00 | 2020-07-11T22:58:06.777710+00:00 | 3,574 | false | ```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n \n // if the size is smaller than 4 than we can easily make each of them equal and hence min possible difference is zero\n if(nums.size() <= 3)\n return 0;\n \n int n = nums.size();\n \n ... | 33 | 2 | [] | 6 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | ✅Easiest 3 Step Cpp / Java / Py / JS Solution | Beginner Level 🏆| No Advance | easiest-3-step-cpp-java-py-js-solution-b-ihkh | \n### C++\n\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n //step 1\n int n = nums.size();\n if (n <= 4) return 0 | dev_yash_ | NORMAL | 2024-07-03T01:11:28.565627+00:00 | 2024-07-03T07:07:39.399973+00:00 | 7,075 | false | \n### C++\n```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n //step 1\n int n = nums.size();\n if (n <= 4) return 0;\n\n // step 2: Sort the array\n sort(nums.begin(), nums.end());\n\n // step 3: Evaluate the minimum difference possible with at most 3... | 32 | 0 | ['Array', 'Greedy', 'C', 'Sorting', 'Python', 'Java', 'Python3', 'JavaScript'] | 13 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Help understanding the question? | help-understanding-the-question-by-pytho-vrur | As of 7/28/2021, this is the description of the problem. \n\nGiven an array nums, you are allowed to choose one element of nums and change it by any value in on | python-rocks | NORMAL | 2021-07-29T02:45:49.763875+00:00 | 2021-07-29T02:45:49.763919+00:00 | 1,716 | false | As of 7/28/2021, this is the description of the problem. \n```\nGiven an array nums, you are allowed to choose one element of nums and change it by any value in one move.\n\nReturn the minimum difference between the largest and smallest value of nums after perfoming at most 3 moves.\n```\nAm I missing something here? \... | 31 | 0 | [] | 9 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | nth_element & sort 4 smallest, biggest vs 2 heaps vs 1-liner||17ms Beats 100% | nth_element-sort-4-smallest-biggest-vs-2-u6ym | Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy algorithm.\n\nSorting the whole array nums is easy, but the time complexity is r | anwendeng | NORMAL | 2024-07-03T02:30:46.054631+00:00 | 2024-07-03T12:07:31.028584+00:00 | 6,921 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy algorithm.\n\nSorting the whole array nums is easy, but the time complexity is raised up to $O(n\\log n)$.\n\nTry nth_element to find the 4 smallest & 4 biggest ints, then sort.\n\nPython solution is 1-liner using sorting the whole... | 30 | 0 | ['Array', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++', 'Python3'] | 14 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | C++ Simple Solution with Explanation | 100% Faster | c-simple-solution-with-explanation-100-f-iyom | kill 3 smallest elements\n2. kill 3 biggest elements\n3. kill 1 biggest elements + 2 smallest elements\n4. kill 2 biggest elements + 1 smallest elements\n\ncla | chiragjain77 | NORMAL | 2021-05-25T16:48:51.686423+00:00 | 2021-05-25T16:48:51.686468+00:00 | 2,986 | false | 1. kill 3 smallest elements\n2. kill 3 biggest elements\n3. kill 1 biggest elements + 2 smallest elements\n4. kill 2 biggest elements + 1 smallest elements\n```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n if(n<=4){\... | 25 | 0 | ['C', 'Sorting'] | 4 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Simple O(N) | C++ | Partial Sort | Detailed explaination | simple-on-c-partial-sort-detailed-explai-ma79 | We need to minimize the amplitude range (max_ele - min_ele) by changing at most 3 elements. \n\nIn order to do this, first we can sort the elements and then eit | joyful_bytes | NORMAL | 2022-03-15T06:47:18.638789+00:00 | 2022-03-15T06:55:05.026839+00:00 | 1,626 | false | We need to minimize the amplitude range (max_ele - min_ele) by changing at most 3 elements. \n\nIn order to do this, first we can **sort** the elements and then either\n**1. Kill last 3 elements\n2. Kill last 2 elements and first 1 element\n3. Kill last 1 element and first 2 element\n4. Kill first 3 elements**\nHere, k... | 22 | 0 | ['C', 'C++'] | 2 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Python Solution 🚀 | python-solution-by-a_bs-uan5 | Intuition\nThe problem requires minimizing the difference between the largest and smallest values in an array after at most three moves. By changing up to three | 20250406.A_BS | NORMAL | 2024-07-03T01:41:21.887081+00:00 | 2024-07-03T01:41:21.887099+00:00 | 2,168 | false | ### Intuition\nThe problem requires minimizing the difference between the largest and smallest values in an array after at most three moves. By changing up to three elements to any value, we can effectively remove up to three outliers. Thus, the core insight is that we can minimize the range by focusing on changing eit... | 19 | 0 | ['Python3'] | 4 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Easy understanding, Commented C++ solution with sort and sliding window | easy-understanding-commented-c-solution-n0oo1 | \n// Idea: \n// 1. Chaning a number to any value is the same as removing them from array,\n// in the sense of calculating min difference.\n// 2. Try | tinfu330 | NORMAL | 2021-11-06T01:13:42.786515+00:00 | 2021-11-08T00:53:18.212059+00:00 | 1,528 | false | ```\n// Idea: \n// 1. Chaning a number to any value is the same as removing them from array,\n// in the sense of calculating min difference.\n// 2. Try to simplify the question, what if you were asked to change one value\n// from a sorted array and get the min difference of largest and smallest value ... | 19 | 0 | ['C', 'Sliding Window', 'Sorting', 'C++'] | 3 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Java | With Explanation | java-with-explanation-by-surajthapliyal-25jv | Let say arr : \n[2,3,1,9,8,6,4]\n\nAfter sort :\n[1,2,3,4,6,8,9]\n\nwe\'ll replace 3 max/min elements with the min/max respectively\nobviously to make the diff | surajthapliyal | NORMAL | 2021-09-16T07:18:26.244639+00:00 | 2021-09-16T07:20:52.730631+00:00 | 1,102 | false | Let say arr : \n`[2,3,1,9,8,6,4]`\n\nAfter sort :\n`[1,2,3,4,6,8,9]`\n\nwe\'ll replace 3 max/min elements with the min/max respectively\nobviously to make the diff smaller.\n\n**case1** - [1,2,3,4,changed,changed,changed] => `res = Min(res,4-1) = 3`\n**case2** - [changed,2,3,4,5,changed,changed] => `res = Min(res,5-2) ... | 19 | 0 | [] | 5 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [C++] Partial sort; O(n); with explanation | c-partial-sort-on-with-explanation-by-mh-l6lz | We just need to know the four smallest numbers and the four largest to choose our optimal strategy. We could sort the entire array, but we don\'t have to. We ca | mhelvens | NORMAL | 2020-07-11T16:02:25.025212+00:00 | 2020-07-11T16:02:25.025262+00:00 | 1,221 | false | We just need to know the four smallest numbers and the four largest to choose our optimal strategy. We could sort the entire array, but we don\'t have to. We can use [partial sort](https://en.cppreference.com/w/cpp/algorithm/partial_sort).\n\n```C++\nint minDifference(vector<int>& nums) {\n int const N = nums.size();\... | 19 | 0 | ['C'] | 6 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | ✅💯🔥Explanations No One Will Give You🎓🧠2 Detailed Approaches🎯🔥Extremely Simple And Effective🔥 | explanations-no-one-will-give-you2-detai-38vk | \n \n \n Nothing is impossible. The word itself says \'I\'m possible!\'"\n \n \n \n | heir-of-god | NORMAL | 2024-07-03T14:16:06.338019+00:00 | 2024-07-03T14:21:36.363492+00:00 | 773 | false | <blockquote>\n <p>\n <b>\n Nothing is impossible. The word itself says \'I\'m possible!\'"\n </b> \n </p>\n <p>\n --- Audrey Hepburn ---\n </p>\n</blockquote>\n\n# \uD83D\uDC51Problem Explanation and Understanding:\n\n## \uD83C\uDFAF Pro... | 17 | 9 | ['Array', 'Greedy', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 10 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | JAVA - sorting O(nLog(n)) - only 4 choices | java-sorting-onlogn-only-4-choices-by-ru-5phh | Once we have array sorted, we can cut down this problem to selecting among only 4 choices for making 3 moves. \n\nConsider below example:\na b c d e f g h i j ( | rupesh25127 | NORMAL | 2021-07-05T06:32:14.257572+00:00 | 2021-07-05T06:32:33.976175+00:00 | 1,579 | false | Once we have array sorted, we can cut down this problem to selecting among only 4 choices for making 3 moves. \n\nConsider below example:\na b c d e f g h i j (say, this array is sorted)\n\n1. Will it matter if you change d, e, f, g to anything? No. You can set them all to a or j, and result will still be same.\n2. Thi... | 17 | 0 | ['Sorting', 'Java'] | 3 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Full Detailed Explanation 🏆🏆 | full-detailed-explanation-by-shivakumar1-sitd | Intuition\nGiven the array 0 1 5 10 14, we need to remove 3 numbers to make the difference between the maximum and minimum values as small as possible. There ar | shivakumar1 | NORMAL | 2024-07-03T06:34:13.898644+00:00 | 2024-07-03T06:34:13.898701+00:00 | 706 | false | # Intuition\nGiven the array `0 1 5 10 14`, we need to remove 3 numbers to make the difference between the maximum and minimum values as small as possible. There are four possible ways to achieve this:\n\n1. Remove the first 3 elements: `? ? ? 10 14`. The difference between the maximum and minimum is `14 - 10 = 4`.\n2.... | 15 | 0 | ['Array', 'Greedy', 'Sorting', 'Java'] | 3 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Java | Greedy | Easy Solution | java-greedy-easy-solution-by-rishabh255-6rri | \nclass Solution {\n public int minDifference(int[] nums) {\n int n = nums.length; \n if(n <= 4) return 0;\n Arrays.sort(nums);\n | rishabh255 | NORMAL | 2021-10-06T18:05:13.455221+00:00 | 2021-10-06T18:05:13.455267+00:00 | 1,489 | false | ```\nclass Solution {\n public int minDifference(int[] nums) {\n int n = nums.length; \n if(n <= 4) return 0;\n Arrays.sort(nums);\n \n int minv = Integer.MAX_VALUE;\n \n // Case 1 : converting last three values\n minv = Math.min(minv, nums[n-4] - nums[0]);\n ... | 15 | 0 | ['Greedy', 'Sorting', 'Java'] | 5 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Nth_element and Single Pass| C++ 11 ms 100% | Java 2 ms 100% | Python3 241 ms 99% | nth_element-and-single-pass-c-11-ms-100-rzkhp | Intuition\nUsing no more than 3 element removals, we need to minimize the array diameter, which is the max difference between its elements (the task statement s | sergei99 | NORMAL | 2024-07-03T07:53:26.614034+00:00 | 2024-07-03T18:04:13.658529+00:00 | 771 | false | # Intuition\nUsing no more than 3 element removals, we need to minimize the array diameter, which is the max difference between its elements (the task statement says "change element to any value", but from the target function perspective it\'s effectively the same as the element removal).\n\nObviously we are going to c... | 14 | 0 | ['Array', 'Sorting', 'Quickselect', 'C++', 'Java', 'Python3'] | 3 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | simple and easy C++ solution with explanation 😍❤️🔥 | simple-and-easy-c-solution-with-explanat-hgcr | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) \n {\n if(nums.s | shishirRsiam | NORMAL | 2024-07-03T01:25:03.138779+00:00 | 2024-07-03T01:25:03.138804+00:00 | 1,517 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n int minDifference(vector<int>& nums) \n {\n if(nums.size() <= 3) return 0;\n sort(begin(nums), end(nums));\n\n int ans = INT_MAX, n = nums.size();\n\n // frist three remove\n ans =... | 14 | 0 | ['Array', 'Greedy', 'Sorting', 'C++'] | 8 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [Python3] 1-line O(N) | python3-1-line-on-by-ye15-dl8m | Algo\nHere, at most 8 numbers are relevant, i.e. the 4 smallest and the 4 largest. Suppose they are labeled as \n\nm1, m2, m3, m4, ... M4, M3, M2, M1 \n\nthen m | ye15 | NORMAL | 2020-07-11T16:23:20.376828+00:00 | 2020-07-11T16:50:18.515880+00:00 | 1,873 | false | Algo\nHere, at most 8 numbers are relevant, i.e. the 4 smallest and the 4 largest. Suppose they are labeled as \n\n`m1, m2, m3, m4, ... M4, M3, M2, M1` \n\nthen `min(M4-m1, M3-m2, M2-m3, M1-m4)` gives the solution. It is linear `O(N)` to find `m1-m4` and `M1-M4` like below. \n\n`O(N)` time & `O(1)` space leveraging on ... | 14 | 2 | ['Python3'] | 4 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | One-pass solution with intuition | No sorting | Beats 99% | Python3 | one-pass-solution-with-intuition-no-sort-w54d | Intuition\nObserve that when making a move, there is no point in introducing a new number in the array - it is better to replace a number with something already | reas0ner | NORMAL | 2024-07-03T07:14:04.201511+00:00 | 2024-07-03T07:17:09.281718+00:00 | 806 | false | # Intuition\nObserve that when making a move, there is no point in introducing a new number in the array - it is better to replace a number with something already present elsewhere in the array, so as to not introduce a new max-min difference. This is equivalent to removing a number from the array.\n\nSo how do we remo... | 13 | 1 | ['Array', 'Greedy', 'Python3'] | 6 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | kya O(N) possible hain !? Lets Solve || C++, Beats 100% ?? | kya-on-possible-hain-lets-solve-c-beats-au3w2 | Check Out My New Channel : https://www.youtube.com/@Intuit_and_Code\n> if you came for O(N) approach then skip the first part\n# Intuition\n\n\n Describe your f | Rarma | NORMAL | 2024-07-03T04:54:05.463489+00:00 | 2024-09-11T11:57:12.589183+00:00 | 1,619 | false | **Check Out My New Channel : https://www.youtube.com/@Intuit_and_Code**\n> if you came for O(N) approach then skip the first part\n# Intuition\n\n\n<!-- Describe your first thoughts on how to solve this pro... | 13 | 0 | ['Array', 'Greedy', 'Sliding Window', 'Sorting', 'C++'] | 5 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | 💯✅🔥Detailed Easy Java ,Python3 ,C++ Solution|| 15 ms ||≧◠‿◠≦✌ | detailed-easy-java-python3-c-solution-15-hro1 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe key insights behind this intution is:\n1. If the array has less than 5 elements, th | suyalneeraj09 | NORMAL | 2024-07-03T02:24:28.803877+00:00 | 2024-07-03T02:24:49.228509+00:00 | 3,542 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key insights behind this intution is:\n1. If the array has less than 5 elements, the minimum difference will be 0, as we can\'t form two groups of 4 elements.\n1. Sorting the array in ascending order allows us to easily identify the 4... | 13 | 0 | ['Array', 'Greedy', 'Sorting', 'C++', 'Java', 'Python3'] | 6 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | JAVA Solution Explained in HINDI(2 Approaches) | java-solution-explained-in-hindi2-approa-hyx0 | https://youtu.be/eb4vwq4BBxI\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote | The_elite | NORMAL | 2024-07-03T08:54:53.771686+00:00 | 2024-07-03T08:56:29.590098+00:00 | 413 | false | https://youtu.be/eb4vwq4BBxI\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 500\nCurrent Subscriber:... | 10 | 0 | ['Java'] | 1 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [C++] Try 4 Possible Choices After Sorting | c-try-4-possible-choices-after-sorting-b-y2lo | Intuition\n Describe your first thoughts on how to solve this problem. \n- There are only 4 possible choices after sorting the integer array\n\n# Approach\n Des | pepe-the-frog | NORMAL | 2024-07-03T00:35:36.378157+00:00 | 2024-07-03T01:08:11.259121+00:00 | 1,342 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- There are only 4 possible choices after sorting the integer array\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Handle the base case\n - when `nums.size() <= 4`, we can make all the elements to the same valu... | 10 | 0 | ['Greedy', 'Sorting', 'C++'] | 6 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [Python3/Python] Easy readable solution with comments. | python3python-easy-readable-solution-wit-2hbb | \nclass Solution:\n \n def minDifference(self, nums: List[int]) -> int:\n \n n = len(nums)\n # If nums are less than 3 all can be rep | ssshukla26 | NORMAL | 2021-08-30T00:25:35.986528+00:00 | 2021-08-30T00:26:25.606995+00:00 | 1,921 | false | ```\nclass Solution:\n \n def minDifference(self, nums: List[int]) -> int:\n \n n = len(nums)\n # If nums are less than 3 all can be replace,\n # so min diff will be 0, which is default condition\n if n > 3:\n \n # Init min difference\n min_diff ... | 10 | 0 | ['Sorting', 'Python', 'Python3'] | 4 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | ✅ One Line Solution | one-line-solution-by-mikposp-647m | Code #1\nTime complexity: O(n). Space complexity: O(1).\n\nclass Solution:\n def minDifference(self, a: List[int]) -> int:\n return min(map(sub,nlarge | MikPosp | NORMAL | 2024-07-03T08:16:28.444307+00:00 | 2024-07-03T08:45:27.174699+00:00 | 670 | false | # Code #1\nTime complexity: $$O(n)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n def minDifference(self, a: List[int]) -> int:\n return min(map(sub,nlargest(4,a)[::-1],nsmallest(4,a)))\n```\n\n# Code #2\nTime complexity: $$O(n*log(n))$$. Space complexity: $$O(n)$$.\n```\nclass Solution:\n def minD... | 9 | 0 | ['Array', 'Sorting', 'Python', 'Python3'] | 2 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Easy 3 liner code beats 97.8% users... | easy-3-liner-code-beats-978-users-by-aim-lvqy | 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 | Aim_High_212 | NORMAL | 2024-07-03T02:26:28.682546+00:00 | 2024-07-03T02:26:28.682569+00:00 | 105 | 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)$$ --... | 9 | 0 | ['Array', 'Greedy', 'C', 'Sorting', 'Python', 'C++', 'Python3'] | 0 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Well Explained || 2 Approaches || Easy for mind to Accept it | well-explained-2-approaches-easy-for-min-s8nx | BRUTE APPROACH\n\nclass Solution {\n public int minDifference(int[] nums) {\n int n = nums.length;\n if(n <= 4) return 0;\n Arrays.sort( | hi-malik | NORMAL | 2022-01-03T07:18:12.895501+00:00 | 2022-01-03T07:18:12.895550+00:00 | 811 | false | **BRUTE APPROACH**\n```\nclass Solution {\n public int minDifference(int[] nums) {\n int n = nums.length;\n if(n <= 4) return 0;\n Arrays.sort(nums);\n int res = Integer.MAX_VALUE;\n for(int i = 0; i < 4; i++){\n res = Math.min(res, nums[n - 1 - 3 + i] - nums[i]);\n ... | 9 | 0 | ['Java'] | 2 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Simple JAVA code with detailed explanation | simple-java-code-with-detailed-explanati-g532 | To minimize the diff between the max and min values, we need to alter either the values in the min range or the value in the max range. Here min range means the | prakhar3agrwal | NORMAL | 2021-07-10T15:53:39.001444+00:00 | 2021-07-10T15:59:17.965710+00:00 | 658 | false | To minimize the diff between the max and min values, we need to alter either the values in the min range or the value in the max range. Here min range means the minimum value and the values present close to it, and the max range means the maximum value and the values present close to it in the array. So, we just need t... | 8 | 0 | [] | 0 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [Python] O(N) Time, O(1) Space, beats 100 % without sorting | python-on-time-o1-space-beats-100-withou-9wlm | We only need to find the max 4 and min 4 elements in nums, and It could be done by O(n) time without sorting (O(nlogn)).\n\nclass Solution:\n def minDifferen | licpotis | NORMAL | 2020-11-03T07:27:38.037396+00:00 | 2020-11-03T07:29:05.764096+00:00 | 1,316 | false | We only need to find the max 4 and min 4 elements in nums, and It could be done by O(n) time without sorting (O(nlogn)).\n```\nclass Solution:\n def minDifference(self, nums: List[int]) -> int:\n if len(nums) < 5:\n return 0\n \n maxV, minV = [-float(\'inf\')] * 4, [float(\'inf\')] * ... | 8 | 1 | ['Python', 'Python3'] | 1 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | [Python] O(n) time O(1) space - Two heaps solution | python-on-time-o1-space-two-heaps-soluti-5fvr | Explanation:\n First, handle the case for n<=4 is easy as it means the diff will be 0 always. so let\'s assume n >= 5.\n Basically the max | theleetman | NORMAL | 2020-07-11T16:08:00.448526+00:00 | 2020-07-11T16:08:15.284534+00:00 | 1,038 | false | Explanation:\n First, handle the case for n<=4 is easy as it means the diff will be 0 always. so let\'s assume n >= 5.\n Basically the max diff is determined by the diff between the biggest and smallest element.\n Our options to remove elements are only to remove 3 elements between the ... | 8 | 3 | [] | 6 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | ✔️ 100% Fastest TypeScript Solution | 100-fastest-typescript-solution-by-serge-v7eo | \nfunction minDifference(nums: number[]): number {\n if (nums.length <= 4) return 0\n\n nums.sort((a, b) => a - b)\n\n let opts = [\n nums[nums.length - 4 | sergeyleschev | NORMAL | 2022-03-29T05:05:41.138936+00:00 | 2022-03-30T16:40:53.703998+00:00 | 479 | false | ```\nfunction minDifference(nums: number[]): number {\n if (nums.length <= 4) return 0\n\n nums.sort((a, b) => a - b)\n\n let opts = [\n nums[nums.length - 4] - nums[0],\n nums[nums.length - 3] - nums[1],\n nums[nums.length - 2] - nums[2],\n nums[nums.length - 1] - nums[3],\n ]\n\n return Math.min(...o... | 7 | 0 | ['TypeScript', 'JavaScript'] | 1 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | O(n) time and O(1) space solution Python | on-time-and-o1-space-solution-python-by-ng1qr | The hardest part of this problem is recognizing the trick. The value you change the numbers in the array to need not be calculated, so changed values can be tre | ck7aj | NORMAL | 2021-10-19T16:38:26.550881+00:00 | 2021-10-19T16:38:26.550920+00:00 | 982 | false | The hardest part of this problem is recognizing the trick. The value you change the numbers in the array to need not be calculated, so changed values can be treated as though they are removed entirely. Also, notice that removing elements will never increase the spread of the numbers in an array, so we will use all 3 of... | 7 | 0 | ['Heap (Priority Queue)', 'Python'] | 2 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | JAVA beats 100% | Clear Explanation | java-beats-100-clear-explanation-by-shah-6rj3 | Its actually pretty simple. If you think, we dont need to change any values, it is just that we need to remove any 3 numbers, such that max - min is the least. | shahrukhitsme | NORMAL | 2021-07-10T09:55:05.637110+00:00 | 2021-07-10T14:12:39.237014+00:00 | 545 | false | Its actually pretty simple. If you think, we dont need to change any values, it is just that we need to remove any 3 numbers, such that max - min is the least. Now if you sort the array, the best ways to remove the numbers are at the ends, becuase then only you would be able to lessen the range. So you can remove the n... | 7 | 1 | [] | 3 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | Beats 100%|| Simple and Easy Solution||Properly explained||T.C:O(n log n)|| | beats-100-simple-and-easy-solutionproper-b84j | Intuition\nIf the array has fewer than 5 elements (n < 5), it returns 0.\nBy sorting the array first, we can easily access the smallest and largest values.\nFor | twaritagrawal | NORMAL | 2024-07-03T04:28:11.815262+00:00 | 2024-07-03T04:28:11.815317+00:00 | 459 | false | # Intuition\nIf the array has fewer than 5 elements (n < 5), it returns 0.\nBy sorting the array first, we can easily access the smallest and largest values.\nFor arrays with 5 or more elements, the strategy to minimize the range would be to either raise the value of the smallest numbers or lower the value of the large... | 6 | 0 | ['Array', 'Math', 'Greedy', 'Brainteaser', 'Sorting', 'C++'] | 1 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | try all combos | solution for generic k moves | try-all-combos-solution-for-generic-k-mo-8w8r | Intuition & Approach\n\nFirst note that instead of "changing" the elements, we can simply remove them instead, since we\'re allowed to change them to any value, | jyscao | NORMAL | 2024-07-03T03:48:20.009662+00:00 | 2024-07-03T04:17:20.736814+00:00 | 1,495 | false | # Intuition & Approach\n\nFirst note that instead of "changing" the elements, we can simply remove them instead, since we\'re allowed to change them to any value, which means we can always change the chosen elements to the median of the input, thereby making their remaining presence in the array inconsequential.\n\nNow... | 6 | 0 | ['Sorting', 'Python3'] | 5 |
minimum-difference-between-largest-and-smallest-value-in-three-moves | A concise solution | a-concise-solution-by-jaihindh-u5ox | If there are 4 or less elements in it, we\'re going to be left with 1 element at most, making the difference b/w min and max 0.\nIf there are more elements, the | jaihindh | NORMAL | 2021-04-22T16:32:01.304971+00:00 | 2021-04-22T16:39:52.128672+00:00 | 425 | false | If there are 4 or less elements in it, we\'re going to be left with 1 element at most, making the difference b/w min and max 0.\nIf there are more elements, then we have one of these four choices:\n1. get rid of the 3 biggest elements.\n2. get rid of 2 biggest elements, and the smallest.\n3. get rid of the biggest elem... | 6 | 0 | ['Heap (Priority Queue)', 'Python'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.