question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
minimum-amount-of-time-to-collect-garbage
Best Java Solution || Beats 100%
best-java-solution-beats-100-by-ravikuma-cyuz
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
ravikumar50
NORMAL
2023-11-20T02:56:03.023507+00:00
2023-11-20T02:56:03.023537+00:00
239
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
['Java']
3
minimum-amount-of-time-to-collect-garbage
✅ 100% || 🚀 Greedy Approach ||
100-greedy-approach-by-lazy_coder007-l6mn
\n\n# C++ Result:\n\n\n# Python Result:\n\n\n# Java Result:\n\n\n# Intuition:\nHere we are given a list of garbage and a list of travel times. We need to find t
Lazy_Coder007
NORMAL
2023-11-20T00:31:08.903910+00:00
2023-11-20T00:31:08.903941+00:00
943
false
\n\n# C++ Result:\n![Screenshot 2023-11-20 at 5.50.53\u202FAM.png](https://assets.leetcode.com/users/images/c0d70d54-531f-438f-b623-70d26a06202e_1700439683.2697353.png)\n\n# Python Result:\n![Screenshot 2023-11-20 at 5.51.42\u202FAM.png](https://assets.leetcode.com/users/images/5a0b91fd-29b8-4a69-94fb-6ef9b9947859_1700...
3
0
['Array', 'Greedy', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3']
1
minimum-amount-of-time-to-collect-garbage
Python O(n)
python-on-by-shubhlaxh_porwal-v9d9
Intuition\n Describe your first thoughts on how to solve this problem. \nThe code is implementing a garbage collection algorithm that calculates the total dista
shubhlaxh_porwal
NORMAL
2023-06-20T07:08:59.697128+00:00
2023-06-20T07:08:59.697161+00:00
54
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code is implementing a garbage collection algorithm that calculates the total distance traveled by a garbage truck based on the type of garbage collected at each house and the travel distances between consecutive houses. The types of ...
3
0
['String', 'Python3']
1
minimum-amount-of-time-to-collect-garbage
Easy Java Solution || Beats 97% online submissions
easy-java-solution-beats-97-online-submi-sq1i
Code\n\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int ans = 0;\n \n int g = 0, m = 0, p = 0;\n
Viraj_Patil_092
NORMAL
2023-04-27T06:47:57.286400+00:00
2023-04-27T06:47:57.286443+00:00
489
false
# Code\n```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int ans = 0;\n \n int g = 0, m = 0, p = 0;\n\n for(int i = garbage.length-1;i >= 0;i--){\n if(garbage[i].contains("G")){\n g = i;\n break;\n ...
3
0
['Array', 'String', 'Prefix Sum', 'Java']
0
minimum-amount-of-time-to-collect-garbage
JAVA | solution in function
java-solution-in-function-by-firdavs06-j16a
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
Firdavs06
NORMAL
2023-02-26T12:04:01.232595+00:00
2023-02-26T12:04:01.232627+00:00
321
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
['Java']
0
minimum-amount-of-time-to-collect-garbage
[Python3] 'One-liner' || Beats 100% || O(n)/O(n)🚛
python3-one-liner-beats-100-onon-by-gepr-8m94
Intuition\n Describe your first thoughts on how to solve this problem. \nWe want to know two things about our garbage collection:\n\nThe number of bins to colle
gepru
NORMAL
2023-01-14T03:46:13.878212+00:00
2023-11-20T11:04:41.504265+00:00
636
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe want to know two things about our garbage collection:\n\nThe number of bins to collect (1 minute each), and the number of houses each truck must travel to in order to collect all bins of their waste type (`travel` summed up to the last...
3
0
['Python3']
1
minimum-amount-of-time-to-collect-garbage
c++ O(n*m) solution, constant space
c-onm-solution-constant-space-by-augus7-q2w1
\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity: O(n * m)\n Add your time complexity here, e.g. O(n) \n\n- Space complexit
Augus7
NORMAL
2023-01-10T14:14:24.123411+00:00
2023-01-10T14:14:24.123458+00:00
627
false
\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n * m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int garbageCollection(v...
3
0
['Array', 'String', 'Prefix Sum', 'C++']
0
minimum-amount-of-time-to-collect-garbage
Short || Clean || HashMap || Java Solution
short-clean-hashmap-java-solution-by-him-ul28
\njava []\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n Map<String,Integer> map = new HashMap();\n for(i
HimanshuBhoir
NORMAL
2023-01-05T07:57:37.554985+00:00
2023-01-05T07:57:37.555047+00:00
554
false
\n```java []\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n Map<String,Integer> map = new HashMap();\n for(int i=1; i<travel.length; i++) travel[i] += travel[i-1];\n for(int i=1; i<garbage.length; i++){\n if(garbage[i].contains("M")) map.put("...
3
0
['Java']
0
minimum-amount-of-time-to-collect-garbage
Simulation
simulation-by-fllght-pfif
Java\njava\npublic int garbageCollection(String[] garbage, int[] travel) {\n int totalTime = 0;\n\n for (int house = 0, metal = 0, glass = 0, plas
FLlGHT
NORMAL
2022-08-28T13:14:12.230938+00:00
2022-08-28T13:14:12.230977+00:00
117
false
##### *Java*\n```java\npublic int garbageCollection(String[] garbage, int[] travel) {\n int totalTime = 0;\n\n for (int house = 0, metal = 0, glass = 0, plastic = 0; house < garbage.length; ++house) {\n String currentHouse = garbage[house];\n if (currentHouse.contains("M")) {\n ...
3
0
['C', 'Java']
0
minimum-amount-of-time-to-collect-garbage
O(1) Memory | O(n) time
o1-memory-on-time-by-nadaralp-ed41
Only 1 garbage truck can move at a time. This directly tells us that this problem IS NOT A DP because we can calculate it with simulations/greedy.\n\nEvery truc
nadaralp
NORMAL
2022-08-28T09:00:09.984170+00:00
2022-08-28T09:01:37.231493+00:00
64
false
Only 1 garbage truck can move at a time. This directly tells us that this problem **IS NOT A DP** because we can calculate it with simulations/greedy.\n\nEvery truck must move one index at a time, stopping at the latest index that has it\'s material type (paper, glass, etc). Because from that point onwards there is no ...
3
0
[]
0
minimum-amount-of-time-to-collect-garbage
O(n) solution
on-solution-by-aniketpanchal52648-8r7o
\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n // vector<char> t={\'G\',\'P\'};\n vector
aniketpanchal52648
NORMAL
2022-08-28T08:54:12.801978+00:00
2022-08-28T08:58:19.482494+00:00
94
false
```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n // vector<char> t={\'G\',\'P\'};\n vector<pair<char,int>> t;\n t.push_back({\'M\',-1});\n t.push_back({\'P\',-1});\n t.push_back({\'G\',-1});\n int n=garbage.size();\...
3
0
[]
2
minimum-amount-of-time-to-collect-garbage
Constant Space java solution
constant-space-java-solution-by-siddhant-627i
```\nclass Solution {\n public int garbageCollection(String[] g, int[] t) {\n int a[]=new int[3];\n int k=g.length;\n String c[] = {"M",
Siddhant_1602
NORMAL
2022-08-28T08:17:06.593291+00:00
2022-08-28T08:17:06.593402+00:00
76
false
```\nclass Solution {\n public int garbageCollection(String[] g, int[] t) {\n int a[]=new int[3];\n int k=g.length;\n String c[] = {"M", "P", "G"};\n for(int i=0;i<3;i++)\n {\n for(int j=k-1;j>=0;j--)\n {\n if(g[j].contains(c[i]))\n ...
3
0
['Java']
0
minimum-amount-of-time-to-collect-garbage
Rust
rust-by-wallicent-h58w
This is my unaltered submission to the 2022-08-28 Weekly Contest 308. We have to know how many \'P\'s, \'M\'s and \'G\'s there are in total (1 minute to process
wallicent
NORMAL
2022-08-28T07:49:40.156060+00:00
2022-08-28T07:49:40.156098+00:00
88
false
This is my unaltered submission to the 2022-08-28 Weekly Contest 308. We have to know how many \'P\'s, \'M\'s and \'G\'s there are in total (1 minute to process each letter). We also want to know the position of the last of each letter, since then the truck doesn\'t have to travel further. We need to know the sum of tr...
3
0
['Rust']
0
minimum-amount-of-time-to-collect-garbage
Swift solution (Brute force O(n))
swift-solution-brute-force-on-by-andreev-anqa
\nclass Solution {\n func garbageCollection(_ garbage: [String], _ travel: [Int]) -> Int {\n "MGP".map{ collectGarbage(garbage, travel + [0], type: $0
AndreevIVdev
NORMAL
2022-08-28T06:13:13.554031+00:00
2022-08-28T06:13:13.554081+00:00
104
false
```\nclass Solution {\n func garbageCollection(_ garbage: [String], _ travel: [Int]) -> Int {\n "MGP".map{ collectGarbage(garbage, travel + [0], type: $0) }.reduce(0, +)\n }\n \n private func collectGarbage(_ garbage: [String], _ travel: [Int], type: Character) -> Int {\n var time = 0\n ...
3
0
['Swift']
1
minimum-amount-of-time-to-collect-garbage
C++ frequency count O(N) solution
c-frequency-count-on-solution-by-abhay53-v25y
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\n\nclass Solution {\npublic:\n\n int garbageCollection(vector<string>& garbage, ve
abhay5349singh
NORMAL
2022-08-28T04:03:13.503625+00:00
2023-07-14T03:51:13.470749+00:00
62
false
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n```\nclass Solution {\npublic:\n\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n vector<vector<int>> freq(garbage.size(),vector<int> (3,0)); // frequency for each type of garbage for all indexes\n ...
3
2
[]
0
minimum-amount-of-time-to-collect-garbage
c++ hashmap easy solution
c-hashmap-easy-solution-by-chandakji2204-c6t9
\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n map<int,vector<int>> house;\n vector<int>
chandakji2204
NORMAL
2022-08-28T04:01:55.296373+00:00
2022-08-28T04:01:55.296408+00:00
100
false
```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n map<int,vector<int>> house;\n vector<int> last(3);\n for(int i=0;i<garbage.size();i++){\n house[i]={0,0,0}; \n for(char& c:garbage[i]){\n if(c==\'G\')\n ...
3
0
['C']
1
minimum-amount-of-time-to-collect-garbage
Ho gya re abbbaaa wah ji wah :D socha ki nhi hoga aur karna kaam lekin ho gyaaaaaaaaaaaaaaaaaaaaaaaa
ho-gya-re-abbbaaa-wah-ji-wah-d-socha-ki-jaz2d
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
yesyesem
NORMAL
2024-10-12T17:26:48.124207+00:00
2024-10-12T17:26:48.124239+00:00
11
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
0
['C++']
0
minimum-amount-of-time-to-collect-garbage
Counting || C++, Python, Java
counting-c-python-java-by-not_yl3-aqm3
Approach\n Describe your approach to solving the problem. \nWe only need to sum up all the minutes ending at the last house with each garbage type. We can use s
not_yl3
NORMAL
2024-05-11T23:45:45.732648+00:00
2024-05-11T23:57:28.274284+00:00
70
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe only need to sum up all the minutes ending at the last house with each garbage type. We can use some boolean variables `metal`, `paper`, and `glass` to keep track of when we need to start adding the minutes. In each iteration also add the length of...
2
0
['Array', 'String', 'C', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3']
0
minimum-amount-of-time-to-collect-garbage
C++ || Single For Loop || O(n) || O(1) space
c-single-for-loop-on-o1-space-by-prajnan-yohj
Approach\n\n- In the scenario described, the garbage truck needs to visit the houses sequentially, starting from the 0th index. It\'s not necessary for the truc
prajnanam
NORMAL
2024-04-21T07:28:25.249730+00:00
2024-04-21T07:31:00.123524+00:00
133
false
# Approach\n\n- In the scenario described, the garbage truck needs to visit the houses sequentially, starting from the 0th index. It\'s not necessary for the truck to visit all the houses; it should stop at the last index where G, M, or P appears. After that point, the truck shouldn\'t visit any more houses, as our goa...
2
0
['Prefix Sum', 'C++']
0
minimum-amount-of-time-to-collect-garbage
using prefixsum || simple c++ approach||only one iteration||beginner friendly approach
using-prefixsum-simple-c-approachonly-on-574u
Intuition\n1. we need to calculate prefix sum of travel array of one length more than travel array in which first element is zero for avoiding overflow.\n2. we
Faiizzz786
NORMAL
2024-01-03T19:17:58.319705+00:00
2024-01-04T08:37:00.603582+00:00
10
false
# Intuition\n1. we need to calculate prefix sum of travel array of one length more than travel array in which first element is zero for avoiding overflow.\n2. we need to calculate frequency of \'G\',\'P\' and \'M\' and their last index i.e; its last city.(note: last index helps to minimize the result).\n\n\n# Approach\...
2
0
['C++']
1
minimum-amount-of-time-to-collect-garbage
Simple and Intuitive Java Solution
simple-and-intuitive-java-solution-by-ra-oksi
Intuition\nIf you examine the testcases carefully you will notice for each garbage truck the distance they will travel is the highest index that has at least 1
rainvert
NORMAL
2023-11-20T21:36:24.823414+00:00
2023-11-20T21:36:24.823442+00:00
20
false
# Intuition\nIf you examine the testcases carefully you will notice for each garbage truck the distance they will travel is the highest index that has at least 1 unit of that type of garbage.\n\nSo if you just count all the letters along with noting the highest index of each type of garbage, the problem can be solved o...
2
0
['Java']
0
minimum-amount-of-time-to-collect-garbage
No HashMap | Easy and Intuitive
no-hashmap-easy-and-intuitive-by-spats7-9x4e
```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int[] time = new int[3];\n \n for(int i=garbage
spats7
NORMAL
2023-11-20T19:02:23.646508+00:00
2023-11-20T19:02:23.646536+00:00
23
false
```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int[] time = new int[3];\n \n for(int i=garbage.length-1; i>=0; i--){\n \n for(char c : garbage[i].toCharArray()){\n int idx = c == \'P\' ? 0 : (c==\'M\' ? 1 : 2);\n ...
2
0
['Array', 'Java']
0
minimum-amount-of-time-to-collect-garbage
✅Python || Beats 100% || O(n)
python-beats-100-on-by-ruzibekoff-miy3
\n\n# Problem\nThe problem is asking to minimize the time taken to collect all the garbage. We have three types of garbage and three trucks, each responsible fo
ruzibekoff
NORMAL
2023-11-20T15:21:00.357619+00:00
2023-11-20T15:21:00.357648+00:00
222
false
![Screenshot 2023-11-20 194617.png](https://assets.leetcode.com/users/images/d66ea612-fa5d-42a5-adf6-2db785cf6dd6_1700491643.967531.png)\n\n# Problem\nThe problem is asking to minimize the time taken to collect all the garbage. We have three types of garbage and three trucks, each responsible for one type of garbage. T...
2
0
['Python3']
2
minimum-amount-of-time-to-collect-garbage
populating hashtable in o[n] then counting no of operations
populating-hashtable-in-on-then-counting-6xhy
\n\n# Complexity\n- Time complexity:\no[n]\n\n\n# Code\n\nclass Solution(object):\n def garbageCollection(self, garbage, travel):\n hash = {}\n
AdhamEhabElsheikh
NORMAL
2023-11-20T10:17:48.875437+00:00
2023-11-20T10:17:48.875459+00:00
92
false
\n\n# Complexity\n- Time complexity:\no[n]\n\n\n# Code\n```\nclass Solution(object):\n def garbageCollection(self, garbage, travel):\n hash = {}\n string = \' \'.join(garbage) \n counter = 0 \n \n for char in string:\n if char != \' \':\n if char not in hash...
2
0
['Python']
0
minimum-amount-of-time-to-collect-garbage
Beats 100%🔥|| easy JAVA Solution✅
beats-100-easy-java-solution-by-priyansh-oood
Code\n\nclass Solution {\n public int garbageCollection(String[] g, int[] t) {\n int ans=0;\n for(int i:t){\n ans+=i;\n }\n
priyanshu1078
NORMAL
2023-11-20T08:28:25.022572+00:00
2023-11-20T08:28:25.022592+00:00
26
false
# Code\n```\nclass Solution {\n public int garbageCollection(String[] g, int[] t) {\n int ans=0;\n for(int i:t){\n ans+=i;\n }\n ans*=3;\n for(String i:g) ans+=i.length();\n for(int i=g.length-1;i>0;i--){\n if(!g[i].contains("M")) ans-=t[i-1];\n ...
2
0
['Java']
0
minimum-amount-of-time-to-collect-garbage
Beats 83.88% in Runtime and 91.88% in Memory | C++ | JavaScript
beats-8388-in-runtime-and-9188-in-memory-6y2g
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
Nurliaidin
NORMAL
2023-11-20T08:03:47.496892+00:00
2023-11-20T08:03:47.496927+00:00
612
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
0
['C++', 'JavaScript']
1
minimum-amount-of-time-to-collect-garbage
Video Solution | Explanation With Drawings | In Depth | Java | C++
video-solution-explanation-with-drawings-rywl
Intuition, approach, and complexity discussed in detail in video solution\nhttps://youtu.be/43u8AipcfOk\n\n# Code\nC++\n\nclass Solution {\npublic:\n int gar
Fly_ing__Rhi_no
NORMAL
2023-11-20T06:23:35.346993+00:00
2023-11-20T06:24:47.490278+00:00
675
false
# Intuition, approach, and complexity discussed in detail in video solution\nhttps://youtu.be/43u8AipcfOk\n\n# Code\nC++\n```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n long long totalTimeToPick = 0, sz = garbage.size();\n unordered_map<char, in...
2
0
['C++', 'Java']
1
minimum-amount-of-time-to-collect-garbage
Simple python solution for beginners
simple-python-solution-for-beginners-by-fkmqx
\n\n# Code\n\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n garbage.reverse()\n sum=0\n
Dhaxina
NORMAL
2023-11-20T06:08:31.129257+00:00
2023-11-20T06:08:31.129277+00:00
34
false
\n\n# Code\n```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n garbage.reverse()\n sum=0\n for x in travel:\n sum+=x\n sum*=3\n for i in range(len(garbage)-1):\n if \'G\' not in garbage[i]:\n sum-...
2
0
['Math', 'Python', 'Python3']
0
minimum-amount-of-time-to-collect-garbage
C++ Solution
c-solution-by-pranto1209-07tf
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n O(N * K)\n Where N is garbage.length and K is garbage[i].length\n\n- Space c
pranto1209
NORMAL
2023-11-20T05:56:36.902763+00:00
2023-11-20T05:56:36.902786+00:00
6
false
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(N * K)\n Where N is garbage.length and K is garbage[i].length\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n O(1)\n\n# Code\n```\nclass Solution {\npublic:\n int garbageCollection(v...
2
0
['C++']
0
minimum-amount-of-time-to-collect-garbage
C++ | Easy code | Beat 95%
c-easy-code-beat-95-by-ankita2905-r6qk
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
Ankita2905
NORMAL
2023-11-20T04:33:46.066378+00:00
2023-11-20T04:33:46.066396+00:00
8
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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
0
['C++']
0
minimum-amount-of-time-to-collect-garbage
[C++] Simple Solution without Prefix Sum
c-simple-solution-without-prefix-sum-by-qo42d
Intuition\n Describe your first thoughts on how to solve this problem. \n- We can simulate the garbage collection for each truck separately\n - All trucks are
pepe-the-frog
NORMAL
2023-11-20T04:30:21.861908+00:00
2023-11-20T04:30:21.861930+00:00
261
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We can simulate the garbage collection for each truck separately\n - All trucks are independent, because ```Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks ...
2
0
['Hash Table', 'Simulation', 'Counting', 'C++']
0
minimum-amount-of-time-to-collect-garbage
Easy Python Solution || Beats 94% in Runtime
easy-python-solution-beats-94-in-runtime-u9la
\n\n# Approach\n1. Keep track of index of the last occurance of each garbage.\n2. Also keep track of frequency of Each letter. (You can maintain a single variab
pranav743
NORMAL
2023-11-20T03:59:55.949273+00:00
2023-11-20T04:04:30.984849+00:00
161
false
![image.png](https://assets.leetcode.com/users/images/1bc23daa-4b60-4c7d-8c40-9bb8312ad521_1700452494.021158.png)\n\n# Approach\n1. Keep track of index of the last occurance of each garbage.\n2. Also keep track of frequency of Each letter. (You can maintain a single variable which stores total freq of each letter, here...
2
0
['Python3']
2
minimum-amount-of-time-to-collect-garbage
Easy Intuitive solution using Hashmap and Prefix Sum
easy-intuitive-solution-using-hashmap-an-yl79
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \ntravel time(taking pref
yashaswisingh47
NORMAL
2023-11-20T03:43:15.722193+00:00
2023-11-20T03:43:15.722221+00:00
592
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ntravel time(taking prefix sum) will give us the time to travel to the particular index and travel_time[last_index[i] - 1] will give us the time to travel to the last i...
2
0
['Hash Table', 'Prefix Sum', 'Python3']
0
minimum-amount-of-time-to-collect-garbage
🫠Simplest_Brute_Force.py🙌
simplest_brute_forcepy-by-jyot_150-bwk0
Code\n\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n def cnt(ch,g):\n gb=[]\n
jyot_150
NORMAL
2023-11-20T03:32:28.342454+00:00
2023-11-20T03:32:28.342516+00:00
38
false
# Code\n```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n def cnt(ch,g):\n gb=[]\n for i in g:gb.append(i.count(ch))\n for i in range(len(gb)-1,-1,-1):\n if gb[i]==0:gb.pop()\n else:break\n ...
2
0
['Python3']
1
minimum-amount-of-time-to-collect-garbage
C# Solution for Minimum Amount of Time to Collect Garbage Problem
c-solution-for-minimum-amount-of-time-to-s35n
Intuition\n Describe your first thoughts on how to solve this problem. \n1.\tPrefix Sum Calculation: The solution calculates the prefix sum of travel times, pro
Aman_Raj_Sinha
NORMAL
2023-11-20T03:08:48.263489+00:00
2023-11-20T03:08:48.263508+00:00
163
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1.\tPrefix Sum Calculation: The solution calculates the prefix sum of travel times, providing the accumulated time from the 0th house to the i-th house.\n2.\tMapping Last House Index and Garbage Count: It maps each garbage type to its las...
2
0
['C#']
0
minimum-amount-of-time-to-collect-garbage
Java Solution for Minimum Amount of Time to Collect Garbage Problem
java-solution-for-minimum-amount-of-time-01y4
Intuition\n Describe your first thoughts on how to solve this problem. \n1.\tTravel Time Calculation: The first loop modifies the travel array to hold the prefi
Aman_Raj_Sinha
NORMAL
2023-11-20T03:00:39.180878+00:00
2023-11-20T03:00:39.180910+00:00
442
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1.\tTravel Time Calculation: The first loop modifies the travel array to hold the prefix sum of travel times. This step ensures that travel[i] holds the total time taken to travel from the 0th house to the i-th house.\n2.\tGarbage Type an...
2
0
['Java']
2
minimum-amount-of-time-to-collect-garbage
16 line Simple C++ Solution
16-line-simple-c-solution-by-yashmenaria-75tn
\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n#
yashmenaria
NORMAL
2023-11-20T02:17:13.197789+00:00
2023-11-20T02:17:13.197811+00:00
10
false
\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n int res = 0;\n ...
2
0
['C++']
0
minimum-amount-of-time-to-collect-garbage
Python3 Solution
python3-solution-by-motaharozzaman1996-rlp2
\n\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n ans=0\n n=len(garbage)\n for c in "MP
Motaharozzaman1996
NORMAL
2023-11-20T01:36:42.411017+00:00
2023-11-20T01:36:42.411054+00:00
132
false
\n```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n ans=0\n n=len(garbage)\n for c in "MPG":\n best=0\n cur=0\n cur+=garbage[0].count(c)\n best=max(cur,best)\n for i in range(1,n):\n ...
2
0
['Python', 'Python3']
1
minimum-amount-of-time-to-collect-garbage
🔥💥 C++ Simple Solution Using HashMap💥🔥
c-simple-solution-using-hashmap-by-eknat-ghka
Intuition\n Describe your first thoughts on how to solve this problem. \nThe approach involves iterating through the given houses and their respective garbage,
eknath_mali_002
NORMAL
2023-11-20T01:05:19.006789+00:00
2023-11-20T01:05:19.006808+00:00
682
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe approach involves iterating through the given houses and their respective garbage, keeping track of the `last occurrence of each type of garbage`. Then, simulate the traversal of each type of garbage truck through the houses while cal...
2
0
['Array', 'Hash Table', 'String', 'C++']
1
minimum-amount-of-time-to-collect-garbage
✅ Python3 || 🚀 Count || ⭐️ Thoroughly Explanation and Clean code ⭐️
python3-count-thoroughly-explanation-and-ikqp
Intuition\nIt is hard to understand the description of this problem, if we focus on meaning of it we realize that calculating each step when it picked a garbage
lutfullo_m
NORMAL
2023-11-14T11:38:39.638068+00:00
2023-12-12T16:14:39.752248+00:00
11
false
# Intuition\nIt is hard to understand the description of this problem, if we focus on meaning of it we realize that calculating each step when it picked a garbage and moving every house accrording to travel distance is our work.\n\n# Approach\n1. First, we assign a variable to calculatin each step` s minutes as well as...
2
0
['Counting', 'Iterator', 'Python3']
0
minimum-amount-of-time-to-collect-garbage
99% Faster✅ 86% Less Memory✅ Clean Explained C++ Code
99-faster-86-less-memory-clean-explained-l7an
Intuition\nAll kinds of elements take same amount of time to be picked up, their difference only matters to calculate the no. of trips to be made.\nSo calculate
ayunick
NORMAL
2023-07-29T18:23:38.921945+00:00
2023-07-29T18:23:38.921994+00:00
20
false
# Intuition\nAll kinds of elements take same amount of time to be picked up, their difference only matters to calculate the no. of trips to be made.\nSo calculate the last index (and eventually time) upto which truck will need to go for each type of garbage.\n# Approach\nCalculate prefix travel array, travel[i] = time ...
2
0
['Array', 'String', 'Prefix Sum', 'C++']
0
minimum-amount-of-time-to-collect-garbage
Easy Peasy implementation C++
easy-peasy-implementation-c-by-ajay_1134-8nrb
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ajay_1134
NORMAL
2023-05-11T02:47:13.778139+00:00
2023-05-11T02:47:13.778185+00:00
18
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Array', 'C++']
0
minimum-amount-of-time-to-collect-garbage
💯🚨Prefix Sum | JAVA | Very Easy
prefix-sum-java-very-easy-by-dipesh_12-wy07
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
dipesh_12
NORMAL
2023-05-10T07:32:37.659513+00:00
2023-05-10T07:32:37.659545+00:00
332
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
0
['Java']
0
minimum-amount-of-time-to-collect-garbage
Minimum Amount of Time to Collect Garbage Solution in C++
minimum-amount-of-time-to-collect-garbag-6qns
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
The_Kunal_Singh
NORMAL
2023-04-16T07:07:01.154194+00:00
2023-04-27T16:34:13.065099+00:00
253
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)$$ -->\nO(n^2)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n...
2
0
['C++']
0
minimum-amount-of-time-to-collect-garbage
EASY TO UNDERSTANDING || C++
easy-to-understanding-c-by-tapabrata_007-7uoi
\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) O(n^2)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) O(1)\n\n
tapabrata_007
NORMAL
2023-04-01T09:10:22.653131+00:00
2023-04-01T09:10:22.653167+00:00
381
false
\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(n^2)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(1)\n\n# Code\n```\nclass Solution\n{\npublic:\n\tint garbageCollection(vector<string> &garbage, vector<int> &travel)\n\t{\n\t\tint answer = 0;\n...
2
0
['Array', 'Prefix Sum', 'C++']
0
minimum-amount-of-time-to-collect-garbage
Faster Than 99% C++ Solution
faster-than-99-c-solution-by-anish25-l3q3
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
Anish25
NORMAL
2023-01-11T13:04:57.204795+00:00
2023-01-11T13:04:57.204840+00:00
295
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- O(1)\n<!-- Add your space complexity here, e.g. $$O...
2
0
['C++']
0
minimum-amount-of-time-to-collect-garbage
✅✅✅ very easy to understand solution using python arrays
very-easy-to-understand-solution-using-p-klf7
\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n travel.insert(0, 0)\n answer, trash = [0, 0, 0
Najmiddin1
NORMAL
2023-01-03T03:40:40.251955+00:00
2023-01-03T03:40:40.252014+00:00
390
false
```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n travel.insert(0, 0)\n answer, trash = [0, 0, 0], [0, 0, 0]\n for i, v in enumerate(garbage):\n trash = [trash[0]+travel[i], trash[1]+travel[i], trash[2]+travel[i]]\n paper, g...
2
0
['Python', 'Python3']
1
minimum-amount-of-time-to-collect-garbage
✅ [Rust] 22 ms, fastest (100%) & concise solution using smart counting (with detailed comments)
rust-22-ms-fastest-100-concise-solution-4s7e4
This solution employs a smart counting technique to calculate total time. It demonstrated 22 ms runtime (100.00%) and used 9.3 MB memory (25.00%). Time complexi
stanislav-iablokov
NORMAL
2022-10-05T10:12:56.241348+00:00
2022-10-23T12:44:36.532864+00:00
67
false
This [**solution**](https://leetcode.com/submissions/detail/815668646/) employs a smart counting technique to calculate total time. It demonstrated **22 ms runtime (100.00%)** and used **9.3 MB memory (25.00%)**. Time complexity is linear: **O(N)**. Space complexity is constant: **O(1)**. Detailed comments are provided...
2
0
['Rust']
0
minimum-amount-of-time-to-collect-garbage
easy python solution
easy-python-solution-by-sghorai-iu3r
\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n counter = 0 \n garbageDict = {}\n for i
sghorai
NORMAL
2022-09-30T03:02:31.414934+00:00
2022-09-30T03:02:31.414974+00:00
115
false
```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n counter = 0 \n garbageDict = {}\n for i in range(len(garbage)) : \n counter += len(garbage[i])\n if \'G\' in garbage[i] : \n garbageDict[\'G\'] = i\n ...
2
0
['Prefix Sum', 'Python', 'Python3']
0
minimum-amount-of-time-to-collect-garbage
JAVA solution | Prefix sum | Easy
java-solution-prefix-sum-easy-by-sourin_-qdmt
Please Upvote !!! (\u25E0\u203F\u25E0)\n\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int glassLastIdx = 0, pl
sourin_bruh
NORMAL
2022-09-22T09:41:21.832660+00:00
2022-09-22T09:44:07.996312+00:00
146
false
### Please Upvote !!! **(\u25E0\u203F\u25E0)**\n```\nclass Solution {\n public int garbageCollection(String[] garbage, int[] travel) {\n int glassLastIdx = 0, plasticLastIdx = 0, metalLastIdx = 0;\n int totalTime = 0;\n\n for (int i = 0; i < garbage.length; i++) {\n // if m/g/p seen a...
2
0
['Prefix Sum', 'Java']
0
minimum-amount-of-time-to-collect-garbage
𝗖++ | 𝗣𝗥𝗘𝗙𝗜𝗫 𝗦𝗨𝗠 | 𝗛𝗔𝗦𝗛𝗠𝗔𝗣
c-prefix-sum-hashmap-by-nikhil1947-pg2w
```\nclass Solution {\npublic:\n int garbageCollection(vector& garbage, vector& travel) {\n\t\n unordered_map mp;\n int ans=0;\n\t\t\n for
nikhil1947
NORMAL
2022-09-19T16:20:53.191423+00:00
2022-09-19T16:20:53.191472+00:00
258
false
```\nclass Solution {\npublic:\n int garbageCollection(vector<string>& garbage, vector<int>& travel) {\n\t\n unordered_map<char,int> mp;\n int ans=0;\n\t\t\n for(int i=0;i<garbage.size();i++){\n for(int j=0;j<garbage[i].length();j++){\n mp[garbage[i][j]]=i;\n ...
2
0
['C', 'Prefix Sum']
1
minimum-amount-of-time-to-collect-garbage
PYTHON FASTER THAN 97% !!!!!
python-faster-than-97-by-vansh-grover-o2gu
\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n st=\'\'\n for xx in garbage:\n st+=
Vansh-Grover
NORMAL
2022-09-07T19:25:23.995182+00:00
2022-09-07T19:25:23.995218+00:00
107
false
```\nclass Solution:\n def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:\n st=\'\'\n for xx in garbage:\n st+=xx\n ans=0\n x=-1\n y=-1\n z=-1\n for i in range(len(garbage)):\n if "P" in garbage[i]:\n x=(i)\...
2
0
['Python']
1
minimum-amount-of-time-to-collect-garbage
C
c-by-tinachien-izx3
Runtime: 185 ms, faster than 95.45% of C online submissions for Minimum Amount of Time to Collect Garbage.\nMemory Usage: 27.8 MB, less than 31.82% of C online
TinaChien
NORMAL
2022-09-05T04:03:36.603821+00:00
2022-09-05T04:05:10.750119+00:00
48
false
Runtime: 185 ms, faster than 95.45% of C online submissions for Minimum Amount of Time to Collect Garbage.\nMemory Usage: 27.8 MB, less than 31.82% of C online submissions for Minimum Amount of Time to Collect Garbage.\n```\nint garbageCollection(char ** garbage, int garbageSize, int* travel, int travelSize){\n int ...
2
0
[]
0
special-array-with-x-elements-greater-than-or-equal-x
Simple Java efficient solution beats 100% time and 100% memory
simple-java-efficient-solution-beats-100-7wpm
\nclass Solution {\n public int specialArray(int[] nums) {\n int x = nums.length;\n int[] counts = new int[x+1];\n \n for(int ele
sr1105
NORMAL
2020-10-04T04:59:10.876707+00:00
2020-10-07T01:38:37.236882+00:00
9,902
false
```\nclass Solution {\n public int specialArray(int[] nums) {\n int x = nums.length;\n int[] counts = new int[x+1];\n \n for(int elem : nums)\n if(elem >= x)\n counts[x]++;\n else\n counts[elem]++;\n \n int res = 0;\n ...
94
3
['Java']
14
special-array-with-x-elements-greater-than-or-equal-x
Clean Python 3, O(sort)
clean-python-3-osort-by-lenchen1112-im17
Concept is similar to H-index\nAfter while loop, we can get i which indicates there are already i items larger or equal to i.\nMeanwhile, if we found i == nums[
lenchen1112
NORMAL
2020-10-04T04:02:07.020099+00:00
2020-10-05T11:26:31.902951+00:00
11,268
false
Concept is similar to H-index\nAfter `while` loop, we can get `i` which indicates there are already `i` items larger or equal to `i`.\nMeanwhile, if we found `i == nums[i]`, there will be `i + 1` items larger or equal to `i`, which makes array not special.\nTime: `O(sort)`, can achieve `O(N)` if we use counting sort\nS...
93
1
[]
17
special-array-with-x-elements-greater-than-or-equal-x
✅Detailed Explanation🔥2 Approaches🔥🔥Extremely Simple and effective🔥🔥🔥 Beginner-friendly🔥
detailed-explanation2-approachesextremel-754k
\uD83C\uDFAFProblem Explanation:\nYou are given a list of integers nums and want to find the special number i for which here\'s exactly i numbers greater then o
heir-of-god
NORMAL
2024-05-27T05:42:43.424375+00:00
2024-05-27T05:42:43.424425+00:00
11,494
false
# \uD83C\uDFAFProblem Explanation:\nYou are given a list of integers ```nums``` and want to find the special number ```i``` for which here\'s exactly ```i``` numbers greater then or equal to ```i```. (If ```i``` doesn\'t exist then return -1)\n\n# \uD83D\uDCE5Input:\n- Integer array ```nums```\n\n# \uD83D\uDCE4Output:\...
72
3
['Array', 'Binary Search', 'C', 'Sorting', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']
13
special-array-with-x-elements-greater-than-or-equal-x
🔥🔥 Every Step Explained! A detailed Explanation 😱😱 || 2 Methods
every-step-explained-a-detailed-explanat-oaw7
Approach - 1\n\nLet\'s understand and solve this problem using an example!\n\nInput: nums = [1,2,5,3,4]\nOutput: 3\n\n\nSo, in the starting we will check!\n\n[1
hi-malik
NORMAL
2024-05-27T00:40:31.395551+00:00
2024-05-27T02:30:40.282252+00:00
18,745
false
**Approach - 1**\n\nLet\'s understand and solve this problem using an example!\n```\nInput: nums = [1,2,5,3,4]\nOutput: 3\n```\n\nSo, in the starting we will check!\n```\n[1, 2, 5, 3, 4]\n ^\n```\nIs there one number, i.e. greater than or equals to **1**, **`No`** there are **5** numbers that are greater than or equals...
70
1
['C', 'Python', 'Java']
12
special-array-with-x-elements-greater-than-or-equal-x
C++ 6 different Solutions with analysis
c-6-different-solutions-with-analysis-by-hfip
just for fun\n\n// naive brute force O(N^2)\nbool check(int num, vector<int> &nums) { \n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] >= num)
midokura
NORMAL
2020-10-05T01:57:14.422930+00:00
2020-10-05T02:00:51.694583+00:00
6,018
false
just for fun\n```\n// naive brute force O(N^2)\nbool check(int num, vector<int> &nums) { \n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] >= num) \n return (nums.size() - i) == num; \n }\n return false;\n}\nint specialArray(vector<int>& nums) {\n sort(nums.begin(), n...
61
1
[]
8
special-array-with-x-elements-greater-than-or-equal-x
c++ use counting sort 0ms
c-use-counting-sort-0ms-by-escrowdis-ce35
count the amount of numbers\n2. add the amount backward so we can know how many numbers are no less than the current index.\n\nExample:\n\ninput [0, 4, 3, 0, 4]
escrowdis
NORMAL
2020-10-04T04:02:32.816846+00:00
2020-10-17T21:06:23.809202+00:00
8,910
false
1. count the amount of numbers\n2. add the amount backward so we can know how many numbers are no less than the current index.\n\nExample:\n```\ninput [0, 4, 3, 0, 4]\n\nindex 0 1 2 3 4 0 ... 1000 // the range defined in the question\nv [2, 0, 0, 1, 2, 0, ..., 0]\n# after accumulation\nv [5, 3, 3, 3, 2, ...
54
2
['C', 'C++']
11
special-array-with-x-elements-greater-than-or-equal-x
Java O(nlogn) with easy explanation
java-onlogn-with-easy-explanation-by-ren-0ckz
Explanation: The number we are searching for is any number from zero to length of array. If we sort the array in ascending order, we can iterate through it from
renato4
NORMAL
2020-10-04T04:27:56.170793+00:00
2020-10-04T04:31:41.429044+00:00
5,950
false
**Explanation**: The number we are searching for is any number from `zero` to `length of array`. If we sort the array in ascending order, we can iterate through it from left to right checking if the number of elements until the end and the current value meet the conditions of success. Those are:\n1. The number of eleme...
45
2
[]
7
special-array-with-x-elements-greater-than-or-equal-x
C++ Solution Using Binary Search O(n*log1000) Time and O(1) Space
c-solution-using-binary-search-onlog1000-fzgd
Time Complexity: O(n*log1000)\nSpace Complexity:O(1)\n\nclass Solution {\npublic:\n int solve(vector<int>& nums,int val){\n int count=0;\n for(
AvaraKedavra
NORMAL
2021-06-25T04:03:35.612009+00:00
2021-06-25T04:05:30.733044+00:00
3,374
false
**Time Complexity: O(n*log1000)**\n**Space Complexity:O(1)**\n```\nclass Solution {\npublic:\n int solve(vector<int>& nums,int val){\n int count=0;\n for(int i=0;i<nums.size();++i){\n if(nums[i]>=val){\n ++count;\n }\n }\n return count;\n }\n int...
36
1
['C', 'Binary Tree']
4
special-array-with-x-elements-greater-than-or-equal-x
Python || Sort + Binary Search
python-sort-binary-search-by-nashvenn-ei47
Please upvote if it helps. Thank you!\n\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n l, r = 0, len(nums)
nashvenn
NORMAL
2022-04-07T08:37:12.060309+00:00
2022-04-07T08:38:06.918034+00:00
2,263
false
**Please upvote if it helps. Thank you!**\n```\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n l, r = 0, len(nums) - 1\n while l <= r:\n m = l + (r - l) // 2\n x = len(nums) - m\n if nums[m] >= x:\n if m == 0 or n...
31
0
['Binary Tree', 'Python']
3
special-array-with-x-elements-greater-than-or-equal-x
[Java] Counting Sort - Two Pass Simple Code
java-counting-sort-two-pass-simple-code-z0gg7
\nclass Solution {\n public int specialArray(int[] nums) {\n int[] count = new int[1001];\n for (int num : nums) {\n count[num]++;\n
markyu
NORMAL
2020-10-04T04:07:58.177330+00:00
2020-10-04T20:16:25.467954+00:00
2,373
false
```\nclass Solution {\n public int specialArray(int[] nums) {\n int[] count = new int[1001];\n for (int num : nums) {\n count[num]++;\n }\n int number = nums.length;\n\t\t// the size of nums array is 100 at most\n for (int i = 0; i <= 100; i++) {\n if (number ...
29
3
[]
7
special-array-with-x-elements-greater-than-or-equal-x
Sort/Radix sort + 2 binary search||0ms beats 100%
sortradix-sort-2-binary-search0ms-beats-ymr33
Intuition\n Describe your first thoughts on how to solve this problem. \nSorting at first.\nthen do binary search.\n\n2nd approach uses radix sort with 32 bucke
anwendeng
NORMAL
2024-05-27T02:04:23.429942+00:00
2024-05-27T06:11:38.355008+00:00
5,397
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSorting at first.\nthen do binary search.\n\n2nd approach uses radix sort with 32 buckets.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the array `nums`. The most contribution to TC, i.e. $O(n\\log n)$. Fo...
28
5
['Binary Search', 'Sorting', 'Radix Sort', 'C++']
9
special-array-with-x-elements-greater-than-or-equal-x
[Java] Binary-Search easy solution. 100% faster.
java-binary-search-easy-solution-100-fas-1bnn
[IMP]: In this approach sorting is optional. Dosn\'t affect the time complexity.\nThe least/smallest value can be "0" , eg: [] empty and count==0.\nThe highest
omar_2077
NORMAL
2021-09-22T10:25:40.871919+00:00
2021-09-26T14:44:08.679444+00:00
2,093
false
[IMP]: In this approach sorting is optional. Dosn\'t affect the time complexity.\nThe least/smallest value can be "0" , eg: [] empty and count==0.\nThe highest/maximum can be the "arr.length" ,e.g:[6,7,8,9] length=4 and >=4 count is also 4.\nElse the values lies in middle.\n\nUpvote if useful.\n\n```\nclass Solution {...
21
1
['Binary Tree', 'Java']
7
special-array-with-x-elements-greater-than-or-equal-x
[Java, Beats 100%] Two Binary Search methods and detailed explanation
java-beats-100-two-binary-search-methods-8i5g
First, we can think out if we sort the array, that will be easier for us to find the X. If the array is sorted, for nums[i] there will be len - i numbers that a
dongxiaoran
NORMAL
2020-10-07T04:46:20.906191+00:00
2020-10-07T05:20:11.226448+00:00
3,062
false
First, we can think out if we sort the array, that will be easier for us to find the X. If the array is sorted, for `nums[i]` there will be `len - i` numbers that are greater or equal to `nums[i]`.\nSo one idea by intution is to enumerate each `X` and find the first position that `nums[i] >= X` . Then check `len - i = ...
21
1
['Binary Tree', 'Java']
5
special-array-with-x-elements-greater-than-or-equal-x
[c++][faster than100% + brute force][easy understanding]
cfaster-than100-brute-forceeasy-understa-lu0p
TC: O(n^2) [Brute force]\n\nclass Solution {\npublic:\n int specialArray(vector<int>& nums) {\n for(int i=1;i<1000;i++){\n int cnt=0;\n
rajat_gupta_
NORMAL
2020-10-21T07:27:52.337668+00:00
2020-10-21T07:27:52.337700+00:00
1,941
false
**TC: O(n^2) [Brute force]**\n```\nclass Solution {\npublic:\n int specialArray(vector<int>& nums) {\n for(int i=1;i<1000;i++){\n int cnt=0;\n for(int j=0;j<nums.size();j++){\n if(nums[j]>=i) cnt++;\n }\n if(cnt==i) return i;\n }\n retur...
19
0
['C', 'C++']
3
special-array-with-x-elements-greater-than-or-equal-x
Pythhon | Easy
pythhon-easy-by-khosiyat-z794
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n n = len
Khosiyat
NORMAL
2024-05-27T05:23:20.432420+00:00
2024-05-27T05:23:20.432441+00:00
1,672
false
[see the Successfully Accepted Submission](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/submissions/1269077168/?source=submission-ac)\n\n# Code\n```\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n n = len(nums)\n \n ...
18
1
['Python3']
4
special-array-with-x-elements-greater-than-or-equal-x
Its a simple Binary Search!!
its-a-simple-binary-search-by-ikapoor123-dwwa
Please Upvote \n# Intuition\n Describe your first thoughts on how to solve this problem. \nFind the smallest value of x that makes the array special by using bi
Ikapoor123
NORMAL
2024-05-27T00:40:54.764564+00:00
2024-05-27T06:11:04.791468+00:00
6,649
false
# Please Upvote \n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFind the smallest value of x that makes the array special by using binary search on the sorted array, minimizing the search space at each step based on the count of elements greater than or equal to the current midpoint ...
14
2
['Array', 'Binary Search', 'Sorting', 'C++', 'Java', 'JavaScript']
10
special-array-with-x-elements-greater-than-or-equal-x
✅O(N) Solution || Easy-to-understand || explained
on-solution-easy-to-understand-explained-714a
\nclass Solution {\npublic:\n int specialArray(vector<int>& arr) {\n int n = arr.size();\n vector<int> count(1001,0); // initialize an array w
Arpit507
NORMAL
2022-10-07T09:30:33.861525+00:00
2023-01-15T10:14:24.027388+00:00
1,385
false
```\nclass Solution {\npublic:\n int specialArray(vector<int>& arr) {\n int n = arr.size();\n vector<int> count(1001,0); // initialize an array we know there can maximum 1000 elements\n for(int i = 0;i<n;i++){\n count[arr[i]]++; // store which element comes how many times into coun...
13
1
['C', 'C++']
3
special-array-with-x-elements-greater-than-or-equal-x
100% Faster | Easy to Understand | Brute
100-faster-easy-to-understand-brute-by-g-y2gb
Intuition\n\nAh, the "brute force" approch, where every problem looks like a nail and your solution is a massive hammer! The intuition here is to hit every poss
gameboey
NORMAL
2024-03-20T22:19:21.372839+00:00
2024-05-27T04:09:44.416036+00:00
980
false
# Intuition\n\nAh, the "brute force" approch, where every problem looks like a nail and your solution is a massive hammer! The intuition here is to hit every possible value of `x` with all your might, hoping to strike gold. It\'s like searching for a needle in a haystack by meticulously examining every blade of grass. ...
12
0
['Array', 'C++', 'Java', 'Python3', 'JavaScript']
5
special-array-with-x-elements-greater-than-or-equal-x
Easy Python Solution
easy-python-solution-by-a_bs-73k0
\nIntuition:\n\nThe problem asks us to find a value x in the array (or potentially outside the array) such that there are exactly x elements in the array that a
20250406.A_BS
NORMAL
2024-05-27T02:14:34.142247+00:00
2024-05-27T02:14:34.142267+00:00
1,172
false
\n**Intuition:**\n\nThe problem asks us to find a value `x` in the array (or potentially outside the array) such that there are exactly `x` elements in the array that are greater than or equal to `x`. We can solve this intuitively by iterating through possible values of `x` and checking if the condition holds.\n\n**App...
11
0
['Python3']
3
special-array-with-x-elements-greater-than-or-equal-x
100% C++ || BInary search || O(Nlog(N))
100-c-binary-search-onlogn-by-kunal_j-t3qr
Upvote if it helps...\uD83D\uDE43\t\n\t\n\tint specialArray(vector& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n for(in
Kunal_j
NORMAL
2022-05-09T19:15:34.549475+00:00
2022-05-09T19:15:34.549517+00:00
857
false
Upvote if it helps...\uD83D\uDE43\t\n\t\n\tint specialArray(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n for(int i = 0; i <= n; i++)\n {\n int temp = n;\n int l=0;\n int h=n-1;\n while(h>=l){\n int...
11
0
['C', 'Binary Tree']
1
special-array-with-x-elements-greater-than-or-equal-x
Binary Search Without Sorting the Array
binary-search-without-sorting-the-array-a5mnd
Shorting the array is unnecessary, as its complexity is nLog(n).\nwe can use binary search to point to a number and use linear search to find how many elements
debasishbsws
NORMAL
2022-06-23T05:11:28.487283+00:00
2022-07-22T05:17:03.273205+00:00
935
false
**Shorting the array is unnecessary**, as its complexity is **nLog(n)**.\nwe can use binary search to point to a number and use linear search to find how many elements are greater or equal to the current element\n#### Time Complexity: \n- O(nlog(n) ) where n is array length, \n- O(logN) for binary search. \n- O(n)...
10
0
['Binary Tree', 'Java']
4
special-array-with-x-elements-greater-than-or-equal-x
Java sort loop
java-sort-loop-by-hobiter-urz5
\n public int specialArray(int[] nums) {\n int n = nums.length;\n Arrays.sort(nums);\n for (int i = -1; i < n - 1; i++) \n if
hobiter
NORMAL
2020-10-04T04:03:10.796678+00:00
2020-10-11T04:19:37.058897+00:00
1,156
false
```\n public int specialArray(int[] nums) {\n int n = nums.length;\n Arrays.sort(nums);\n for (int i = -1; i < n - 1; i++) \n if (nums[i + 1] >= n - i - 1) { //possible solution\n if (i == -1 || nums[i] < n - i - 1) return n - i - 1; // n - i - 1 is the number after nu...
10
5
[]
2
special-array-with-x-elements-greater-than-or-equal-x
Binary Search || C++
binary-search-c-by-hemant_1451-wosd
\n# Code\n\nclass Solution {\npublic:\n\tint specialArray(vector<int>& nums) {\n\t\tint i = 1, j = nums.size();\n\t\twhile(i <= j)\n {\n\t\t\tint mid = i
Hemant_1451
NORMAL
2023-01-07T05:37:01.679239+00:00
2023-01-07T05:37:01.679266+00:00
1,917
false
\n# Code\n```\nclass Solution {\npublic:\n\tint specialArray(vector<int>& nums) {\n\t\tint i = 1, j = nums.size();\n\t\twhile(i <= j)\n {\n\t\t\tint mid = i + (j - i)/2, count=0;\n\t\t\tfor(int k = 0; k < nums.size(); k++)\n {\n\t\t\t\tif(nums[k] >= mid)\n count++;\t\t\n }\t\...
8
0
['Binary Search', 'C++']
1
special-array-with-x-elements-greater-than-or-equal-x
Python | Faster than 94% | 2 methods | O(nlogn)
python-faster-than-94-2-methods-onlogn-b-421o
Method 1 : Without Binary Search 29ms, Using Linear Search. No nested for loop\n\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n
ana_2kacer
NORMAL
2021-10-18T07:46:53.273491+00:00
2022-04-04T20:23:06.348155+00:00
1,546
false
Method 1 : Without Binary Search 29ms, Using Linear Search. No nested for loop\n```\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n n = len(nums)\n\n if n<=nums[0]:\n return n\n \n for i in range(1,n):\n count = n-i #co...
8
0
['Binary Tree', 'Python', 'Python3']
2
special-array-with-x-elements-greater-than-or-equal-x
[Python] Count and binary search
python-count-and-binary-search-by-rudy-rpym
```python\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n left, mid, right = 0, 0, len(nums)\n while
rudy__
NORMAL
2020-10-12T05:50:55.043017+00:00
2020-10-12T05:50:55.043049+00:00
856
false
```python\nclass Solution:\n def specialArray(self, nums: List[int]) -> int:\n nums.sort()\n left, mid, right = 0, 0, len(nums)\n while left <= right:\n mid = (left + right) // 2\n loc = bisect_left(nums, mid)\n if len(nums) - loc == mid: return mid\n ...
8
0
[]
0
special-array-with-x-elements-greater-than-or-equal-x
✅ One Line Solution
one-line-solution-by-mikposp-db6v
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1 - Brute Force\nTime complexity: O(n^2)
MikPosp
NORMAL
2024-05-27T09:12:41.419692+00:00
2024-05-27T09:12:41.419708+00:00
898
false
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1 - Brute Force\nTime complexity: $$O(n^2)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n def specialArray(self, a: List[int]) -> int:\n return next((x for x in range(len(a)+1) if su...
7
0
['Array', 'Binary Search', 'Sorting', 'Python', 'Python3']
0
special-array-with-x-elements-greater-than-or-equal-x
C++ Solution | Beats 100% users Solution | Easy to understand | Sorting +Binary Search
c-solution-beats-100-users-solution-easy-87zd
Intuition \n1.) Brute Force\n2.) Binary Search\n Describe your first thoughts on how to solve this problem. \n\n# Approach \nWe can do brute force but I have do
professor43236
NORMAL
2024-05-27T05:11:06.388855+00:00
2024-05-27T05:11:06.388882+00:00
1,540
false
# Intuition \n1.) Brute Force\n2.) Binary Search\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach \nWe can do brute force but I have done Binary Search to improve it.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n log n + log n) (sorti...
7
0
['C++']
2
special-array-with-x-elements-greater-than-or-equal-x
Sort and Traverse || Beat 100%
sort-and-traverse-beat-100-by-cs_monks-fds7
\n\n# Intuition\nTo solve this problem, we need to find a number x such that there are exactly x numbers in the array that are greater than or equal to x. We\'l
CS_MONKS
NORMAL
2024-05-27T03:17:56.016236+00:00
2024-05-27T03:39:54.132840+00:00
1,784
false
\n![Screenshot from 2024-05-27 08-48-39.png](https://assets.leetcode.com/users/images/2575732a-2c0e-4cdd-bd2e-a68e92b44612_1716779946.773754.png)\n# Intuition\nTo solve this problem, we need to find a number x such that there are exactly x numbers in the array that are greater than or equal to x. We\'ll sort the array ...
7
0
['Python', 'C++', 'Java']
4
special-array-with-x-elements-greater-than-or-equal-x
Cpp || beats 100 % || binary search
cpp-beats-100-binary-search-by-ribhav_32-oovs
\n# Approach\nUse of binary search\n\n# Complexity\n- Time complexity:\nO(logN)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n int m;
ribhav_32
NORMAL
2023-01-13T06:39:07.037356+00:00
2023-01-13T06:39:07.037425+00:00
775
false
\n# Approach\nUse of binary search\n\n# Complexity\n- Time complexity:\nO(logN)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int m; \n int bin(int i, int j, int n, vector<int>&a)\n {\n if(i > j)\n return -1;\n\n m = (i+j)/2;\n\n if(a[m] >= n-m)\n {...
7
0
['Array', 'Binary Search', 'Sorting', 'C++']
3
special-array-with-x-elements-greater-than-or-equal-x
[JavaScript] 3 solutions from O(n^2) to O(n)
javascript-3-solutions-from-on2-to-on-by-6ao9
SOLUTION 1\n\nStraight forward O(n^2) solution:\n\njs\nconst specialArray = (nums) => {\n for (let i = 0; i <= nums.length; ++i) {\n let c = 0;\n for (co
poppinlp
NORMAL
2020-10-11T07:10:37.066698+00:00
2020-10-11T08:02:33.497982+00:00
934
false
## SOLUTION 1\n\nStraight forward O(n^2) solution:\n\n```js\nconst specialArray = (nums) => {\n for (let i = 0; i <= nums.length; ++i) {\n let c = 0;\n for (const num of nums) {\n num >= i && ++c;\n }\n if (c === i) return i;\n }\n return -1;\n};\n```\n\n## SOLUTION 2\n\nWe sort the `nums` first and...
7
0
['JavaScript']
3
special-array-with-x-elements-greater-than-or-equal-x
Javascript C++ | O(n) no sort
javascript-c-on-no-sort-by-shkvorets-frgr
\nvar specialArray = function(nums) {\n const freq = new Array(1001).fill(0);\n for(let n of nums)\n freq[n]++;\n \n for(let i=1000, cnt=0; i
shkvorets
NORMAL
2020-10-04T04:57:14.101097+00:00
2020-10-04T04:57:14.101128+00:00
829
false
```\nvar specialArray = function(nums) {\n const freq = new Array(1001).fill(0);\n for(let n of nums)\n freq[n]++;\n \n for(let i=1000, cnt=0; i>=0; i--){\n cnt += freq[i];\n if(i==cnt) return i;\n }\n \n return -1;\n};\n```\n\n```\nint specialArray(vector<int>& nums) {\n\tvect...
7
0
['C', 'JavaScript']
1
special-array-with-x-elements-greater-than-or-equal-x
Easy C++ Solution Using Sorting and BS
easy-c-solution-using-sorting-and-bs-by-kgg1w
Video Explanation:\nhttps://youtu.be/gAQe-ODV9Ko?si=-er7wP9Qttm5n-hu\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition b
Atharav_s
NORMAL
2024-05-27T06:18:33.072804+00:00
2024-05-27T06:18:33.072828+00:00
833
false
# Video Explanation:\nhttps://youtu.be/gAQe-ODV9Ko?si=-er7wP9Qttm5n-hu\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this approach is to leverage the sorted order of the array to efficiently determine the count of elements greater than or equal to each possible ...
6
0
['C++']
2
special-array-with-x-elements-greater-than-or-equal-x
✅ Easy Python Solution | With Explanation
easy-python-solution-with-explanation-by-ma2v
To solve this problem, we need to find a number x such that there are exactly x numbers in the array nums that are greater than or equal to x. The unique soluti
KG-Profile
NORMAL
2024-05-27T03:52:16.234195+00:00
2024-05-27T03:52:16.234214+00:00
335
false
To solve this problem, we need to find a number x such that there are exactly x numbers in the array nums that are greater than or equal to x. The unique solution x must satisfy this condition exactly, otherwise, we return \u22121.\n\nHere\'s a step-by-step approach to solve this problem:\n\n1. Sort the Array: Sorting ...
6
0
['Python3']
0
special-array-with-x-elements-greater-than-or-equal-x
Easy to understand solution/Binary Search (99%/74%)
easy-to-understand-solutionbinary-search-0pcp
Code\n\n/**\n * @param {number[]} nums\n * @return {number}\n */\n\nfunction bs(arr, target){\n let left = 0;\n let right = arr.length - 1;\n\n while(l
kubatabdrakhmanov
NORMAL
2023-09-06T05:09:35.742023+00:00
2023-09-06T05:09:35.742054+00:00
559
false
# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\n\nfunction bs(arr, target){\n let left = 0;\n let right = arr.length - 1;\n\n while(left < right){\n let mid = Math.floor((left + right) / 2);\n\n if(arr[mid] >= target){\n right = mid;\n }else{\n ...
6
0
['Array', 'Binary Search', 'Sorting', 'JavaScript']
0
special-array-with-x-elements-greater-than-or-equal-x
[ Python ] ✅✅ Simple Python Solution Using Three Approach 🥳✌👍
python-simple-python-solution-using-thre-fnad
If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n\t\n# Approach 1 : Using Binary Search\n# Runtime: 52 ms, faster
ashok_kumar_meghvanshi
NORMAL
2022-07-25T07:05:25.685166+00:00
2024-05-27T13:45:57.041515+00:00
1,172
false
# If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n\t\n# Approach 1 : Using Binary Search\n# Runtime: 52 ms, faster than 62.06% of Python3 online submissions for Special Array With X Elements Greater Than or Equal X.\n# Memory Usage: 13.8 MB, less than 62.52% of Python3 onl...
6
0
['Binary Search', 'Binary Tree', 'Python', 'Python3']
2
special-array-with-x-elements-greater-than-or-equal-x
✔ Simple and Easy using Binary Search in C++
simple-and-easy-using-binary-search-in-c-n15f
\n int specialArray(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n \n for(int i=0;i<=nums.size();i++){\n \n
sarvesh_2-1
NORMAL
2021-07-15T09:00:36.887380+00:00
2021-07-15T09:00:36.887433+00:00
770
false
```\n int specialArray(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n \n for(int i=0;i<=nums.size();i++){\n \n int index=lower_bound(nums.begin(),nums.end(),i) - nums.begin();\n \n int count= (nums.size() - index);\n \n ...
6
0
['C', 'Binary Tree', 'C++']
1
special-array-with-x-elements-greater-than-or-equal-x
[Java] Sort
java-sort-by-manrajsingh007-cmd4
```\nclass Solution {\n public int specialArray(int[] nums) {\n Arrays.sort(nums);\n int n = nums.length;\n for(int i = n - 1; i >= 0; i
manrajsingh007
NORMAL
2020-10-04T04:01:31.045608+00:00
2020-10-04T04:01:47.749876+00:00
794
false
```\nclass Solution {\n public int specialArray(int[] nums) {\n Arrays.sort(nums);\n int n = nums.length;\n for(int i = n - 1; i >= 0; i--) {\n while(i > 0 && nums[i] == nums[i - 1]) i--;\n if(i > 0) {\n if(n - i > nums[i - 1] && n - i <= nums[i]) return n - ...
6
1
[]
0
special-array-with-x-elements-greater-than-or-equal-x
JAVA Solution Explained in HINDI(3 Approaches)
java-solution-explained-in-hindi3-approa-9nyh
https://youtu.be/Qnv_9N1aKSk\n\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvot
The_elite
NORMAL
2024-05-27T16:25:50.101512+00:00
2024-05-27T16:25:50.101540+00:00
450
false
https://youtu.be/Qnv_9N1aKSk\n\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:- 400\nCurrent Subscribe...
5
0
['Java']
0
special-array-with-x-elements-greater-than-or-equal-x
Simple O(N) time and O(1) auxiliary space solution beats 100%
simple-on-time-and-o1-auxiliary-space-so-8xi7
Intuition\nThe maximum value of x (the return value) is the length of the array.\nThis allows us to refine our search for this return value to the range [0,N].
MrMag
NORMAL
2024-05-27T05:03:59.265995+00:00
2024-05-27T05:35:44.826102+00:00
48
false
# Intuition\nThe maximum value of x (the return value) is the length of the array.\nThis allows us to refine our search for this return value to the range [0,N]. \n\nUsing this we are able to count the number of values greater or equal to than the each value between 0 and N. We then itterate over these until there is a...
5
0
['C++']
0
special-array-with-x-elements-greater-than-or-equal-x
Single pass check || beats 100% with C++ & 89% with java || python3 || typescript
single-pass-check-beats-100-with-c-89-wi-d7ec
Approach\nSingle pass check\n\n# Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(1)\n\n# Explanation\n1. Sorting the Array:\n\n- Arrays.sort(nu
SanketSawant18
NORMAL
2024-05-27T04:09:20.853893+00:00
2024-05-27T04:09:20.853910+00:00
1,159
false
# Approach\nSingle pass check\n\n# Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(1)\n\n# Explanation\n1. **Sorting the Array:**\n\n- Arrays.sort(nums);\n- The array nums is sorted in ascending order. This step is crucial because it helps us efficiently check how many elements are greater than or equa...
5
0
['Array', 'Sorting', 'C++', 'Java', 'TypeScript', 'Python3']
4
special-array-with-x-elements-greater-than-or-equal-x
Beats 98.53 users.... Please upvote
beats-9853-users-please-upvote-by-aim_hi-xjkn
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-05-27T02:02:39.500470+00:00
2024-05-27T02:02:39.500488+00:00
44
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
['C', 'Python', 'Java', 'Python3']
0
special-array-with-x-elements-greater-than-or-equal-x
Java Detailed Binary Search Solution :
java-detailed-binary-search-solution-by-l48wj
Intuition\n First of all we will discuss Why Binary Search, even if the array is not sorted . Look here the array is not sorted but lemme tell you if we have s
hokteyash
NORMAL
2023-08-07T21:01:40.362973+00:00
2023-08-07T21:09:33.414807+00:00
551
false
# Intuition\n First of all we will discuss Why Binary Search, even if the array is not sorted . Look here the array is not sorted but lemme tell you if we have some range so we can definitely apply binary search on range because range is something which will always be in a sorted fashion for example suppose we have th...
5
0
['Array', 'Binary Search', 'Java']
1
special-array-with-x-elements-greater-than-or-equal-x
✅Well Explained -->2 approaches--> Easy to Understand --> C++ code🔥
well-explained-2-approaches-easy-to-unde-caku
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can iterate over all possible values of x and check if there are exactly x numbers i
sunny_6289
NORMAL
2023-05-12T09:02:14.868444+00:00
2023-05-12T10:06:45.093609+00:00
1,031
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can iterate over all possible values of x and check if there are exactly x numbers in nums that are greater than or equal to x. If we find such a value of x, we can return it as the answer. If we have checked all possible values of x a...
5
0
['Array', 'Binary Search', 'Sorting', 'C++']
1
special-array-with-x-elements-greater-than-or-equal-x
Java solution in Binary Search
java-solution-in-binary-search-by-kashif-1y9p
\n\n# Code\n\nclass Solution {\n public int specialArray(int[] nums) {\n int high=nums.length;\n int low=0;\n while(low<=high){\n
Kashif_Rahman
NORMAL
2022-10-15T18:51:35.408642+00:00
2022-10-15T18:51:35.408678+00:00
580
false
\n\n# Code\n```\nclass Solution {\n public int specialArray(int[] nums) {\n int high=nums.length;\n int low=0;\n while(low<=high){\n int mid=low+(high-low)/2;\n int count=0;\n for(int i=0;i<nums.length;i++){\n if(nums[i]>=mid) count++;\n ...
5
0
['Java']
1
special-array-with-x-elements-greater-than-or-equal-x
[JS] O(1) Space | Binary Search Explained
js-o1-space-binary-search-explained-by-h-kplz
TL-DR: Plain Solution \n\n\nvar specialArray = function(nums) {\n const N = nums.length; let l = 0, r = N-1; \n \n nums.sort((a,b) => a - b);\n \n
hugotannus
NORMAL
2022-09-03T01:14:49.735224+00:00
2022-09-29T17:40:42.129800+00:00
470
false
## TL-DR: **Plain Solution** \n\n```\nvar specialArray = function(nums) {\n const N = nums.length; let l = 0, r = N-1; \n \n nums.sort((a,b) => a - b);\n \n while(l < r - 1){\n let mid = l + ((r - l) >> 1);\n let x = N - mid;\n \n if(nums[mid] >= x && x > nums[mid-1]) return x...
5
0
['Binary Tree', 'JavaScript']
1
special-array-with-x-elements-greater-than-or-equal-x
C++ || Sorting
c-sorting-by-aditya_pratap1-h2me
\nclass Solution {\npublic:\n int specialArray(vector<int>& nums) {\n \n int n = nums.size();\n \n sort(nums.begin(),nums.end());
aditya_pratap1
NORMAL
2022-04-07T17:24:06.731404+00:00
2022-04-07T17:24:06.731439+00:00
240
false
```\nclass Solution {\npublic:\n int specialArray(vector<int>& nums) {\n \n int n = nums.size();\n \n sort(nums.begin(),nums.end());\n \n for(int i=0;i<n;i++){\n int len = n - i; // len gives the number of elements greater than\n\t\t\t\t\t\t\t...
5
0
['C', 'Sorting']
0
special-array-with-x-elements-greater-than-or-equal-x
[java] brute-force , binary search approach
java-brute-force-binary-search-approach-o757y
IF U DO LIKE SOLUTION PLEASE UPVOTE IT\nHere we can solve this problem using two approaches\n1. brute force approach\n2. binary search\n\nbrute force approach :
salmanshaikssk007
NORMAL
2021-11-30T04:13:02.075809+00:00
2021-11-30T05:29:05.490212+00:00
445
false
**IF U DO LIKE SOLUTION PLEASE UPVOTE IT**\nHere we can solve this problem using two approaches\n1. brute force approach\n2. binary search\n\nbrute force approach : \n\nHere we point two pointers at start of the array and iterate through the loop for the solution\ntime complexity - O(n2)\n\nBinary search approach\nHere...
5
0
['Binary Tree', 'Java']
1