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
check-if-digits-are-equal-in-string-after-operations-i
Python 3 lines, quardratic solution
python-3-lines-quardratic-solution-by-sa-jbxc
IntuitionWe can just simulate step by step where at each step we reduce the number of digits by one.Complexity Time complexity: O(n2). As each steps takes O(n)
salvadordali
NORMAL
2025-04-11T07:45:22.829708+00:00
2025-04-11T07:45:22.829708+00:00
1
false
# Intuition We can just simulate step by step where at each step we reduce the number of digits by one. # Complexity - Time complexity: $O(n^2)$. As each steps takes $O(n)$ - Space complexity: $O(n)$ # Code ```python3 [] class Solution: def hasSameDigits(self, s: str) -> bool: digits = [int(c) for c in s] ...
0
0
['Python3']
0
check-if-digits-are-equal-in-string-after-operations-i
Simplest C++ Solution
simplest-c-solution-by-0j60pwopfd-yp5p
IntuitionApproachComplexity Time complexity: Space complexity: Code
0j60PWOPfD
NORMAL
2025-04-10T22:05:48.244802+00:00
2025-04-10T22:05:48.244802+00:00
1
false
# Intuition # Approach # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: bool hasSameDigits(string s) { while (s.size()>= 2) { ...
0
0
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
Optimized simple solution - beats 100%🔥
optimized-simple-solution-beats-100-by-c-kky1
Complexity Time complexity: O(N) Space complexity: O(N) Code
cyrusjetson
NORMAL
2025-04-10T10:45:17.682827+00:00
2025-04-10T10:45:36.760893+00:00
2
false
# Complexity - Time complexity: O(N) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(N) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public boolean hasSameDigits(String s) { int[] digits = new int[s.length()]; int distance = ...
0
0
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
easy stringbuilder solution (java)
easy-stringbuilder-solution-java-by-dpas-2z8v
IntuitionApproachComplexity Time complexity: Space complexity: Code
dpasala
NORMAL
2025-04-09T03:10:16.629839+00:00
2025-04-09T03:10:16.629839+00:00
1
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
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
Python Solution -0(n)
python-solution-0n-by-vini__7-h81j
IntuitionApproachComplexity Time complexity: Space complexity: Code
Vini__7
NORMAL
2025-04-08T07:05:57.773571+00:00
2025-04-08T07:05:57.773571+00:00
2
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
check-if-digits-are-equal-in-string-after-operations-i
Java | Recursion approach | Beats 90%
java-recursion-approach-beats-90-by-igor-r928
Code
IgorChurakov
NORMAL
2025-04-07T07:49:37.973381+00:00
2025-04-07T07:49:37.973381+00:00
1
false
# Code ```java [] class Solution { public boolean hasSameDigits(String s) { var chars = new ArrayList<Integer>(); for (int i = 0; i < s.length(); i++) { chars.add(s.charAt(i) - '0'); } return hasSameDigits(chars); } boolean hasSameDigits(ArrayList<Integer> chars)...
0
0
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
Java Intermediate Solution
java-intermediate-solution-by-trevorkmci-9xrv
IntuitionApproachComplexity Time complexity: Space complexity: Code
trevorkmcintyre
NORMAL
2025-04-07T01:16:17.948693+00:00
2025-04-07T01:16:17.948693+00:00
1
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
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
Fastest way - infinite loop
fastest-way-infinite-loop-by-zemamba-6ix5
null
zemamba
NORMAL
2025-04-06T22:25:22.399898+00:00
2025-04-06T22:25:22.399898+00:00
1
false
```javascript [] /** * @param {string} s * @return {boolean} */ var hasSameDigits = function(s) { arr = [...s] while (arr.length > 2) { arr = newDigit(arr) } return arr[0] == arr[1] }; function newDigit(ar) { temp = [] for (let i = 0; i < ar.length - 1; i++) { temp.push((~...
0
0
['JavaScript']
0
check-if-digits-are-equal-in-string-after-operations-i
s.compactMap{$0.wholeNumberValue}
scompactmap0wholenumbervalue-by-victor-s-kkaj
null
Victor-SMK
NORMAL
2025-04-06T17:56:00.311048+00:00
2025-04-06T17:56:00.311048+00:00
1
false
```swift [] class Solution { func hasSameDigits(_ s: String) -> Bool { var arr = s.compactMap{$0.wholeNumberValue} while arr.count > 2 { for i in 1..<arr.count { arr[i-1] = (arr[i-1] + arr[i]) % 10 } arr.removeLast() } re...
0
0
['Math', 'String', 'Swift', 'Python', 'Python3']
0
check-if-digits-are-equal-in-string-after-operations-i
Kotlin Solution
kotlin-solution-by-osagiog-9j3t
IntuitionApproachComplexity Time complexity: Space complexity: Code
osagiog
NORMAL
2025-04-06T12:51:51.169889+00:00
2025-04-06T12:51:51.169889+00:00
1
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
['Kotlin']
0
check-if-digits-are-equal-in-string-after-operations-i
Simple C simluation 100% runtime 94.97% memory
simple-c-simluation-100-runtime-9497-mem-0s1j
IntuitionOkay so.... we need to repeatedly modify the string by replacing adjacent digits with their sum modulo 10 until the string length reduces to exactly 2
PerryThePpatypus
NORMAL
2025-04-06T01:01:45.856795+00:00
2025-04-06T01:02:57.253994+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Okay so.... we need to repeatedly modify the string by replacing adjacent digits with their sum modulo 10 until the string length reduces to exactly 2 characters. At that point, we check if those two characters are the same. Instead of all...
0
0
['C']
0
check-if-digits-are-equal-in-string-after-operations-i
C# | Simulation
c-simulation-by-we6mmvl7tl-n90w
Complexity Time complexity: O(n2) Space complexity: O(1) Code
we6MMvL7tl
NORMAL
2025-04-04T13:54:23.080282+00:00
2025-04-04T13:54:23.080282+00:00
3
false
# Complexity - Time complexity: $$O(n^2)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(1)$$ <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```csharp [] public class Solution { public bool HasSameDigits(string s) { while (s.Length != 2) { ...
0
0
['Simulation', 'C#']
0
check-if-digits-are-equal-in-string-after-operations-i
Check If Digits Are Equal in String After Operations I in Java
check-if-digits-are-equal-in-string-afte-f3tj
Code
sowmy3010
NORMAL
2025-04-02T11:26:03.410988+00:00
2025-04-02T11:26:03.410988+00:00
1
false
# Code ```java [] class Solution { public String Modulo(String s){ String st=""; for(int i=1;i<s.length();i++){ char ch1 = s.charAt(i-1); char ch2 = s.charAt(i); int p = (ch1-'0'+ch2-'0')%10; st+=p; } return st; } public boole...
0
0
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
Checking if a Number Reduces to Two Identical Digits
checking-if-a-number-reduces-to-two-iden-wlaq
IntuitionThe problem requires checking if a given string of digits, when repeatedly transformed by replacing adjacent pairs with their sum modulo 10, eventually
Nylrem
NORMAL
2025-03-31T20:36:10.834163+00:00
2025-03-31T20:36:10.834163+00:00
1
false
## Intuition The problem requires checking if a given string of digits, when repeatedly transformed by replacing adjacent pairs with their sum modulo 10, eventually reduces to two identical digits. ## Approach 1. **Iterative Transformation**: - Start with the given string `s`. - Repeatedly form a new...
0
0
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
my solution
my-solution-by-leman_cap13-574e
IntuitionApproachComplexity Time complexity: Space complexity: Code
leman_cap13
NORMAL
2025-03-30T19:02:15.010852+00:00
2025-03-30T19:02:15.010852+00:00
2
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
check-if-digits-are-equal-in-string-after-operations-i
Scala solution with implicit, recursion and pattern matching
scala-solution-with-implicit-recursion-a-k30z
IntuitionApproachComplexity Time complexity: Space complexity: Code
iyIeO99AmH
NORMAL
2025-03-29T23:47:52.669218+00:00
2025-03-29T23:47:52.669218+00:00
1
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
['Scala']
0
check-if-digits-are-equal-in-string-after-operations-i
Solution using extra space with JS
solution-using-extra-space-with-js-by-be-e6ei
IntuitionApproachComplexity Time complexity: Space complexity: Code
bek-shoyatbek
NORMAL
2025-03-29T19:33:01.811139+00:00
2025-03-29T19:33:01.811139+00:00
2
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
['JavaScript']
0
check-if-digits-are-equal-in-string-after-operations-i
Simple C++ Solution using queue.
simple-c-solution-using-queue-by-optimiz-yddk
Complexity Time complexity: O(n) Space complexity: O(n) Code
OptimizingCompiler
NORMAL
2025-03-29T10:44:19.908531+00:00
2025-03-29T10:44:19.908531+00:00
3
false
# Complexity - Time complexity: $$O(n)$$ - Space complexity: $$O(n)$$ # Code ```cpp [] class Solution { public: bool hasSameDigits(string s) { deque<int> q; for (char c : s) { q.push_back(c - '0'); } int n = 0; int c = q.size(); while (q.size() > 2) { ...
0
0
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
Simple Swift Solution
simple-swift-solution-by-felisviridis-qjyc
Code
Felisviridis
NORMAL
2025-03-25T09:51:01.184421+00:00
2025-03-25T09:51:01.184421+00:00
2
false
![Screenshot 2025-03-25 at 12.50.26 PM.png](https://assets.leetcode.com/users/images/5a3b2471-038c-44c8-b01d-f5f8ca154089_1742896242.9352245.png) # Code ```swift [] class Solution { func hasSameDigits(_ s: String) -> Bool { var digits = s.compactMap(\.wholeNumberValue) while digits.count > 2 { ...
0
0
['Swift']
0
check-if-digits-are-equal-in-string-after-operations-i
Go
go-by-stuu-7m0i
Code
stuu
NORMAL
2025-03-23T01:48:21.827964+00:00
2025-03-23T01:48:21.827964+00:00
3
false
![image.png](https://assets.leetcode.com/users/images/03f9c282-b294-466e-88d5-b8c00c57aab9_1742694496.0946155.png) # Code ```golang [] func hasSameDigits(s string) bool { operationResult := s for { operationResult = reduceDigit(operationResult) if len(operationResult) == 2 { break } } if operationResu...
0
0
['Go']
0
check-if-digits-are-equal-in-string-after-operations-i
C++ Solution
c-solution-by-chandreyee_12-uaqy
Code
chandreyee_12
NORMAL
2025-03-22T15:50:14.666810+00:00
2025-03-22T15:50:14.666810+00:00
5
false
# Code ```cpp [] class Solution { public: bool hasSameDigits(string s) { while(s.size()>2) { string str=""; for(int i=0;i<s.size()-1;i++) { int x=s[i]-'0'; int y=s[i+1]-'0'; int sum=(x+y)%10; char c...
0
0
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
Update the list in place, 93% speed
update-the-list-in-place-93-speed-by-evg-zx83
Code
evgenysh
NORMAL
2025-03-22T12:59:59.911040+00:00
2025-03-22T12:59:59.911040+00:00
2
false
# Code ```python3 [] class Solution: def hasSameDigits(self, s: str) -> bool: lst = list(map(int, s)) for end in range(len(lst) - 1, 1, -1): for i in range(end): lst[i] = (lst[i] + lst[i + 1]) % 10 return lst[0] == lst[1] ```
0
0
['Python3']
0
check-if-digits-are-equal-in-string-after-operations-i
Easy Java Solution for Beginners
easy-java-solution-for-beginners-by-ther-u0ad
Upvote PleaseApproachComplexity Time complexity: Space complexity: Code
therajnishraj
NORMAL
2025-03-21T05:42:39.452279+00:00
2025-03-21T05:42:39.452279+00:00
3
false
# Upvote Please ![upvote.jpeg](https://assets.leetcode.com/users/images/5280e6d1-ccd5-4f40-af78-4050ea410e6a_1742535712.8630085.jpeg) # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add yo...
0
0
['Hash Table', 'Java']
0
check-if-digits-are-equal-in-string-after-operations-i
Easy In-Place Solution
easy-in-place-solution-by-j_cox-9qpy
IntuitionApproach Loop through S until it has 2 characters On each loop, take pairs of chars, convert them to int Perform the operation of adding them and modul
J_Cox
NORMAL
2025-03-20T16:03:05.019220+00:00
2025-03-20T16:03:05.019220+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach 1. Loop through S until it has 2 characters 2. On each loop, take pairs of chars, convert them to int 3. Perform the operation of adding them and modulo by 10 4. Replace the first of the two digits with this new value 5. Repeat ...
0
0
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
True subquadratic complexity using a bit of number theory :)
true-subquadratic-complexity-using-a-bit-zug9
ApproachThere is a closed form for the two final digits - they are given by summing digits of s multiplied by binomial coefficients, similar to Pascal's triangl
user5094uY
NORMAL
2025-03-19T17:58:22.537458+00:00
2025-03-19T17:58:22.537458+00:00
2
false
# Approach There is a closed form for the two final digits - they are given by summing digits of `s` multiplied by binomial coefficients, similar to Pascal's triangle. This can be leveraged to get log-linear time complexity and logarithmic space complexity. This is a situation where we can't just assume all arithmetic...
0
0
['Python3']
0
check-if-digits-are-equal-in-string-after-operations-i
Using Character Array and HashMap
using-character-array-and-hashmap-by-hem-mlet
IntuitionUsing Character Array and HashMapApproachIterative Transformation:The while loop runs until the length of s is reduced to 2. In each iteration, calcula
hemu1116
NORMAL
2025-03-18T17:14:18.241757+00:00
2025-03-18T17:14:18.241757+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Using Character Array and HashMap # Approach <!-- Describe your approach to solving the problem. --> Iterative Transformation: The while loop runs until the length of s is reduced to 2. In each iteration, calculateNewS(s, n) is called, wh...
0
0
['Java']
0
check-if-digits-are-equal-in-string-after-operations-i
0ms Runtime using C Programming Language with Easy String Operations
0ms-runtime-using-c-programming-language-1hh9
IntuitionThe problem revolves around transforming a string of digits into a sequence of pairs, repeatedly reducing the length of the string until only two digit
Vivek_Bartwal
NORMAL
2025-03-15T05:32:23.636762+00:00
2025-03-15T05:32:23.636762+00:00
9
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The problem revolves around transforming a string of digits into a sequence of pairs, repeatedly reducing the length of the string until only two digits remain. The main focus is to compute the new digits as the modulo 10 of the sum of cons...
0
0
['C']
0
check-if-digits-are-equal-in-string-after-operations-i
Easy logic and code
easy-logic-and-code-by-aniketkumarsingh9-mqed
Intuitionchanging the string based on its size that should not get to 2.ApproachIterative Digit ReductionComplexity Time complexity: O(n). Space complexity:
AniketKumarSingh99
NORMAL
2025-03-14T13:42:09.234943+00:00
2025-03-14T13:42:09.234943+00:00
3
false
# Intuition changing the string based on its size that should not get to 2. # Approach Iterative Digit Reduction # Complexity - Time complexity: O(n). - Space complexity: O(1). # Code ```cpp [] class Solution { public: bool hasSameDigits(string s) { int size=s.size(); while(size!=2){ ...
0
0
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
SIMPLE C PROGRAM
simple-c-program-by-mr_jaikumar-ot5u
IntuitionApproachComplexity Time complexity: 0 MS Space complexity: Code
Mr_JAIKUMAR
NORMAL
2025-03-14T05:34:28.155999+00:00
2025-03-14T05:34:28.155999+00:00
11
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)$$ --> 0 MS - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # C...
0
0
['C']
0
check-if-digits-are-equal-in-string-after-operations-i
Kotlin Imperative Solution
kotlin-imperative-solution-by-curenosm-joib
Code
curenosm
NORMAL
2025-03-13T14:35:19.032310+00:00
2025-03-13T14:35:19.032310+00:00
2
false
# Code ```kotlin [] class Solution { fun hasSameDigits(s: String): Boolean { var s = s; var i = 1 while (s.length > 2) { val str = StringBuilder() for (i in 1 until s.length) str.append( (s[i - 1].digitToInt() + s[i].digitToInt()) % 10 ...
0
0
['Kotlin']
0
check-if-digits-are-equal-in-string-after-operations-i
Easy to understand...
easy-to-understand-by-udisha_1234-rc5v
Code
Udisha_1234
NORMAL
2025-03-13T12:52:43.788627+00:00
2025-03-13T12:52:43.788627+00:00
5
false
# Code ```cpp [] class Solution { public: bool hasSameDigits(string s) { string ans = s; while (ans.size() != 2) { s = ans; ans = ""; for (int i = 0; i + 1 < s.size(); i++) { int a = s[i] - 48; int b = s[i + 1] - 48; ...
0
0
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
simple and easy answer
simple-and-easy-answer-by-shiva135-vk92
IntuitionApproachComplexity Time complexity: Space complexity: Code
Shiva135
NORMAL
2025-03-12T15:07:17.592900+00:00
2025-03-12T15:07:17.592900+00:00
2
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
check-if-digits-are-equal-in-string-after-operations-i
simple
simple-by-diorsalimov2006-15e2
IntuitionApproachComplexity Time complexity: Space complexity: Code
diorsalimov2006
NORMAL
2025-03-12T07:54:18.446961+00:00
2025-03-12T07:54:18.446961+00:00
2
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
check-if-digits-are-equal-in-string-after-operations-i
C++
c-by-tinachien-nkko
IntuitionApproachComplexity Time complexity: Space complexity: Code
TinaChien
NORMAL
2025-03-12T00:40:31.996732+00:00
2025-03-12T00:40:31.996732+00:00
4
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
['C++']
0
check-if-digits-are-equal-in-string-after-operations-i
Java
java-by-soumya_699-5nd6
IntuitionApproachComplexity Time complexity: Space complexity: Code
Soumya_699
NORMAL
2025-03-11T08:47:58.021618+00:00
2025-03-11T08:47:58.021618+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
longest-uploaded-prefix
Python Elegant & Short | Amortized O(1) | Commented
python-elegant-short-amortized-o1-commen-wz9c
\nclass LUPrefix:\n """\n Memory: O(n)\n Time: O(1) per upload call, because adding to the set takes O(1) time, and the prefix\n\t\t\t\t can be incre
Kyrylo-Ktl
NORMAL
2022-10-01T16:07:49.332700+00:00
2022-10-01T18:19:06.617886+00:00
3,394
false
```\nclass LUPrefix:\n """\n Memory: O(n)\n Time: O(1) per upload call, because adding to the set takes O(1) time, and the prefix\n\t\t\t\t can be increased no more than n times for all n calls to the upload function\n """\n\n def __init__(self, n: int):\n self._longest = 0\n self._nums =...
78
2
['Python', 'Python3']
12
longest-uploaded-prefix
Most Easy and Short solution + Meme
most-easy-and-short-solution-meme-by-har-2iuy
Self explanatory solution\n\n\nclass LUPrefix {\n Set<Integer> set;\n int max=0;\n public LUPrefix(int n) {\n set=new HashSet<>();\n }\n p
HarshitMaurya
NORMAL
2022-10-01T16:00:53.534938+00:00
2022-11-01T06:23:08.799523+00:00
2,741
false
**Self explanatory solution**\n\n```\nclass LUPrefix {\n Set<Integer> set;\n int max=0;\n public LUPrefix(int n) {\n set=new HashSet<>();\n }\n public void upload(int video) {\n set.add(video);\n while(set.contains(max+1)) max++;\n }\n public int longest() {\n return max...
37
1
['Ordered Set', 'Java']
7
longest-uploaded-prefix
C++ | Set | Easy Understanding
c-set-easy-understanding-by-kiranpalsing-wh7n
Approach \n- We will insert number in set s.\n- When the longest() function will be called, the set will try to increase the answer by checking the next values.
kiranpalsingh1806
NORMAL
2022-10-01T16:04:20.078027+00:00
2022-10-01T16:16:32.096928+00:00
2,449
false
**Approach** \n- We will insert number in set `s`.\n- When the `longest()` function will be called, the set will try to increase the answer by checking the next values.\n\n**C++ Code**\n\n```cpp\nclass LUPrefix {\n public:\n set<int> s;\n int t = 0;\n LUPrefix(int n) {\n }\n\n void upload(int video) {\...
26
4
['C']
7
longest-uploaded-prefix
Java TreeSet (super simple)
java-treeset-super-simple-by-ricola-ba5r
Intuition\nKeep a TreeSet of all the numbers (videos) NOT uploaded yet.\nYou can then look at the lowest not uploaded value, and the prefix is the value just be
ricola
NORMAL
2022-10-01T16:01:10.469006+00:00
2022-10-03T09:46:49.356863+00:00
1,025
false
# Intuition\nKeep a TreeSet of all the numbers (videos) NOT uploaded yet.\nYou can then look at the lowest not uploaded value, and the prefix is the value just before this one.\nSince it\'s a tree, it allows to get the lowest value (leftmost node in the tree) in O(log n)\n\n# Complexity\n- Time complexity:\n - initi...
19
1
['Java']
1
longest-uploaded-prefix
✅C++ | ✅Use Array | ✅Easy approach
c-use-array-easy-approach-by-yash2arma-e07s
\nclass LUPrefix {\npublic:\n \n vector<int> pre;\n int val=0;\n \n LUPrefix(int n) \n {\n pre.resize(n+2, 0);\n }\n \n void u
Yash2arma
NORMAL
2022-10-01T17:11:30.530961+00:00
2022-10-01T17:11:30.531012+00:00
1,080
false
```\nclass LUPrefix {\npublic:\n \n vector<int> pre;\n int val=0;\n \n LUPrefix(int n) \n {\n pre.resize(n+2, 0);\n }\n \n void upload(int video) \n {\n pre[video] = 1;\n \n }\n \n int longest() \n {\n while(pre[val+1]==1)\n val++;\n ...
12
0
['Array', 'C', 'C++']
1
longest-uploaded-prefix
Python 3 || iteration || T/S: 97% / 59%
python-3-iteration-ts-97-59-by-spaulding-lg18
\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.stream = [False]*n\n self.maxLength = n\n self.prefLength = 0\n \n de
Spaulding_
NORMAL
2022-10-01T19:06:27.019656+00:00
2024-06-15T14:41:14.594046+00:00
579
false
```\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.stream = [False]*n\n self.maxLength = n\n self.prefLength = 0\n \n def upload(self, video: int) -> None:\n self.stream[video-1] = True\n\n def longest(self) -> int:\n for i in range(self.prefLength,self.maxLen...
9
0
['Python', 'Python3']
0
longest-uploaded-prefix
✅✅✅ C++ with Explanation || Very Simple & Easy to Understand Solution
c-with-explanation-very-simple-easy-to-u-s23c
Up Vote if you like the solution \n\n\n/* take an array that keeps a mark of each of the video that uploaded.\n keep another varible - latest, that keeps trac
kreakEmp
NORMAL
2022-10-01T16:02:18.394646+00:00
2022-10-01T16:27:24.477152+00:00
898
false
<b>Up Vote if you like the solution \n```\n\n/* take an array that keeps a mark of each of the video that uploaded.\n keep another varible - latest, that keeps track of all the video that\n has been already uploaded till that point of time.\n Update latest, when the new video uploaded just next to it, also keep \...
9
0
[]
3
longest-uploaded-prefix
3 Solutions: Fenwick Tree or Binary Indexed Tree | Segment Tree | Disjoint Set ADT
3-solutions-fenwick-tree-or-binary-index-1jvx
This discussion thread includes 3 separate solutions using different data structures namely,\n\n1. Fenwick Tree or Binary Indexed Tree\n2. Segment Tree\n3. Disj
mrtwinklesharma
NORMAL
2022-10-09T21:18:00.444046+00:00
2022-10-09T21:18:48.414730+00:00
522
false
This discussion thread includes 3 separate solutions using different data structures namely,\n\n**1. Fenwick Tree or Binary Indexed Tree\n2. Segment Tree\n3. Disjoint Set**\n\nThe intuition behind fenwick tree and segment tree solution is,\n=> We want to find the Longest Uploaded Prefix,\n=> Let\'s create an array of s...
8
0
['Tree', 'Binary Tree']
3
longest-uploaded-prefix
Java | O(1) time | 1D Array
java-o1-time-1d-array-by-akrchaubey-ndon
```\nclass LUPrefix {\n \n boolean[] uploaded;\n int max;\n int size;\n public LUPrefix(int n) {\n uploaded = new boolean[n + 1];\n
akrchaubey
NORMAL
2022-10-01T16:34:13.658878+00:00
2022-10-01T16:42:57.339528+00:00
775
false
```\nclass LUPrefix {\n \n boolean[] uploaded;\n int max;\n int size;\n public LUPrefix(int n) {\n uploaded = new boolean[n + 1];\n max = 0;\n size = n;\n }\n \n public void upload(int video) {\n uploaded[video] = true;\n\t\t\n\t\t/** \n\t\tIf the longest uploaded pre...
8
2
['Array', 'Java']
0
longest-uploaded-prefix
Extremely Easy Solution | Vector instead of Set | Linear Solution
extremely-easy-solution-vector-instead-o-5pcz
We can just use a vector and resize it to n to initialize it. We can maintain a global variable named last wihch will tell us the longest video which we can see
modernbeast02
NORMAL
2022-10-03T02:14:10.231590+00:00
2022-10-03T02:14:10.231624+00:00
581
false
We can just use a vector and resize it to n to initialize it. We can maintain a global variable named last wihch will tell us the longest video which we can see. Total Time Complexity will be O(N) but Amortized Time Complexity will be O(1). If it helped u, don\'t forget to upvote.\uD83D\uDE03\n```\nclass LUPrefix {\n ...
7
0
[]
0
longest-uploaded-prefix
very easy solution ||C++||O(Nlogn)
very-easy-solution-conlogn-by-baibhavkr1-ooh0
Intuition\nWe will going to use set here because we know that set have element in sorted order\n\n# Approach\nnow i am going to describe my intution using a exa
baibhavkr143
NORMAL
2022-10-01T16:03:35.029265+00:00
2022-10-01T16:13:24.670707+00:00
612
false
# Intuition\nWe will going to use set here because we know that set have element in sorted order\n\n# Approach\nnow i am going to describe my intution using a example\nlet n=6;\nnow put all element from 1 to 6 in set\ns={1,2,3,4,5,6}\n\nnow when ever the function ***upload*** is called we gonna delete that element from...
7
0
['Ordered Set', 'C++']
2
longest-uploaded-prefix
TreeSet
treeset-by-java_programmer_ketan-o0c4
\n/*\nWe will maintain a sorted set of un-uploaded videos.\nTo handle longest() query just return the first_element of the set -1\nFor uploading videos remove t
Java_Programmer_Ketan
NORMAL
2022-10-01T16:01:16.135472+00:00
2022-10-01T16:01:16.135535+00:00
278
false
```\n/*\nWe will maintain a sorted set of un-uploaded videos.\nTo handle longest() query just return the first_element of the set -1\nFor uploading videos remove the video from the set\n*/\nclass LUPrefix {\n TreeSet<Integer> set;\n public LUPrefix(int n) {\n this.set = new TreeSet<>();\n for(int i=...
6
2
[]
2
longest-uploaded-prefix
Disjoint Set || Java
disjoint-set-java-by-abdulazizms-jbau
Intuition\nFirst thing came to my mind was to use a disjoint set since different chains are merged at some point.\n\n\n# Approach\nI want to connect the current
abdulazizms
NORMAL
2022-10-01T16:10:11.796035+00:00
2022-10-01T16:23:42.937746+00:00
532
false
# Intuition\nFirst thing came to my mind was to use a disjoint set since different chains are merged at some point.\n\n\n# Approach\nI want to connect the current index to its left and right and maintain the total size of the chain. Disjoint set is a great candidate.\n\nThis approach can be used to solve this problem t...
5
0
['Java']
1
longest-uploaded-prefix
🧽 Java Clean & Simple | Union Find
java-clean-simple-union-find-by-palmas-ala9
\nclass LUPrefix {\n int[] map;\n\n public LUPrefix(int n) {\n map = new int[n + 1];\n }\n\n public void upload(int video) {\n map[vid
palmas
NORMAL
2022-10-01T16:41:58.310568+00:00
2022-10-01T16:41:58.310606+00:00
279
false
```\nclass LUPrefix {\n int[] map;\n\n public LUPrefix(int n) {\n map = new int[n + 1];\n }\n\n public void upload(int video) {\n map[video - 1] = find(video);\n }\n\n public int longest() {\n return find(0);\n }\n\n int find(int index) {\n if (map[index] == 0)\n ...
4
0
['Java']
1
longest-uploaded-prefix
[Python3] Using List || O(1) amortized || 354ms || beats 100%
python3-using-list-o1-amortized-354ms-be-keh0
Here is a small trick with adding additional False to the list end like indicator of boundary. So we don\'t need to check the boundry in the while loop and got
yourick
NORMAL
2024-03-09T19:14:47.874518+00:00
2024-03-09T19:35:46.554497+00:00
104
false
###### Here is a small trick with adding additional False to the list end like indicator of boundary. So we don\'t need to check the boundry in the while loop and got additional speed profit.\n`while self.videos[self.prefix]` instead of \n`while self.prefix < len(self.videos) and self.videos[self.prefix]`\n```python3 [...
3
0
['Python', 'Python3']
0
longest-uploaded-prefix
98% FASTER || C++ || USE ARRAY || EASY APPROACH
98-faster-c-use-array-easy-approach-by-y-yarh
\nclass LUPrefix {\npublic:\n int x = 1;\n vector<bool> v;\n LUPrefix(int n) {\n v.resize(100002,false);\n }\n \n void upload(int video
yash___sharma_
NORMAL
2023-03-06T05:02:05.969121+00:00
2023-03-06T05:02:05.969181+00:00
569
false
```\nclass LUPrefix {\npublic:\n int x = 1;\n vector<bool> v;\n LUPrefix(int n) {\n v.resize(100002,false);\n }\n \n void upload(int video) {\n v[video] = true;\n while(v[x]==true){\n x++;\n }\n }\n \n int longest() {\n return x-1;\n }\n};\n```
3
0
['Array', 'C', 'C++']
0
longest-uploaded-prefix
✅C++ || Easy to understand CODE || SHORT
c-easy-to-understand-code-short-by-abhin-tl9e
\n\n\tclass LUPrefix {\n\t\tpublic:\n\t\t\tvector v;\n\t\t\tint it=0;\n\t\t\tLUPrefix(int n) {\n\t\t\t\tvector temp(n,-1);\n\t\t\t\tv=temp;\n\t\t\t}\n\n\t\t\tvo
abhinav_0107
NORMAL
2022-10-01T18:58:03.353364+00:00
2022-10-01T18:59:15.520582+00:00
906
false
![image](https://assets.leetcode.com/users/images/830cdb8a-b6c4-432c-a633-e6324e10421f_1664650348.5840409.png)\n\n\tclass LUPrefix {\n\t\tpublic:\n\t\t\tvector<int> v;\n\t\t\tint it=0;\n\t\t\tLUPrefix(int n) {\n\t\t\t\tvector<int> temp(n,-1);\n\t\t\t\tv=temp;\n\t\t\t}\n\n\t\t\tvoid upload(int video) {\n\t\t\t\tv[video-...
3
0
['C', 'C++']
0
longest-uploaded-prefix
JAVA solution | HashSet
java-solution-hashset-by-sourin_bruh-b73l
Please Upvote !!! (\u25E0\u203F\u25E0)\n\nclass LUPrefix {\n Set<Integer> set;\n int maxConsecutiveVideo = 0;\n \n public LUPrefix(int n) {\n
sourin_bruh
NORMAL
2022-10-01T18:05:30.507548+00:00
2022-10-01T18:05:30.507574+00:00
368
false
### ***Please Upvote !!!*** **(\u25E0\u203F\u25E0)**\n```\nclass LUPrefix {\n Set<Integer> set;\n int maxConsecutiveVideo = 0;\n \n public LUPrefix(int n) {\n set = new HashSet<>();\n }\n \n public void upload(int video) {\n set.add(video);\n while (set.contains(maxConsecutiveV...
3
0
['Java']
0
longest-uploaded-prefix
easy implementation O(n) in vector || comments|| beginner friendly
easy-implementation-on-in-vector-comment-lzkw
\tclass LUPrefix {\n private:\n vector v;\n int i;\n\tpublic:\n LUPrefix(int n) {\n v.resize(n+1);\n\t\t//take i from start\n i=0;\n
sjain8078
NORMAL
2022-10-01T16:03:35.221525+00:00
2022-10-01T17:13:21.977631+00:00
218
false
\tclass LUPrefix {\n private:\n vector<int> v;\n int i;\n\tpublic:\n LUPrefix(int n) {\n v.resize(n+1);\n\t\t//take i from start\n i=0;\n // memset(v.begin(),v.end(),0);\n }\n \n void upload(int video) {\n\t//upload it to the previous index so we can track it\n v[video-1]...
3
0
['Design', 'C']
0
longest-uploaded-prefix
Using Segment Tree Approach
using-segment-tree-approach-by-jayush10a-tgdb
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
jayush10ashu
NORMAL
2024-01-18T21:44:45.770255+00:00
2024-01-18T21:44:45.770297+00:00
72
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
['Segment Tree', 'C++']
0
longest-uploaded-prefix
Easy Solution Using Max & Min Heap
easy-solution-using-max-min-heap-by-shri-0tq5
\n\n# Code\n\nclass LUPrefix {\npublic:\n priority_queue<int>q;\n priority_queue<int,vector<int>,greater<int>>q2;\n int prev;\n LUPrefix(int n) {\n
Shristha
NORMAL
2023-02-05T13:08:45.611241+00:00
2023-02-05T13:08:45.611273+00:00
443
false
\n\n# Code\n```\nclass LUPrefix {\npublic:\n priority_queue<int>q;\n priority_queue<int,vector<int>,greater<int>>q2;\n int prev;\n LUPrefix(int n) {\n prev=0;\n }\n \n void upload(int video) {\n q.push(video);\n q2.push(video);\n }\n \n int longest() {\n if(!q.e...
2
0
['Heap (Priority Queue)', 'C++']
0
longest-uploaded-prefix
[Python] Union Find
python-union-find-by-coolguazi-w2d8
\n# Code\n\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.videos = list(range(n + 1))\n self.uploaded = [1] + [0] * (n + 1)\n\n def
coolguazi
NORMAL
2023-01-30T10:55:56.179039+00:00
2023-01-30T10:55:56.179070+00:00
73
false
\n# Code\n```\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.videos = list(range(n + 1))\n self.uploaded = [1] + [0] * (n + 1)\n\n def upload(self, video: int) -> None:\n self.uploaded[video] = 1\n if self.uploaded[video + 1]: self.union(video, video + 1)\n if self.uplo...
2
0
['Union Find', 'Python3']
0
longest-uploaded-prefix
very simple solution using bitarray
very-simple-solution-using-bitarray-by-d-4nfc
Intuition\nUse an array to keep the indexes of the videos that has been uploaded, and a variable llp (Last Longest Prefix) to keep the last longer prefix\n\n# A
dwluciano
NORMAL
2022-12-12T20:14:47.667377+00:00
2022-12-12T20:15:18.776228+00:00
37
false
# Intuition\nUse an array to keep the indexes of the videos that has been uploaded, and a variable llp (Last Longest Prefix) to keep the last longer prefix\n\n# Approach\nUse bit array to keep the indexes of the uploaded videos, and precalculate the LUP on each upload, this means to loop through the bit array until a n...
2
0
['Bit Manipulation', 'C#']
0
longest-uploaded-prefix
Easiest approach | C++ | Vector
easiest-approach-c-vector-by-yashrajyash-fshv
\nclass LUPrefix {\npublic:\n vector<int> arr;\n int ptr = 0;\n LUPrefix(int n) {\n arr.resize(n, 0);\n }\n \n void upload(int video) {
yashrajyash
NORMAL
2022-11-04T12:21:27.907972+00:00
2022-11-04T12:21:27.908019+00:00
30
false
```\nclass LUPrefix {\npublic:\n vector<int> arr;\n int ptr = 0;\n LUPrefix(int n) {\n arr.resize(n, 0);\n }\n \n void upload(int video) {\n arr[video-1]++;\n }\n \n int longest() {\n while(ptr < arr.size() && arr[ptr] != 0)\n ptr++;\n return ptr;\n }...
2
0
['Array', 'C', 'C++']
0
longest-uploaded-prefix
[JAVA] Three Approaches [ Segment Tree + Binary Search ] [ Union Find] [Array Based]
java-three-approaches-segment-tree-binar-78xe
\n\n# Segment Tree + Binary Search\n\n\nclass LUPrefix {\n int tree [] ;\n int update(int l , int r , int index,int value){\n if(l==r && l==value){
aniket7419
NORMAL
2022-10-02T17:37:30.688751+00:00
2022-10-02T17:37:30.688793+00:00
179
false
\n\n# Segment Tree + Binary Search\n```\n\nclass LUPrefix {\n int tree [] ;\n int update(int l , int r , int index,int value){\n if(l==r && l==value){\n tree[index] = 1;\n return 1;\n }\n int mid = (l+r)/2;\n if(r<value || value<l) return tree[index];\n els...
2
0
['Java']
0
longest-uploaded-prefix
C++ | Using Vector | Time Complexity - O(N) | Space Complexity - O(N)
c-using-vector-time-complexity-on-space-qnt78
\nclass LUPrefix {\nprivate:\n int i;\n int n;\n vector<int> nums;\npublic:\n LUPrefix(int N) {\n i = 0;\n n = N+2;\n nums.resi
CPP_Bot
NORMAL
2022-10-02T01:53:34.025574+00:00
2022-10-02T01:53:34.025615+00:00
284
false
```\nclass LUPrefix {\nprivate:\n int i;\n int n;\n vector<int> nums;\npublic:\n LUPrefix(int N) {\n i = 0;\n n = N+2;\n nums.resize(n, -1);\n }\n \n void upload(int video) {\n nums[video] = 1;\n while(i<n && (nums[i+1]!=-1)){\n i++;\n } \n ...
2
0
['C']
0
longest-uploaded-prefix
[Python] Union-Find
python-union-find-by-dazzbourgh-cfpt
When adding an element, it becomes a member of its own set. Then if a video behind it was uploaded, go ahead and union new set with the previous one. Similarly,
dazzbourgh
NORMAL
2022-10-01T19:51:57.798551+00:00
2022-10-01T19:51:57.798590+00:00
146
false
When adding an element, it becomes a member of its own set. Then if a video behind it was uploaded, go ahead and union new set with the previous one. Similarly, if there\'s another set right after it - merge these two, too.\n\n```\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.uploaded = [0] * (n + 1...
2
0
['Union Find', 'Python']
0
longest-uploaded-prefix
Few Lines of Code That you should See.O(1)
few-lines-of-code-that-you-should-seeo1-bwrtt
\n
abhinaychaturvedi88
NORMAL
2022-10-01T17:44:05.114756+00:00
2022-10-01T17:50:12.188768+00:00
145
false
![image](https://assets.leetcode.com/users/images/98976518-fc55-4008-a8ae-2d03da6a3a3e_1664646440.7935584.png)\n
2
0
[]
0
longest-uploaded-prefix
C++ | Easy Understanding
c-easy-understanding-by-coderabhi2308-6bgs
Self Explanatory Solution\n\nclass LUPrefix {\npublic:\n int ans=0;\n vector< int >isUpdated;\n \n LUPrefix( int n ) {\n isUpdated.assign( n+
CoderAbhi2308
NORMAL
2022-10-01T16:33:42.669069+00:00
2022-10-01T16:34:56.349959+00:00
90
false
Self Explanatory Solution\n\n```class LUPrefix {\npublic:\n int ans=0;\n vector< int >isUpdated;\n \n LUPrefix( int n ) {\n isUpdated.assign( n+2 , 0 );\n }\n \n void upload( int video ) {\n isUpdated[ video ] = 1;\n while ( isUpdated[ ans + 1 ] == 1 )\n {\n a...
2
0
['C', 'Binary Tree']
0
longest-uploaded-prefix
Python clean
python-clean-by-404akhan-mdny
\n# N2. Longest Uploaded Prefix\nclass LUPrefix:\n def __init__(self, n: int):\n self.arr = [0] * (n + 2)\n self.ans = 0\n\n def upload(self
404akhan
NORMAL
2022-10-01T16:17:55.888047+00:00
2022-10-01T16:17:55.888075+00:00
150
false
```\n# N2. Longest Uploaded Prefix\nclass LUPrefix:\n def __init__(self, n: int):\n self.arr = [0] * (n + 2)\n self.ans = 0\n\n def upload(self, video: int) -> None:\n self.arr[video] = 1\n\n def longest(self) -> int:\n # answer only grows up, by 1\n while self.arr[self.ans +...
2
0
[]
0
longest-uploaded-prefix
C++ | Easy to Understand | Using Vector
c-easy-to-understand-using-vector-by-dhe-680l
\nclass LUPrefix {\npublic:\n vector<int> v;\n int maxi=1;\n LUPrefix(int n) \n {\n v.resize(n+2, 0); \n v[0]=1;\n maxi=1;\n
dheerajkarwasra
NORMAL
2022-10-01T16:16:18.417072+00:00
2022-10-01T17:23:05.324226+00:00
29
false
```\nclass LUPrefix {\npublic:\n vector<int> v;\n int maxi=1;\n LUPrefix(int n) \n {\n v.resize(n+2, 0); \n v[0]=1;\n maxi=1;\n }\n \n void upload(int video) \n {\n v[video]=1; \n while(v[maxi])\n maxi++;\n }\n \n int longest() \n {\n ...
2
0
['C']
0
longest-uploaded-prefix
One Liner functions using vectors O(n) solution
one-liner-functions-using-vectors-on-sol-6kre
Explanation :\n1) i(variable) stores the current index upto which video prefixes from 1 to i-1 are all uploades.\n2) If a videos is uploaded while loop wil
Priyanshu_Chaudhary_
NORMAL
2022-10-01T16:13:35.320865+00:00
2022-10-01T17:19:20.456942+00:00
255
false
Explanation :\n1) i(variable) stores the current index upto which video prefixes from 1 to i-1 are all uploades.\n2) If a videos is uploaded while loop will loop till it gets an unuploaded video \n3) Since all values are being travel only once the time complextity will be O(n).\n\n```\nclass LUPrefix {\npublic:\...
2
0
['Array', 'C']
1
longest-uploaded-prefix
✅✅✅🤓😎O(n) Solution with Most Easy Solution and Question too
on-solution-with-most-easy-solution-and-j0yar
****Very Simple and Straight Forward Approch\n\n\nclass LUPrefix {\n\n private: vector<bool>server;\n int ind=-1,maxi=0,_n;\n public:\n
abhigupta7049612180
NORMAL
2022-10-01T16:06:18.488814+00:00
2022-10-01T16:15:50.118838+00:00
363
false
****Very Simple and Straight Forward Approch\n\n```\nclass LUPrefix {\n\n private: vector<bool>server;\n int ind=-1,maxi=0,_n;\n public:\n LUPrefix(int n) {\n server.resize(n+5,0);\n server[0]=1;\n _n=n;\n }\n \n void upload(int video) {\n server[video]=1;\n...
2
0
['Array', 'C++']
1
longest-uploaded-prefix
[Python3] One-Pass Solution O(n), Clean & Concise
python3-one-pass-solution-on-clean-conci-18ws
\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.videos = [False] * (n + 1)\n self.ans = 0\n\n def upload(self, video: int) -> None:
xil899
NORMAL
2022-10-01T16:03:04.790824+00:00
2022-10-01T16:03:04.790864+00:00
480
false
```\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.videos = [False] * (n + 1)\n self.ans = 0\n\n def upload(self, video: int) -> None:\n self.videos[video] = True\n if video == self.ans + 1:\n while video < len(self.videos):\n if not self.videos[video...
2
0
['Python', 'Python3']
0
longest-uploaded-prefix
simple code | streak method
simple-code-streak-method-by-priyanshuhe-pxzu
\nunordered_map<int, int> mp;\n LUPrefix(int n) {\n for(int i=0;i<n;i++)\n mp[i+1] = 0;\n }\n \n void upload(int video) {\n
priyanshuHere27
NORMAL
2022-10-01T16:02:34.845581+00:00
2022-10-01T16:13:26.254144+00:00
33
false
```\nunordered_map<int, int> mp;\n LUPrefix(int n) {\n for(int i=0;i<n;i++)\n mp[i+1] = 0;\n }\n \n void upload(int video) {\n int right = video + 1;\n int left = video - 1;\n int rightStreak = 0, leftStreak = 0;\n \n if(mp[right]!=0)\n rightSt...
2
0
['C', 'Java']
1
longest-uploaded-prefix
C++ | Caching | Beats 98% - TC
c-caching-beats-98-tc-by-ghozt777-6hap
Intuition use array to keep track of the videos uploaded use caching to store previous results of longest() function to avoid recalculation Approach our DS cont
ghozt777
NORMAL
2025-03-25T06:07:11.172885+00:00
2025-03-25T06:07:11.172885+00:00
26
false
# Intuition - use array to keep track of the videos uploaded - use caching to store previous results of `longest()` function to avoid recalculation # Approach - our DS contains a boolean array to store wether the ith video is uploaded or not, variable prefix to keep track of the largest prefix, and another variable to ...
1
0
['C++']
0
longest-uploaded-prefix
(beats 95% for time) Segment tree
beats-95-for-time-segment-tree-by-divyan-qgps
Intuition\nwe can check for the left child and update the parent node on the basis of the left child if the left child dont have the node True the irrespective
Divyansh55BE29
NORMAL
2024-10-02T11:51:17.495872+00:00
2024-10-02T11:51:17.495905+00:00
41
false
# Intuition\nwe can check for the left child and update the parent node on the basis of the left child if the left child dont have the node True the irrespective of the length of the right child and if the left child has a prefix value we can simply add the left and right child for parent value.\n\n# Approach\nSegment ...
1
0
['Segment Tree', 'C++']
0
longest-uploaded-prefix
Segment Tree + binary search longest | O(1) time build, upload, O(logn) time logest(), O(n) space.
segment-tree-binary-search-longest-o1-ti-tzhf
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
ziegfeld
NORMAL
2024-06-21T19:22:50.694902+00:00
2024-06-21T19:22:50.694918+00:00
20
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)$$ --...
1
0
['C++']
1
longest-uploaded-prefix
Python | Union-Find
python-union-find-by-aljipa-9xhf
Code\n\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.prnt = [-1] * n\n self.size = [0] * n\n\n def _find(self, i):\n while
aljipa
NORMAL
2024-03-10T02:12:54.637166+00:00
2024-03-10T02:12:54.637192+00:00
9
false
# Code\n```\nclass LUPrefix:\n\n def __init__(self, n: int):\n self.prnt = [-1] * n\n self.size = [0] * n\n\n def _find(self, i):\n while i != self.prnt[i]:\n i = self._find(self.prnt[i])\n return self.prnt[i]\n \n def _union(self, x, y):\n if x < 0 or y >= len(...
1
0
['Python3']
0
longest-uploaded-prefix
Fenwick Tree Solution || Binary Search || Explained
fenwick-tree-solution-binary-search-expl-3cfj
First Learn Fenwick Tree from here :\nSimple Explanation\nhttps://www.hackerearth.com/practice/notes/binary-indexed-tree-or-fenwick-tree/\nAdvance Versions\nhtt
coder_rastogi_21
NORMAL
2024-02-24T13:52:15.923926+00:00
2024-06-25T06:39:31.056085+00:00
73
false
# First Learn Fenwick Tree from here :\nSimple Explanation\n[https://www.hackerearth.com/practice/notes/binary-indexed-tree-or-fenwick-tree/]()\nAdvance Versions\n[https://cp-algorithms.com/data_structures/fenwick.html]()\n\n\n# Complexity\n- Time complexity:\nupload function: $$O(log(n))$$ \nlongest function: $$O(log(...
1
0
['Binary Search', 'Binary Indexed Tree', 'C++']
1
longest-uploaded-prefix
[Java] Easy 100% solution
java-easy-100-solution-by-ytchouar-1rkl
java\nclass LUPrefix {\n private boolean[] videos;\n private int maxIdx = 0;\n\n public LUPrefix(int n) {\n this.videos = new boolean[n + 1];\n
YTchouar
NORMAL
2024-02-21T03:26:45.035628+00:00
2024-02-21T03:27:19.382606+00:00
191
false
```java\nclass LUPrefix {\n private boolean[] videos;\n private int maxIdx = 0;\n\n public LUPrefix(int n) {\n this.videos = new boolean[n + 1];\n }\n \n public void upload(int video) {\n this.videos[video] = true;\n\n while(maxIdx < this.videos.length - 1 && videos[maxIdx + 1])\n...
1
0
['Java']
0
longest-uploaded-prefix
Java | Array + Max Value
java-array-max-value-by-tbekpro-k5k5
Code\n\nclass LUPrefix {\n\n int res;\n int max;\n int[] arr;\n\n public LUPrefix(int n) {\n res = 0;\n max = 0;\n arr = new in
tbekpro
NORMAL
2023-11-25T14:23:22.935939+00:00
2023-11-25T14:23:22.935956+00:00
117
false
# Code\n```\nclass LUPrefix {\n\n int res;\n int max;\n int[] arr;\n\n public LUPrefix(int n) {\n res = 0;\n max = 0;\n arr = new int[n + 1];\n }\n\n public void upload(int video) {\n arr[video]++;\n max = Math.max(video, max);\n if (video == res + 1) {\n ...
1
0
['Java']
0
longest-uploaded-prefix
"Python Concise and Efficient | Achieving Amortized O(1) Complexity | Annotated for Clarity"
python-concise-and-efficient-achieving-a-gxtm
Intuition & Approach :\nThe class LUPrefix is designed to efficiently track the longest prefix of consecutive integers. It uses a set _nums to store uploaded vi
aditya0542pandey
NORMAL
2023-10-28T06:29:00.598004+00:00
2023-10-28T06:29:00.598026+00:00
7
false
# Intuition & Approach :\nThe class LUPrefix is designed to efficiently track the longest prefix of consecutive integers. It uses a set _nums to store uploaded videos, and the variable _longest to maintain the length of the longest consecutive prefix.\n\nIn the constructor __init__, it initializes _longest to 0 and cre...
1
0
['Python3']
0
longest-uploaded-prefix
Java Average Time complexity O(1)
java-average-time-complexity-o1-by-milan-f6y4
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
milangupta95
NORMAL
2023-08-07T20:10:55.124385+00:00
2023-08-07T20:10:55.124407+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)$$ --...
1
0
['Java']
1
longest-uploaded-prefix
Easy Javascript Solution with array - max 731 ms
easy-javascript-solution-with-array-max-kwe5m
```\nclass LUPrefix{\n constructor(n){\n this.i = 0;\n this.arr = new Array(n);\n //console.log(this.arr);\n }\n / \n * @param {nu
okarademirci
NORMAL
2022-10-20T17:48:07.868916+00:00
2022-10-20T17:48:07.868956+00:00
14
false
```\nclass LUPrefix{\n constructor(n){\n this.i = 0;\n this.arr = new Array(n);\n //console.log(this.arr);\n }\n /** \n * @param {number} video\n * @return {void}\n */\n upload = function(video) {\n this.arr[video-1] = video;\n }\n\n/**\n * @return {number}\n */\n longest =...
1
0
[]
0
longest-uploaded-prefix
Java || TreeSet || union Find
java-treeset-union-find-by-lagahuahubro-8co4
set contains all the videos which are not yet uploaded so smallest number in the TreeSet represent the smallest numbered video that needs to be uploaded.\n\n\nc
lagaHuaHuBro
NORMAL
2022-10-07T09:42:10.110252+00:00
2022-10-07T10:04:03.503252+00:00
45
false
```set contains all the videos which are not yet uploaded so smallest number in the TreeSet represent the smallest numbered video that needs to be uploaded.```\n\n```\nclass LUPrefix {\n TreeSet<Integer> set = new TreeSet<>();\n public LUPrefix(int n) {\n for (int i = 1; i <= n + 1; i++) {\n set...
1
0
[]
0
longest-uploaded-prefix
Rust, HashSet, O(n)
rust-hashset-on-by-goodgoodwish-pb6k
Only record the current end of the prefix [1..i]. Keep extending it while can be extended.\n\nuse std::collections::HashSet;\n\nstruct LUPrefix {\n points:
goodgoodwish
NORMAL
2022-10-07T03:53:04.465331+00:00
2022-10-07T03:53:04.465366+00:00
136
false
Only record the current end of the prefix [1..i]. Keep extending it while can be extended.\n```\nuse std::collections::HashSet;\n\nstruct LUPrefix {\n points: HashSet<i32>,\n far: i32,\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut ...
1
0
['Rust']
0
longest-uploaded-prefix
C++ || Array
c-array-by-sachin-vinod-h487
Approch :-\n1.] Here I am going to use a three number which is -1,0,1 which is as follows ( -1 -> not uploded, 0 -> uploaded but not created prefix , 1 -> uploa
Sachin-Vinod
NORMAL
2022-10-06T11:32:41.360238+00:00
2022-10-06T11:32:41.360285+00:00
267
false
**Approch** :-\n1.] Here I am going to use a three number which is -1,0,1 which is as follows ( -1 -> not uploded, 0 -> uploaded but not created prefix , 1 -> uploaded and created bond with prefix ).\n2.] In upload function what i am going to do is if **curr-1th** is connectd with prefix so we can expand prefix from *...
1
0
['Array', 'C', 'C++']
0
longest-uploaded-prefix
C++ easy and concise solution
c-easy-and-concise-solution-by-sanket070-flpj
Happy Leetcoding !\n\n\nclass LUPrefix {\npublic:\n set<int>st;\n LUPrefix(int n) {\n for(int i=1;i<=n+1;i++)\n {\n st.insert(i);
sanket0708
NORMAL
2022-10-06T04:54:49.166637+00:00
2022-10-06T04:54:49.166683+00:00
61
false
Happy Leetcoding !\n\n```\nclass LUPrefix {\npublic:\n set<int>st;\n LUPrefix(int n) {\n for(int i=1;i<=n+1;i++)\n {\n st.insert(i);\n }\n }\n \n void upload(int video) {\n st.erase(video);\n }\n \n int longest() {\n return (*st.begin())-1;\n }\n};...
1
0
[]
0
longest-uploaded-prefix
Easy JS Solution: Queue
easy-js-solution-queue-by-dollysingh-tuzp
Explanation:\nData structure : Queue. \n\n\nvar LUPrefix = function(n) {\n let q = new Array(n).fill(0);\n this.q = q;\n this.f = 0; //"f" is front of
dollysingh
NORMAL
2022-10-04T18:00:09.101073+00:00
2022-10-04T18:00:09.101113+00:00
84
false
**Explanation:**\nData structure : Queue. \n\n```\nvar LUPrefix = function(n) {\n let q = new Array(n).fill(0);\n this.q = q;\n this.f = 0; //"f" is front of queue\n};\n\n//O(1)\nLUPrefix.prototype.upload = function(video) {\n this.q[video - 1] = 1;\n};\n\n//O(n)\nLUPrefix.prototype.longest = function() {\n...
1
0
['Queue', 'JavaScript']
0
longest-uploaded-prefix
✅ [Rust] fastest (100%) solution using boolean array (with detailed comments)
rust-fastest-100-solution-using-boolean-is2la
This solution employs a simple boolean array to store the upload status that is used to update longest prefix index. It demonstrated 98 ms runtime (100.00%) and
stanislav-iablokov
NORMAL
2022-10-03T12:16:22.056899+00:00
2022-10-23T12:46:40.488448+00:00
79
false
This [**solution**](https://leetcode.com/submissions/detail/814188631/) employs a simple boolean array to store the upload status that is used to update longest prefix index. It demonstrated **98 ms runtime (100.00%)** and used **54.5 MB memory (100.00%)**. Time complexity is linear: **O(N)**. Space complexity is const...
1
0
['Array', 'Rust']
0
longest-uploaded-prefix
C++ solution using Fenwick Tree + Binary Search
c-solution-using-fenwick-tree-binary-sea-u5lf
Solution:\n```\ntemplate\nclass BIT {\npublic:\n vector bit;\n int n;\n \n BIT() {}\n \n BIT(int _n) {\n n = _n;\n bit = vector(
dhavalkumar
NORMAL
2022-10-03T05:10:37.023618+00:00
2022-10-03T05:10:37.023657+00:00
157
false
**Solution:**\n```\ntemplate<typename T>\nclass BIT {\npublic:\n vector<T> bit;\n int n;\n \n BIT() {}\n \n BIT(int _n) {\n n = _n;\n bit = vector<T>(n, 0LL);\n }\n \n void inc(int idx, T val) {\n for(int i = idx + 1; i <= n; i += (i & -i)) \n bit[i - 1] += val...
1
0
['Binary Indexed Tree', 'Binary Tree']
0
longest-uploaded-prefix
[Python 3] Only update left and right endpoints | Time O(1), Space O(N)
python-3-only-update-left-and-right-endp-q2lv
If we maintain a list for all the segments so far, the longest uploaded prefix essentially is the size of the first element a.k.a self.P[1] in my case for avoid
zhuzhengyuan824
NORMAL
2022-10-02T20:54:45.459935+00:00
2022-10-02T20:58:54.059587+00:00
165
false
If we maintain a list for all the segments so far, the longest uploaded prefix essentially is the size of the first element a.k.a `self.P[1]` in my case for avoiding index overflow.\n\nThe only tricky part is the way to update left&right most endpoints: \n1. find left most endpoint(`x-self.P[x-1]`) and rightmost endpoi...
1
0
['Python']
0
longest-uploaded-prefix
c++ simple solution
c-simple-solution-by-hanzhoutang-ue1x
The idea is that after one video has been uploaded, it will never be removed, which means the logested prefix keeps growing and we can simply track the by a si
hanzhoutang
NORMAL
2022-10-02T20:23:27.212958+00:00
2022-10-02T20:25:36.980115+00:00
35
false
The idea is that after one video has been uploaded, it will never be removed, which means the logested prefix keeps growing and we can simply track the by a single variable. (The intuition here is very samilar to sliding window)\nAnd since the simple variable will move from 0 to n. We know the time complixity is actua...
1
0
[]
0
longest-uploaded-prefix
c#, Sorted Set
c-sorted-set-by-bytchenko-bcn3
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can store unloaded chunks, so to compupute the prefix we should find the min unloade
bytchenko
NORMAL
2022-10-02T10:38:04.664043+00:00
2022-10-02T10:38:04.664089+00:00
29
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can store **unloaded** chunks, so to compupute the prefix we should find the min unloaded chunk.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can use `SortedSet<int>` to store **unloaded** chunks\n\n# Comp...
1
0
['C#']
0
longest-uploaded-prefix
C++ | Vector | Pointer | Well Commented | O(n) solution
c-vector-pointer-well-commented-on-solut-ydhx
Please upvote if you like!!\n\nTC: O(n)\nSC: O(n)\n\nclass LUPrefix {\npublic:\n\t// we will use a vector to keep track of the uploaded videos\n vector<int>
_prit
NORMAL
2022-10-02T05:32:50.845855+00:00
2022-10-02T05:33:13.710056+00:00
55
false
**Please upvote if you like!!**\n\nTC: O(n)\nSC: O(n)\n``` \nclass LUPrefix {\npublic:\n\t// we will use a vector to keep track of the uploaded videos\n vector<int> v;\n int pointer;\n \n LUPrefix(int n) {\n\t\t// initialize the vector of size (n+1) as the video indexes start from 1 to n\n v.resize(n...
1
0
['C']
0
longest-uploaded-prefix
C++ || Easy & Simple || Amortized O(1) || 100% faster
c-easy-simple-amortized-o1-100-faster-by-dtl7
\nclass LUPrefix {\npublic:\n vector<bool>uploaded;\n int size;\n int longestPrefix;\n LUPrefix(int n) {\n size = n;\n uploaded.resize
AJAY_MAKVANA
NORMAL
2022-10-02T05:09:00.167742+00:00
2022-10-02T05:10:33.439512+00:00
58
false
```\nclass LUPrefix {\npublic:\n vector<bool>uploaded;\n int size;\n int longestPrefix;\n LUPrefix(int n) {\n size = n;\n uploaded.resize(size + 1, false);\n longestPrefix = 0;\n }\n\n void upload(int video) {\n uploaded[video] = true;\n }\n\n int longest() {\n ...
1
0
['C', 'C++']
0
longest-uploaded-prefix
C++|| SET|| Easy
c-set-easy-by-aakash_172-2guk
\nclass LUPrefix {\npublic:\n set<int>st;\n LUPrefix(int n) {\n for(int i=1;i<=n+1;i++){\n st.insert(i);\n }\n }\n \n vo
aakash_172
NORMAL
2022-10-01T21:36:37.768224+00:00
2022-10-01T21:36:37.768263+00:00
38
false
```\nclass LUPrefix {\npublic:\n set<int>st;\n LUPrefix(int n) {\n for(int i=1;i<=n+1;i++){\n st.insert(i);\n }\n }\n \n void upload(int video) {\n st.erase(video);\n }\n \n int longest() {\n return (*st.begin())-1;\n }\n};\n```
1
0
['C', 'Ordered Set']
0
longest-uploaded-prefix
Easy and optimized python3 solution
easy-and-optimized-python3-solution-by-m-4mi8
class LUPrefix:\n\n def init(self, n: int):\n \n self.v = [0]*(n+1)\n self.cur = 1\n \n\n def upload(self, video: int) -> None
mayankmaheshwari
NORMAL
2022-10-01T20:21:41.712865+00:00
2022-10-01T20:23:44.703539+00:00
123
false
class LUPrefix:\n\n def __init__(self, n: int):\n \n self.v = [0]*(n+1)\n self.cur = 1\n \n\n def upload(self, video: int) -> None:\n self.v[video] = 1\n if video == self.cur:\n self.cur+=1\n \n while self.cur<len(self.v) and self.v[self.cur]!=0:\...
1
0
['Python3']
0
longest-uploaded-prefix
Python All O(1) endpoint algorithm, no amortization
python-all-o1-endpoint-algorithm-no-amor-3hod
It\'s quite straightforward to get amortized O(logn) with SortedList or amortized O(1) by counting up till the missing video. However, if you are familiar with
chuan-chih
NORMAL
2022-10-01T19:59:08.486019+00:00
2022-10-01T20:22:44.692065+00:00
167
false
It\'s quite straightforward to get amortized `O(logn)` with `SortedList` or amortized `O(1)` by counting up till the missing `video`. However, if you are familiar with the "endpoint algorithm" that keeps track of all the contiguous segments, it\'s just as simple to get an all `O(1)` algorithm:\n\n1. Use `left` and `rig...
1
0
['Python']
1
longest-uploaded-prefix
Python Easy Solution
python-easy-solution-by-titanolodon-xkq4
\nclass LUPrefix:\n\n def __init__(self, n: int) -> None:\n \n self.uploaded = set()\n self.prefix = list(range(n, -1, -1))\n \n
Titanolodon
NORMAL
2022-10-01T19:31:25.046012+00:00
2022-10-01T19:31:25.046051+00:00
78
false
```\nclass LUPrefix:\n\n def __init__(self, n: int) -> None:\n \n self.uploaded = set()\n self.prefix = list(range(n, -1, -1))\n \n def upload(self, video: int) -> None:\n \n self.uploaded.add(video - 1)\n\t\t\n while self.prefix[-1] in self.uploaded:\n ...
1
0
['Python']
0
longest-uploaded-prefix
Java Array Solution
java-array-solution-by-solved-yrk6
\nclass LUPrefix {\n boolean[] array;\n int maxSize;\n public LUPrefix(int n) {\n this.array = new boolean[n];\n this.maxSize = 0;\n }
solved
NORMAL
2022-10-01T19:13:03.012999+00:00
2022-10-01T19:13:03.013043+00:00
61
false
```\nclass LUPrefix {\n boolean[] array;\n int maxSize;\n public LUPrefix(int n) {\n this.array = new boolean[n];\n this.maxSize = 0;\n }\n public void upload(int video) {\n array[video - 1] = true;\n int count = 0;\n for (int i = 0; i < array.length; i++) {\n ...
1
0
['Array', 'Java']
0
longest-uploaded-prefix
O(nlogn) using merging lower upper bound intervals
onlogn-using-merging-lower-upper-bound-i-oh59
Main Idea:\n+ Managing lower/upper bound intervals\n+ Uploading method:\n + vmin, vmax = video, video\n + Find upper bound interval: video - 1 -> found: vmin
dntai
NORMAL
2022-10-01T18:13:23.528707+00:00
2022-10-01T18:13:23.528750+00:00
121
false
**Main Idea**:\n+ Managing lower/upper bound intervals\n+ Uploading method:\n + vmin, vmax = video, video\n + Find upper bound interval: video - 1 -> found: vmin = min(interval), delete lower/upper bound intervals corresponding\n + Find lower bound interval: video + 1 -> found: vmax = max(interval), delete lower/upp...
1
0
['Python3']
0
longest-uploaded-prefix
Simple swift solution
simple-swift-solution-by-zhedre1n-565v
\nclass LUPrefix {\n var last = 0\n var cache = Set<Int>()\n\n init(_ n: Int) {}\n \n func upload(_ video: Int) {\n appendIfNeeded(video)\
ZheDre1N
NORMAL
2022-10-01T18:09:17.364618+00:00
2022-10-01T18:25:32.436772+00:00
50
false
```\nclass LUPrefix {\n var last = 0\n var cache = Set<Int>()\n\n init(_ n: Int) {}\n \n func upload(_ video: Int) {\n appendIfNeeded(video)\n }\n \n func longest() -> Int {\n last\n }\n \n private func appendIfNeeded(_ video: Int) {\n if last + 1 == video {\n ...
1
0
['Swift']
0
longest-uploaded-prefix
Two very efficient Solutions | Python
two-very-efficient-solutions-python-by-s-v321
Sorted List solution:\n\nfrom sortedcontainers import SortedList\n\nclass LUPrefix:\n def __init__(self, n: int):\n self.notUploaded = SortedList(i fo
swissnerd
NORMAL
2022-10-01T17:55:12.521228+00:00
2022-10-01T18:51:18.230826+00:00
71
false
**Sorted List** solution:\n```\nfrom sortedcontainers import SortedList\n\nclass LUPrefix:\n def __init__(self, n: int):\n self.notUploaded = SortedList(i for i in range(n + 1))\n # Time: O(n)\n # Space: O(n)\n\n def upload(self, video: int) -> None:\n self.notUploaded.remove(video - 1)\n #...
1
0
['Python']
0