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
find-the-student-that-will-replace-the-chalk
Simple | Short | C++ | O(n)
simple-short-c-on-by-gavnish_kumar-0gcr
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst of all we calculate the sum of chalk used by all students,\nNow if we divide k wi
gavnish_kumar
NORMAL
2024-09-02T04:14:34.900612+00:00
2024-09-02T04:15:48.386510+00:00
34
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst of all we calculate the sum of chalk used by all students,\nNow if we divide `k` with sum then we get number of circle formed,\nso `k%sum` will give us the chalk left for last round.\nso we will traverse for last round and whenever ...
2
0
['C++']
0
find-the-student-that-will-replace-the-chalk
C++ || Easy Video Solution || Faster than 98.12%
c-easy-video-solution-faster-than-9812-b-3s52
The video solution for the below code is\nhttps://youtu.be/mch99mRQUFE\n\n# Code\ncpp []\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, i
__SAI__NIVAS__
NORMAL
2024-09-02T02:06:50.751775+00:00
2024-09-02T02:06:50.751806+00:00
182
false
The video solution for the below code is\nhttps://youtu.be/mch99mRQUFE\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // Note points:\n // The number of studen...
2
0
['C++']
1
find-the-student-that-will-replace-the-chalk
O(n) solution
on-solution-by-rgoswami3419-hizt
Intuition\nTo determine which student will be the first to run out of chalk, we need to simulate the distribution of chalk among students. Given a list of chalk
rgoswami3419
NORMAL
2024-09-02T02:04:40.924049+00:00
2024-09-02T02:04:40.924070+00:00
203
false
# Intuition\nTo determine which student will be the first to run out of chalk, we need to simulate the distribution of chalk among students. Given a list of chalk amounts and a number `k` representing the total chalk pieces, we can optimize the process by calculating the remainder of chalk after a full cycle of all stu...
2
0
['Java']
0
find-the-student-that-will-replace-the-chalk
DCC 2 SEPTEMBER 2024 || Arrays🔥
dcc-2-september-2024-arrays-by-sajaltiwa-i5li
Approach and Intuition:\n\n1. Understanding the Problem:\n - You have an array chalk where each element represents the amount of chalk a student uses.\n - I
sajaltiwari007
NORMAL
2024-09-02T02:03:18.150379+00:00
2024-09-02T02:03:18.150410+00:00
36
false
### Approach and Intuition:\n\n1. **Understanding the Problem:**\n - You have an array `chalk` where each element represents the amount of chalk a student uses.\n - Initially, there are `k` units of chalk available.\n - Starting from the first student, each student uses up the amount of chalk specified by their r...
2
0
['Array', 'Java']
0
find-the-student-that-will-replace-the-chalk
Get total sum of chalk, then mod by k O(N)
get-total-sum-of-chalk-then-mod-by-k-on-96bjf
\n# Approach\nGet the total amount of chalk that the students will use. Then take the total MOD k to get the amount of chalk that will be left in the last roun
midnightsimon
NORMAL
2024-09-02T01:49:50.196179+00:00
2024-09-02T01:49:50.196215+00:00
33
false
\n# Approach\nGet the total amount of chalk that the students will use. Then take the total MOD k to get the amount of chalk that will be left in the last round of chalk distribution.\n\n# Complexity\n- Time complexity:\nO(n)\nWe do two passes. The first pass is to get the total sum of chalk, then we iterate over cha...
2
0
['C++']
0
find-the-student-that-will-replace-the-chalk
Student that will replace chalk -🌟 Unique Solution 🌟
student-that-will-replace-chalk-unique-s-koiu
Intuition\n1. Find the sum of all elements in the chalk so that we can get the chalk used in the single turn of students from 0 to n-1.\n\n2. Using that,we\'ll
RAJESWARI_P
NORMAL
2024-09-02T01:41:02.963017+00:00
2024-09-02T01:41:02.963047+00:00
37
false
# Intuition\n1. Find the sum of all elements in the chalk so that we can get the chalk used in the single turn of students from 0 to n-1.\n\n2. Using that,we\'ll find the chalk that will remain after the number of full complete turn ends.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approac...
2
0
['Array', 'Java']
0
find-the-student-that-will-replace-the-chalk
Beginner-level Go code on PrefixSum + BinarySearch
beginner-level-go-code-on-prefixsum-bina-zt42
Code\ngolang []\nfunc chalkReplacer(chalk []int, k int) int {\n n := len(chalk)\n if n > 0 && chalk[0] > k {\n return 0\n }\n for i := 1; i <
casualcow
NORMAL
2024-09-02T01:13:06.747682+00:00
2024-09-02T01:13:06.747708+00:00
44
false
# Code\n```golang []\nfunc chalkReplacer(chalk []int, k int) int {\n n := len(chalk)\n if n > 0 && chalk[0] > k {\n return 0\n }\n for i := 1; i < n; i++ {\n chalk[i] += chalk[i-1]//in-place modification as prefix sum\n if chalk[i] > k {\n return i\n }\n }\n k %=...
2
0
['Binary Search', 'Prefix Sum', 'Go']
1
find-the-student-that-will-replace-the-chalk
Easy-To-Understand 5-Line and Most Optimal Solution, Beats 95% in Python!!
easy-to-understand-5-line-and-most-optim-vi2f
Intuition\n Describe your first thoughts on how to solve this problem. \nThe trick is to iterate over all of the elements of chalk with each iteration reducing
NickieChmikie
NORMAL
2024-09-02T01:03:04.949139+00:00
2024-09-02T01:06:47.749584+00:00
353
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe trick is to iterate over all of the elements of ```chalk``` with each iteration reducing the value of ```k``` by the value of ```chalk[i]```, until the value of ```k``` is negative, meaning that the current element ```chalk[i]``` need...
2
0
['Array', 'Binary Search', 'Simulation', 'Prefix Sum', 'Python3']
3
find-the-student-that-will-replace-the-chalk
[Swift] 1 line, reductions(_:), partitioningIndex(where:)
swift-1-line-reductions_-partitioningind-0kad
\n\n# Code\nswift []\nimport Algorithms\n\nclass Solution {\n func chalkReplacer(_ chalk: [Int], _ k: Int) -> Int {\n chalk.reductions(+).partitioning
iamhands0me
NORMAL
2024-09-02T00:38:30.057184+00:00
2024-09-02T00:38:30.057202+00:00
41
false
\n\n# Code\n```swift []\nimport Algorithms\n\nclass Solution {\n func chalkReplacer(_ chalk: [Int], _ k: Int) -> Int {\n chalk.reductions(+).partitioningIndex { $0 > k % chalk.reduce(into: 0, +=) }\n }\n}\n```
2
0
['Binary Search', 'Swift', 'Prefix Sum']
1
find-the-student-that-will-replace-the-chalk
Java easy solution || Beats 100%
java-easy-solution-beats-100-by-agrwlaan-bq7t
\nclass Solution {\n public int chalkReplacer(int[] chalk, int k) {\n\t\t\n\t\t//get prefix sum of the array\n long sum =0;\n for(int i=0;i<cha
agrwlaanchal
NORMAL
2024-07-06T11:05:37.799457+00:00
2024-07-06T11:05:37.799506+00:00
145
false
```\nclass Solution {\n public int chalkReplacer(int[] chalk, int k) {\n\t\t\n\t\t//get prefix sum of the array\n long sum =0;\n for(int i=0;i<chalk.length;i++){ \n sum+=chalk[i]; \n }\n \n\t\t// count the k based on sum \n\t\t//convert to int\n k = (int)(k % ...
2
0
['Array', 'Prefix Sum', 'Java']
2
find-the-student-that-will-replace-the-chalk
simple simulation || easy to understand || must see
simple-simulation-easy-to-understand-mus-h2is
Code\n\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& arr, int k) {\n \n //n == chalk.size();\n\n //students numbered fro
akshat0610
NORMAL
2024-04-29T07:02:57.942552+00:00
2024-04-29T07:02:57.942581+00:00
128
false
# Code\n```\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& arr, int k) {\n \n //n == chalk.size();\n\n //students numbered from 0 to n-1\n //0 1 2 3 4. . . . . . . . . . n-1 \n\n //k peices of chalk \n\n //we need to tell the first index on which on the k ...
2
0
['Array', 'Binary Search', 'Simulation', 'Prefix Sum', 'C++']
0
find-the-student-that-will-replace-the-chalk
Easy Solution | Java | Python
easy-solution-java-python-by-atharva77-fddm
Python\n\nclass Solution:\n def chalkReplacer(self, chalk: List[int], k: int) -> int:\n sums = sum(chalk)\n div = k // sums\n k = k - (s
atharva77
NORMAL
2023-03-24T13:13:24.217107+00:00
2023-03-24T13:13:24.217154+00:00
337
false
# Python\n```\nclass Solution:\n def chalkReplacer(self, chalk: List[int], k: int) -> int:\n sums = sum(chalk)\n div = k // sums\n k = k - (sums * div)\n for i in range(len(chalk)):\n if chalk[i] <= k:\n k -= chalk[i]\n else:\n return i\...
2
0
['Java', 'Python3']
1
find-the-student-that-will-replace-the-chalk
C++ | Binary Search
c-binary-search-by-deepak_2311-v03d
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
godmode_2311
NORMAL
2023-03-13T18:09:13.081292+00:00
2023-03-13T18:54:40.943900+00:00
276
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']
1
find-the-student-that-will-replace-the-chalk
cpp easy solution || faster then 100% cpp solution
cpp-easy-solution-faster-then-100-cpp-so-kze4
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
ankit_kumar12345
NORMAL
2023-03-13T17:31:36.165598+00:00
2023-03-13T17:37:37.830277+00:00
387
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:\nO(k)\n\n- Space complexity:\no(1)\n\n# Code\n```\nclass Solution\n{\npublic:\n int chalkReplacer(vector<int> &chalk, int k)\n ...
2
0
['C++']
2
find-the-student-that-will-replace-the-chalk
[Python3] Prefix Sum + Binary Search - Easy to Understand
python3-prefix-sum-binary-search-easy-to-m91v
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
dolong2110
NORMAL
2023-02-25T08:27:16.191369+00:00
2023-02-25T08:27:16.191422+00:00
322
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n + logn) ~ O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space c...
2
0
['Binary Search', 'Prefix Sum', 'Python3']
0
find-the-student-that-will-replace-the-chalk
C++ CODE || Prefix Sum
c-code-prefix-sum-by-chiikuu-gfzt
Intuition\n *k is remainder of total sum of array.*\n Describe your first thoughts on how to solve this problem. \n# Complexity\n- Time complexity: O(n)\n Add y
CHIIKUU
NORMAL
2023-02-14T07:07:34.316633+00:00
2023-02-14T07:07:34.316669+00:00
282
false
# Intuition\n *********k is remainder of total sum of array.*********\n<!-- Describe your first thoughts on how to solve this problem. -->\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n...
2
0
['Binary Search', 'Prefix Sum', 'C++']
0
find-the-student-that-will-replace-the-chalk
Simple Java solution
simple-java-solution-by-abstractconnoiss-9wpq
Code\n\nclass Solution {\n\tpublic int chalkReplacer(int[] chalk, int k) {\n\t\tlong sum = 0;\n\t\tfor (int c : chalk) {\n\t\t\tsum += c;\n\t\t}\n\t\tlong left
abstractConnoisseurs
NORMAL
2023-01-26T06:37:28.696049+00:00
2023-01-26T06:37:28.696090+00:00
206
false
# Code\n```\nclass Solution {\n\tpublic int chalkReplacer(int[] chalk, int k) {\n\t\tlong sum = 0;\n\t\tfor (int c : chalk) {\n\t\t\tsum += c;\n\t\t}\n\t\tlong left = k % sum;\n\t\tfor (int i = 0; i < chalk.length; i++) {\n\t\t\tif(left >= chalk[i]) {\n\t\t\t\tleft -= chalk[i];\n\t\t\t} else {\n\t\t\t\treturn i;\n\t\t\...
2
0
['Array', 'Binary Search', 'Simulation', 'Prefix Sum', 'Java']
1
find-the-student-that-will-replace-the-chalk
Prefix Array and BinarySearch
prefix-array-and-binarysearch-by-vasakri-u29p
Intuition\nCreate Prefix array and find the student who ran out of chalks\n\n# Approach\n1. Create Prefix Array\n2. Modulo K to find chalks at last loop\n3. Fin
vasakris
NORMAL
2022-12-11T10:48:37.947690+00:00
2022-12-11T10:48:37.947735+00:00
265
false
# Intuition\nCreate Prefix array and find the student who ran out of chalks\n\n# Approach\n1. Create Prefix Array\n2. Modulo K to find chalks at last loop\n3. Find student who rans out of chalk using BinarySearch\n\n# Complexity\n- Time complexity:\nO(n + logn)\n\n- Space complexity:\nO(1), reusing input to construct p...
2
0
['Binary Search', 'Prefix Sum', 'Go']
1
find-the-student-that-will-replace-the-chalk
simplest solution for the beginners
simplest-solution-for-the-beginners-by-t-z7tx
class Solution {\npublic:\n int chalkReplacer(vector& chalk, long long int k) {\n long long int tot=0;\n \n for(int i=0;i<chalk.size();i++){\n
tanishqvyas01
NORMAL
2022-10-17T10:43:01.862013+00:00
2022-10-17T11:58:08.964418+00:00
352
false
class Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, long long int k) {\n long long int tot=0;\n \n for(int i=0;i<chalk.size();i++){\n tot+=chalk[i];\n }\n long long rem = k % tot;\n\n for(int i=0;i<chalk.size();i++){\n if(rem<chalk[i]) return i;\n rem...
2
0
[]
0
find-the-student-that-will-replace-the-chalk
c++ | 90% faster than all | easy
c-90-faster-than-all-easy-by-venomhighs7-dtuu
\n# Code\n\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n \n size_t sum=0;\n for(auto &x: chalk)\n
venomhighs7
NORMAL
2022-10-16T04:28:31.202385+00:00
2022-10-16T04:28:31.202437+00:00
607
false
\n# Code\n```\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n \n size_t sum=0;\n for(auto &x: chalk)\n sum+=x; \n \n k = k%sum; \n for(int i=0;i<chalk.size();i++) \n { if( k-chalk[i] < 0) return i;\n else\n ...
2
0
['C++']
0
find-the-student-that-will-replace-the-chalk
Simple Java Solution
simple-java-solution-by-nomaanansarii100-2jhq
\nclass Solution {\n public int chalkReplacer(int[] chalk, int k) \n {\n long sum =0;\n \n for(Integer i: chalk)\n sum +=
nomaanansarii100
NORMAL
2022-10-14T10:55:56.902697+00:00
2022-10-14T10:55:56.902732+00:00
727
false
```\nclass Solution {\n public int chalkReplacer(int[] chalk, int k) \n {\n long sum =0;\n \n for(Integer i: chalk)\n sum += i;\n \n long l = k % sum;\n \n for(int i=0; i<chalk.length;i++)\n {\n if(l >= chalk[i])\n l = l ...
2
0
['Java']
1
find-the-student-that-will-replace-the-chalk
C++ || Easy✅ || Binary Search ✅ || Most Optimized Approach 🔥
c-easy-binary-search-most-optimized-appr-jybx
\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n vector<long long> pref(n);\n \n
UjjwalAgrawal
NORMAL
2022-09-16T04:48:08.017238+00:00
2022-09-16T04:48:08.017282+00:00
365
false
```\nclass Solution {\npublic:\n int chalkReplacer(vector<int>& chalk, int k) {\n int n = chalk.size();\n vector<long long> pref(n);\n \n pref[0] = chalk[0];\n for(int i = 1; i<n; i++){\n pref[i] = pref[i-1] + chalk[i];\n }\n \n k = k % pref[n-1];\n ...
2
0
['C', 'Binary Tree', 'Prefix Sum']
0
find-the-student-that-will-replace-the-chalk
easy method and easy explanation
easy-method-and-easy-explanation-by-devi-4ni2
So, In this question we follow some steps.\nsteps\n1.first we store sum of given chalk array in sum long variable.\n2.Now we take modulus of k with this sum to
devil_pratihar
NORMAL
2022-06-19T20:40:41.644880+00:00
2022-06-19T20:40:41.644921+00:00
195
false
So, In this question we follow some steps.\n**steps**\n1.first we store sum of given chalk array in sum long variable.\n2.Now we take modulus of k with this sum to avoid repitation of steps.\n3.At last we run loop and substract value of array one by one from k. and when our condition become true we come out from loop.\...
2
0
['C', 'C++']
0
design-authentication-manager
C++ Time map and Token map
c-time-map-and-token-map-by-votrubac-v179
A naive single-map solution is accepted (and that\'s why this problem is only 4 points). For an interivew, however, it won\'t cut it. If you add 1000 tokens, an
votrubac
NORMAL
2021-03-20T16:03:45.300318+00:00
2021-03-20T17:43:32.511094+00:00
6,142
false
A naive single-map solution is accepted (and that\'s why this problem is only 4 points). For an interivew, however, it won\'t cut it. If you add 1000 tokens, and query 1000 times, the overal complexity will be quadratic. The test cases here are weak, so the difference between two-map and single-map solution is small (6...
41
5
[]
14
design-authentication-manager
[Java/Python 3] Two codes: HashMap/dict and LinkedHashMap/OrderedDict.
javapython-3-two-codes-hashmapdict-and-l-dcbb
Method 1: HashMap\n\nUse tailMap to skip expired tokens.\njava\n private TreeMap<Integer, String> tm = new TreeMap<>();\n private Map<String, Integer> exp
rock
NORMAL
2021-03-20T16:03:36.055348+00:00
2022-03-30T18:03:04.079812+00:00
5,023
false
**Method 1: HashMap**\n\nUse `tailMap` to skip expired tokens.\n```java\n private TreeMap<Integer, String> tm = new TreeMap<>();\n private Map<String, Integer> expireTime = new HashMap<>();\n private int life;\n \n public AuthenticationManager(int timeToLive) {\n life = timeToLive;\n }\n \n ...
30
1
[]
9
design-authentication-manager
✅Short & Easy w/ Explanation | Clean code with Comments
short-easy-w-explanation-clean-code-with-65u6
\nclass AuthenticationManager {\npublic:\n\t// used for mapping tokenId with generation time\n unordered_map<string, int >mp;\n int ttl;\n Authenticati
archit91
NORMAL
2021-03-20T16:26:23.846953+00:00
2021-03-20T16:34:44.366773+00:00
1,793
false
```\nclass AuthenticationManager {\npublic:\n\t// used for mapping tokenId with generation time\n unordered_map<string, int >mp;\n int ttl;\n AuthenticationManager(int timeToLive) : ttl(timeToLive){}\n \t\n void generate(string tokenId, int currentTime) {\n\t\t// store tokenId mapped with time of generat...
16
1
['C']
3
design-authentication-manager
Clean Python with explanation
clean-python-with-explanation-by-it_bili-by7u
\nclass AuthenticationManager(object):\n\n def __init__(self, timeToLive):\n self.token = dict()\n self.time = timeToLive # store timeToLive
it_bilim
NORMAL
2021-03-20T16:07:34.222303+00:00
2021-03-20T17:13:48.025922+00:00
3,178
false
```\nclass AuthenticationManager(object):\n\n def __init__(self, timeToLive):\n self.token = dict()\n self.time = timeToLive # store timeToLive and create dictionary\n\n def generate(self, tokenId, currentTime):\n self.token[tokenId] = currentTime # store tokenId with currentTime\n\n ...
16
4
['Python', 'Python3']
2
design-authentication-manager
[Java] LinkedHashMap
java-linkedhashmap-by-leonfan-d8yz
Clean expired item for each operation. Use LinkedHashMap to keep the order as also can get item in constant time.\n\nclass AuthenticationManager {\n private
leonfan
NORMAL
2021-03-20T17:30:53.750857+00:00
2021-03-20T17:30:53.750889+00:00
1,302
false
Clean expired item for each operation. Use LinkedHashMap to keep the order as also can get item in constant time.\n```\nclass AuthenticationManager {\n private int timeToLive;\n private Map<String, Integer> map = new LinkedHashMap<String, Integer>(); \n\n public AuthenticationManager(int timeToLive) {\n ...
14
1
[]
2
design-authentication-manager
[python3/Java] OrderedDict/LinkedHashMap O(1) with detailed explanation
python3java-ordereddictlinkedhashmap-o1-sfu5m
Suppose we have a dict where the key is tokenId and value is expireTime, how can we know the order of the expireTime such that we can easily remove the outdated
kytabyte
NORMAL
2021-03-20T16:20:29.632007+00:00
2021-03-22T02:36:07.058278+00:00
1,139
false
Suppose we have a dict where the key is `tokenId` and value is `expireTime`, how can we know the order of the `expireTime` such that we can easily remove the outdated entry everytime?\n\nHere is a specific data structure coming to rescue!\n\nPython\'s `OrderedDict` and Java\'s `LinkedHashMap` can preserve the **key ins...
12
0
[]
1
design-authentication-manager
[C++] Clean Code, Single Map Solution Explained
c-clean-code-single-map-solution-explain-xhtf
The problem is pretty straightforward, so the real challenge is just to get things working as efficiently, scalably and cleanly as possible.\n\nI gave it a shot
ajna
NORMAL
2021-03-20T16:55:50.110738+00:00
2021-03-20T16:55:50.110765+00:00
2,065
false
The problem is pretty straightforward, so the real challenge is just to get things working as efficiently, scalably and cleanly as possible.\n\nI gave it a shot by first of all defining to class variables:\n* `ttl` will store the supplied `timeToLive`;\n* `tokens` is a `unordered_map` with the `{tokenId => expiryTime}`...
8
0
['C', 'C++']
1
design-authentication-manager
Python O(1) solution: Doubly Linked List + Dict. Beat 99.7%
python-o1-solution-doubly-linked-list-di-79jz
Intuition\n Describe your first thoughts on how to solve this problem. \n\nBorrow the idea from LRU cache. Maintain a dict and a doubly linked list(dll) to stor
davidyqy
NORMAL
2024-02-23T04:20:53.797264+00:00
2024-02-23T04:20:53.797292+00:00
927
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nBorrow the idea from LRU cache. Maintain a dict and a doubly linked list(dll) to store the existing tokens.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n- generate: add the node to the dict and to the dll.\n...
7
0
['Hash Table', 'Doubly-Linked List', 'Python3']
0
design-authentication-manager
Clean Python 3, hashmap
clean-python-3-hashmap-by-lenchen1112-vo51
Time: O(max unexpired) for countUnexpiredTokens, O(1) for others\nSpace: O(max unexpired)\n\nclass AuthenticationManager:\n def __init__(self, timeToLive: in
lenchen1112
NORMAL
2021-03-20T16:21:06.723896+00:00
2021-03-20T16:21:06.723921+00:00
561
false
Time: `O(max unexpired)` for `countUnexpiredTokens`, `O(1)` for others\nSpace: `O(max unexpired)`\n```\nclass AuthenticationManager:\n def __init__(self, timeToLive: int):\n self.time = timeToLive\n self.unexpired = {}\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n self.une...
6
0
[]
0
design-authentication-manager
C++ solution || Hash Map|| Fully commented✅
c-solution-hash-map-fully-commented-by-n-ux5q
\n# Code\n\nclass AuthenticationManager {\npublic:\n unordered_map<string, int>mp;\n int time= 0;\n AuthenticationManager(int timeToLive) {\n ti
NitinSingh77
NORMAL
2023-09-02T18:28:24.176151+00:00
2023-09-02T18:28:48.899244+00:00
3,616
false
\n# Code\n```\nclass AuthenticationManager {\npublic:\n unordered_map<string, int>mp;\n int time= 0;\n AuthenticationManager(int timeToLive) {\n time= timeToLive;\n }\n \n void generate(string tokenId, int currentTime) {\n mp[tokenId]= currentTime + time;// This will give you our expiry ...
5
0
['Hash Table', 'C++']
0
design-authentication-manager
Python | Beats 99% | Amortized cost explained
python-beats-99-amortized-cost-explained-9l15
Method 1: Using HashMap\n\n\n# Code\n\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.ex
saurabhkoshatwar
NORMAL
2024-04-23T18:00:02.567208+00:00
2024-04-23T18:00:02.567239+00:00
629
false
# Method 1: Using HashMap\n\n\n# Code\n```\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.expiry = {}\n\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n self.expiry[tokenId] = currentTime + self.ttl\n\n def renew(self...
4
0
['Python', 'Python3']
2
design-authentication-manager
Java Solution with Map and PQ , >90%
java-solution-with-map-and-pq-90-by-stil-kzo9
Intuition\nIteration over map take time to elimate the expired keys\n\n# Approach\nUsed Map and PQ together to improve the performance\n\n# Complexity\n- Time c
StillCoder
NORMAL
2024-03-06T12:30:37.369110+00:00
2024-03-10T10:51:48.784533+00:00
804
false
# Intuition\nIteration over map take time to elimate the expired keys\n\n# Approach\nUsed Map and PQ together to improve the performance\n\n# Complexity\n- Time complexity:\nO(nLogn)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass AuthenticationManager {\n int timeToLive;\n class Pair{\n String tokenId;...
4
0
['Java']
1
design-authentication-manager
Python3: Dictionary + Deque = beat 98% runtime
python3-dictionary-deque-beat-98-runtime-7jzn
Intuition\n The problem has an inherent FIFO nature - tokens are added with strictly increasing timestamps, and the tokens which are added first will also expir
conquerworld
NORMAL
2023-08-23T10:46:18.005130+00:00
2023-08-23T10:46:18.005159+00:00
1,104
false
# Intuition\n* The problem has an inherent FIFO nature - tokens are added with strictly increasing timestamps, and the tokens which are added first will also expire first since TTL is the same for all tokens. This should inspire using a queue. \n* I used a hashmap with the queue just to keep track of the tokenids, but ...
4
0
['Python3']
3
design-authentication-manager
Java Using HashMap
java-using-hashmap-by-tbekpro-tqdk
Code\n\nclass AuthenticationManager {\n\n HashMap<String, Integer> map;\n int time;\n public AuthenticationManager(int timeToLive) {\n map = new
tbekpro
NORMAL
2023-06-24T15:54:33.450601+00:00
2023-06-24T15:54:33.450625+00:00
1,216
false
# Code\n```\nclass AuthenticationManager {\n\n HashMap<String, Integer> map;\n int time;\n public AuthenticationManager(int timeToLive) {\n map = new HashMap<>();\n time = timeToLive;\n }\n\n public void generate(String tokenId, int currentTime) {\n map.put(tokenId, currentTime + tim...
4
0
['Java']
0
design-authentication-manager
🔥🔥Easiest Java Solution For Beginners🔥🔥
easiest-java-solution-for-beginners-by-j-x52o
\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n\nclass AuthenticationManager {\n\n int time=0;\n\n HashMap<String,Inte
jaiyadav
NORMAL
2023-01-11T15:08:05.192631+00:00
2023-01-11T15:08:05.192671+00:00
1,395
false
\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass AuthenticationManager {\n\n int time=0;\n\n HashMap<String,Integer>mp=new HashMap<>();\n\n public AuthenticationManager(int timeToLive) {\n \n time=timeToLive;\n\n }\n \n public void generate(String...
4
0
['Hash Table', 'Design', 'Java']
2
design-authentication-manager
In JavaScript using Hashmap
in-javascript-using-hashmap-by-vishwanat-4kgc
\n/**\n * @param {number} timeToLive\n */\nvar AuthenticationManager = function(timeToLive) {\n this.timeToLive=timeToLive;\n this.tokens=new Map();\n};\n
vishwanath1
NORMAL
2022-03-31T06:25:29.051996+00:00
2022-03-31T06:25:29.052043+00:00
259
false
```\n/**\n * @param {number} timeToLive\n */\nvar AuthenticationManager = function(timeToLive) {\n this.timeToLive=timeToLive;\n this.tokens=new Map();\n};\n\n/** \n * @param {string} tokenId \n * @param {number} currentTime\n * @return {void}\n */\nAuthenticationManager.prototype.generate = function(tokenId, cur...
4
0
['JavaScript']
1
design-authentication-manager
[C++] unordered_map + queue (faster than 100%)
c-unordered_map-queue-faster-than-100-by-fasg
\nclass AuthenticationManager {\n queue<pair<string, int>> q;\n unordered_map<string,int> mp;\n int ttl;\n \n\t//remove all the expired tokens in qu
vivekaltruist
NORMAL
2021-03-20T16:37:59.772076+00:00
2021-03-20T16:43:39.371843+00:00
406
false
```\nclass AuthenticationManager {\n queue<pair<string, int>> q;\n unordered_map<string,int> mp;\n int ttl;\n \n\t//remove all the expired tokens in queue\n void removeExpired(int t){\n while(!q.empty() && q.front().second <= t){\n string id = q.front().first;\n if(mp[id] == ...
4
0
[]
0
design-authentication-manager
Beats 92% || C++|| Priority Queue || Map
beats-92-c-priority-queue-map-by-sai_sre-9q5r
Intuition\nThe goal of this problem is to design a class that manages authentication tokens with a certain time-to-live (TTL) value and provides functions for g
sai_sreekar_
NORMAL
2023-09-13T09:05:44.521124+00:00
2023-09-13T09:09:05.979434+00:00
655
false
# **Intuition**\nThe goal of this problem is to design a class that manages authentication tokens with a certain time-to-live (TTL) value and provides functions for generating, renewing, and counting unexpired tokens based on the current time.\n\n# **Approach**\nTo solve this problem, we can use an unordered map (`ump`...
3
0
['Hash Table', 'Design', 'Ordered Map', 'Heap (Priority Queue)', 'C++']
1
design-authentication-manager
C++ Solution
c-solution-by-pranto1209-bt7x
Approach\n Describe your approach to solving the problem. \n Map\n\n\n# Code\n\nclass AuthenticationManager {\npublic:\n int timeToLive;\n unordered_ma
pranto1209
NORMAL
2023-07-30T09:40:34.508839+00:00
2023-07-30T09:40:34.508857+00:00
2,234
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n Map\n\n\n# Code\n```\nclass AuthenticationManager {\npublic:\n int timeToLive;\n unordered_map<string, int> mp;\n \n AuthenticationManager(int timeToLive) {\n this->timeToLive = timeToLive;\n }\n \n void generate(string...
3
0
['C++']
0
design-authentication-manager
[Python3] Brute Force Hash Map
python3-brute-force-hash-map-by-blackspi-znul
\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.record = {}\n\n def generate(self, to
blackspinner
NORMAL
2021-03-22T02:05:20.153773+00:00
2023-09-30T21:51:50.642879+00:00
209
false
```\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.record = {}\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n self.record[tokenId] = currentTime\n\n def renew(self, tokenId: str, currentTime: int) -> None:\n i...
3
0
['Python3']
0
design-authentication-manager
✅ Javascript | Simplest Solution | 🏆Hash Table🏆 |🔥Beats 100%🔥
javascript-simplest-solution-hash-table-qxp4q
\n\n# Intuition\nSimple storing tokens in Hash Table, then manipulate as update and iterate through.\n\n# Approach\nDefine timeToLive as this.ttl and Map() for
Satansoft
NORMAL
2024-05-23T19:13:23.082795+00:00
2024-05-23T19:13:23.082830+00:00
29
false
![image.png](https://assets.leetcode.com/users/images/b2f8481e-ea90-4c9b-954e-19243dc184c3_1716490698.3374872.png)\n\n# Intuition\nSimple storing tokens in `Hash Table`, then manipulate as update and iterate through.\n\n# Approach\nDefine `timeToLive` as `this.ttl` and `Map()` for storing and manipulating with tokens d...
2
0
['Hash Table', 'JavaScript']
0
design-authentication-manager
Python3 - dict + heapq - beats 87%
python3-dict-heapq-beats-87-by-sebmulti2-m3yj
Intuition\nFor naive one, go through the hashmap and count the ones which have expired. This passes the test cases but its slow since you need to count all the
SebMulti21
NORMAL
2024-03-31T07:37:52.954183+00:00
2024-03-31T07:37:52.954218+00:00
163
false
# Intuition\nFor naive one, go through the hashmap and count the ones which have expired. This passes the test cases but its slow since you need to count all the keys. \n\nWhat if we delete the expired ones from hashmap as we update the tokens map? \n\n# Approach\nMaintain a hashmap for O(1) lookup of tokens and a sepa...
2
0
['Heap (Priority Queue)', 'Python3']
0
design-authentication-manager
[Java] HashMap + TreeSet
java-hashmap-treeset-by-hristokov-sznq
The algorithm is pretty straightforward, the idea is to add and renew the keys with the added time to live, so we can keep the expiration value and to use a Tre
HristoKov
NORMAL
2022-09-29T13:34:08.792248+00:00
2022-09-29T13:34:08.792286+00:00
684
false
The algorithm is pretty straightforward, the idea is to add and renew the keys with the added time to live, so we can keep the expiration value and to use a TreeSet for keeping it in a sorted manner with time complexity of O(Log (n)) for add and remove and O (M Log (n)) (where M is the number of items which will be tra...
2
0
['Tree', 'Ordered Set', 'Java']
1
design-authentication-manager
[C++] | Easiest Solution | Clean Code | Single Map
c-easiest-solution-clean-code-single-map-ngk9
Pls upvote if you like the solution!\n\nclass AuthenticationManager {\npublic:\n int time;\n unordered_map <string,int> m;\n AuthenticationManager(int
_dhruvbhatia_
NORMAL
2022-05-02T08:11:31.271445+00:00
2022-05-02T08:11:31.271475+00:00
341
false
Pls upvote if you like the solution!\n```\nclass AuthenticationManager {\npublic:\n int time;\n unordered_map <string,int> m;\n AuthenticationManager(int timeToLive) {\n time = timeToLive;\n }\n \n void generate(string tokenId, int currentTime) {\n m[tokenId] = currentTime;\n }\n \...
2
0
['C']
0
design-authentication-manager
Python | Doubly LinkedList | All O(1) TC
python-doubly-linkedlist-all-o1-tc-by-ni-zfnd
\nclass Node:\n def __init__(self, key, exp):\n self.key = key\n self.exp = exp\n self.prev = None\n self.next = None\n \nclas
nishan_4
NORMAL
2022-03-24T18:45:23.872623+00:00
2022-04-01T08:40:11.542745+00:00
396
false
```\nclass Node:\n def __init__(self, key, exp):\n self.key = key\n self.exp = exp\n self.prev = None\n self.next = None\n \nclass AuthenticationManager:\n\n \'\'\'\n create Dobuly linked list\n unexpired tokens are on right \n expired will be on left , which is removed be...
2
0
['Linked List', 'Doubly-Linked List', 'Python']
2
design-authentication-manager
Design Authentication Manager Solution Java
design-authentication-manager-solution-j-gpjc
class AuthenticationManager {\n int timeToLive;\n Map map;\n\n public AuthenticationManager(int timeToLive) {\n this.timeToLive = timeToLive;\n
bhupendra786
NORMAL
2022-03-21T10:26:48.749782+00:00
2022-03-21T10:26:48.749809+00:00
39
false
class AuthenticationManager {\n int timeToLive;\n Map<String, Integer> map;\n\n public AuthenticationManager(int timeToLive) {\n this.timeToLive = timeToLive;\n map = new HashMap<String, Integer>();\n }\n \n public void generate(String tokenId, int currentTime) {\n map.put(tokenId...
2
1
['Design']
0
design-authentication-manager
Easy C++ solution
easy-c-solution-by-imran2018wahid-1m1y
\nclass AuthenticationManager {\npublic:\n int timeToLive;\n unordered_map<string,int>m;\n AuthenticationManager(int timeToLive) {\n this->timeT
imran2018wahid
NORMAL
2022-03-21T06:02:55.198094+00:00
2022-03-21T06:02:55.198142+00:00
267
false
```\nclass AuthenticationManager {\npublic:\n int timeToLive;\n unordered_map<string,int>m;\n AuthenticationManager(int timeToLive) {\n this->timeToLive=timeToLive;\n m.clear();\n }\n \n void generate(string tokenId, int currentTime) {\n m[tokenId]=currentTime;\n }\n \n v...
2
0
['C']
0
design-authentication-manager
[Python3] Dictionary - easy understanding
python3-dictionary-easy-understanding-by-01dt
Time: O(max unexpired) for countUnexpiredTokens, O(1) for others\nSpace: O(max unexpired)\n\n\nclass AuthenticationManager:\n\n def __init__(self, timeToLive
dolong2110
NORMAL
2022-01-25T17:26:08.135679+00:00
2024-01-29T08:50:05.330987+00:00
199
false
Time: O(max unexpired) for countUnexpiredTokens, O(1) for others\nSpace: O(max unexpired)\n\n```\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.exp_at = dict()\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n self.exp_at[...
2
0
['Python', 'Python3']
1
design-authentication-manager
Brute Force | C++
brute-force-c-by-smartchuza-xyax
\nclass AuthenticationManager {\npublic:\n map<string,int>M;\n multiset<int>S;\n int T;\n \n AuthenticationManager(int timeToLive) {\n T=t
smartchuza
NORMAL
2021-04-20T19:47:37.359596+00:00
2021-04-20T19:47:37.359639+00:00
122
false
```\nclass AuthenticationManager {\npublic:\n map<string,int>M;\n multiset<int>S;\n int T;\n \n AuthenticationManager(int timeToLive) {\n T=timeToLive; \n }\n \n void generate(string tokenId, int currentTime) {\n M[tokenId]=currentTime+T;\n S.insert(M[tokenId]);\n ...
2
0
[]
0
design-authentication-manager
Python Faster than 100% Dictionary + Binary search
python-faster-than-100-dictionary-binary-vyai
\n\n\n\nfrom collections import defaultdict\nfrom typing import Dict, List, Tuple\n\n\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\
sumeetsarkar
NORMAL
2021-03-21T17:04:11.798416+00:00
2021-03-21T17:05:56.549911+00:00
376
false
![image](https://assets.leetcode.com/users/images/1a1951ec-ff01-41bf-bea4-80f56bb13d42_1616346345.508527.png)\n\n\n```\nfrom collections import defaultdict\nfrom typing import Dict, List, Tuple\n\n\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self._ttl = timeToLive\n\t\t# dictionar...
2
0
['Binary Search', 'Python', 'Python3']
1
design-authentication-manager
Easy JAVA Solution Using HashMap
easy-java-solution-using-hashmap-by-hima-hkmy
\nclass AuthenticationManager {\n HashMap<String,Integer> tokens;\n int life;\n \n public AuthenticationManager(int timeToLive) {\n tokens=n
himanshuchhikara
NORMAL
2021-03-20T16:53:46.950093+00:00
2021-03-20T18:04:10.371904+00:00
99
false
```\nclass AuthenticationManager {\n HashMap<String,Integer> tokens;\n int life;\n \n public AuthenticationManager(int timeToLive) {\n tokens=new HashMap<>();\n life=timeToLive;\n \n }\n \n public void generate(String tokenId, int currentTime) {\n tokens.put(tokenId,curr...
2
2
['Java']
0
design-authentication-manager
interval with expiration time c++
interval-with-expiration-time-c-by-sguox-esxe
using hashmap to record the expiration time and ordered map to record the start and expiration time and then use prefix sum to get the count\n\n unordered_ma
sguox002
NORMAL
2021-03-20T16:12:36.174084+00:00
2021-03-20T16:12:36.174122+00:00
98
false
using hashmap to record the expiration time and ordered map to record the start and expiration time and then use prefix sum to get the count\n```\n unordered_map<string,int> token;\n map<int,int> mp;\n int tl;\n AuthenticationManager(int timeToLive) {\n tl=timeToLive;\n }\n \n void generate(...
2
0
[]
0
design-authentication-manager
Python: Two solutions Explained Using (Doubly LinkedList + HashMap) or (Heapq + HashMap)
python-2-solutions-explained-using-doubl-7leb
Approach 1Doubly LinkedList + DictionaryComplexity Time complexity: Generate and Renew O(1), CountExpiry O(n) Space complexity: O(n) CodeApproach 2Heapq + Dict
kushalpatel
NORMAL
2025-04-02T03:38:04.305084+00:00
2025-04-02T03:38:30.244692+00:00
63
false
# Approach 1 Doubly LinkedList + Dictionary # Complexity - Time complexity: Generate and Renew O(1), CountExpiry 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 ```python3 [] class ListNode(): def __init__(self, to...
1
0
['Hash Table', 'Heap (Priority Queue)', 'Doubly-Linked List', 'Python3']
0
design-authentication-manager
[C++] list + unordered_map clean solution
c-list-unordered_map-clean-solution-by-a-3wi4
Code
axard
NORMAL
2024-12-30T22:18:27.287643+00:00
2024-12-30T22:19:52.705423+00:00
76
false
# Code ```cpp [] class AuthenticationManager { public: int ttl = 0; list<string> l; unordered_map<string, pair<list<string>::iterator, int>> mp; AuthenticationManager(int timeToLive) { ttl = timeToLive; } void generate(string tokenId, int currentTime) { l.push_front(tokenI...
1
0
['C++']
0
design-authentication-manager
amortized O(1) ^^
amortized-o1-by-andrii_khlevniuk-gdxp
time: amortized O(1)\n\nclass AuthenticationManager \n{\n int t;\n int uniques{};\n unordered_map<string, int> st;\n queue<pair<string, int>> q;\n
andrii_khlevniuk
NORMAL
2024-08-06T00:22:02.528930+00:00
2024-08-06T17:06:05.899753+00:00
55
false
**time: `amortized O(1)`**\n```\nclass AuthenticationManager \n{\n int t;\n int uniques{};\n unordered_map<string, int> st;\n queue<pair<string, int>> q;\n \npublic:\n AuthenticationManager(int t) : t{t} \n { \n }\n \n void generate(string s, int ct) \n {\n st[s] = ct+t-1;\n ...
1
0
['C', 'C++']
0
design-authentication-manager
Java solution using hashmap + queue beats 96%
java-solution-using-hashmap-queue-beats-skvwz
Intuition\nIn order to manage tokens effectively, we need two datastructures - a map to store token -> expiry time data and a queue to easily get the unexpired
problemsolver1111
NORMAL
2024-04-03T20:07:04.674928+00:00
2024-04-03T20:07:04.674953+00:00
76
false
# Intuition\nIn order to manage tokens effectively, we need two datastructures - a map to store token -> expiry time data and a queue to easily get the unexpired token size information.\n\n# Approach\n\nFor generate and renew, simply update the map with token -> new expiry time information. When you generate a new toke...
1
0
['Java']
0
design-authentication-manager
C++ Solution using 2 maps
c-solution-using-2-maps-by-mrcawfee-9izm
\n# Approach\n\nUsing 2 hash maps, one is the index of token_id => timestamp and another is a multimap for timestamp => iterator in the first map. There are 2 m
mrcawfee
NORMAL
2024-02-20T19:13:49.881246+00:00
2024-02-20T19:13:49.881280+00:00
13
false
\n# Approach\n\nUsing 2 hash maps, one is the index of token_id => timestamp and another is a multimap for timestamp => iterator in the first map. There are 2 maps so that countUnexpiredTokens() doesn\'t need to do a full scan of all nodes in the first map, only an indexed version of times.\n\n# Complexity\n- Time comp...
1
0
['C++']
0
design-authentication-manager
Simple Java solution with Streams
simple-java-solution-with-streams-by-mrk-uhvl
Intuition\n\nWe could store tokens in Map using token as a key and expiration time as a value.\n\n# Approach\n\nIn this approach we store state in HashMap durin
mrk-andreev
NORMAL
2024-02-10T20:53:58.449920+00:00
2024-02-10T20:53:58.449953+00:00
221
false
# Intuition\n\nWe could store tokens in Map using token as a key and expiration time as a value.\n\n# Approach\n\nIn this approach we store state in HashMap during all tests. This solution contains a memory leak because we don\'t clean expired tokens. Good solution will have a separate handler for removement of expired...
1
0
['Java']
0
design-authentication-manager
Python solution using OrderedDict (LinkedHashMap) - new data structure learning
python-solution-using-ordereddict-linked-56z3
Complexity\n- Time complexity:\nAverage: O(1) for each query\n\n\n# Code\n\nfrom collections import OrderedDict\n\nclass AuthenticationManager:\n\n def __ini
akki06
NORMAL
2024-02-10T12:52:35.941265+00:00
2024-02-10T12:52:35.941287+00:00
270
false
# Complexity\n- Time complexity:\nAverage: O(1) for each query\n\n\n# Code\n```\nfrom collections import OrderedDict\n\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n self.orderedTokens = OrderedDict()\n\n def generate(self, tokenId: str, curre...
1
0
['Python3']
0
design-authentication-manager
C++ USING SINGLE MAP
c-using-single-map-by-arpiii_7474-kafr
Code\n\nclass AuthenticationManager {\n int ttl;\n unordered_map<string,int> mp;\npublic:\n AuthenticationManager(int timeToLive) {\n ttl=timeTo
arpiii_7474
NORMAL
2023-09-30T19:44:44.017992+00:00
2023-09-30T19:44:44.018008+00:00
52
false
# Code\n```\nclass AuthenticationManager {\n int ttl;\n unordered_map<string,int> mp;\npublic:\n AuthenticationManager(int timeToLive) {\n ttl=timeToLive;\n } \n void generate(string tokenId, int currentTime) {\n mp[tokenId]=currentTime+ttl;\n } \n void renew(string tokenId, int cu...
1
0
['C++']
0
design-authentication-manager
Heap solution (beats 99%) - O(1) generate, O(1) renew , O(nlogn) count
heap-solution-beats-99-o1-generate-o1-re-in25
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst thoughts:\n- Can generate and renew using hashmaps\n- I have to calculate the num
A-V-Jagannathan
NORMAL
2023-09-01T19:19:44.306527+00:00
2023-09-01T19:19:44.306555+00:00
611
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst thoughts:\n- Can generate and renew using hashmaps\n- I have to calculate the number of expired tokens for count\n- Brute way is to check and remove each token, is there any faster approach?\n\n# Approach\n<!-- Describe your approac...
1
0
['Python', 'C++', 'Java', 'Python3']
1
design-authentication-manager
[Java] Easy 100% solution using HashMap and TreeMap
java-easy-100-solution-using-hashmap-and-7pyn
java\nimport java.util.*;\n\nclass AuthenticationManager {\n private final TreeMap<Integer, String> timestamps;\n private final Map<String, Integer> token
YTchouar
NORMAL
2023-05-25T03:16:31.439873+00:00
2023-05-25T03:16:31.439913+00:00
1,553
false
```java\nimport java.util.*;\n\nclass AuthenticationManager {\n private final TreeMap<Integer, String> timestamps;\n private final Map<String, Integer> tokens;\n private final int timeToLive;\n\n public AuthenticationManager(final int timeToLive) {\n this.timestamps = new TreeMap<>();\n this.t...
1
0
['Java']
1
design-authentication-manager
Python3 queue with explanation amortized time O(1) beats 99%
python3-queue-with-explanation-amortized-jhui
Intuition\nFailed this question at a job interview, so glad I found it at leetcode. The trick to optimal solution is to consider amortized time for countUnexpir
sleepingonee
NORMAL
2023-03-11T12:02:45.195971+00:00
2023-03-11T12:04:21.472555+00:00
104
false
# Intuition\nFailed this question at a job interview, so glad I found it at leetcode. The trick to optimal solution is to consider amortized time for countUnexpiredTokens method. \n\nUse two data structures:\n- live_tokens hashmap for storing count of live tokens (each successful call to method renew will increase coun...
1
0
['Hash Table', 'Queue', 'Python3']
0
design-authentication-manager
c# Accepted : Easy to understand
c-accepted-easy-to-understand-by-rhazem1-att0
\npublic class AuthenticationManager {\n public int ttl;\n Dictionary<string,int> tokens;\n public AuthenticationManager(int timeToLive) {\n thi
rhazem13
NORMAL
2023-03-10T10:04:44.881772+00:00
2023-03-10T10:04:44.881810+00:00
751
false
```\npublic class AuthenticationManager {\n public int ttl;\n Dictionary<string,int> tokens;\n public AuthenticationManager(int timeToLive) {\n this.ttl = timeToLive;\n tokens=new();\n }\n \n public void Generate(string tokenId, int currentTime) {\n tokens.Add(tokenId,currentTime)...
1
0
[]
0
design-authentication-manager
Java solution using LinkedHashMap beats 100% with detailed description
java-solution-using-linkedhashmap-beats-yeyvo
Intuition\nWe need to maintain the sessions of different token ids and need a data structure which helps in reduce time by sorting the sessions by their expiry
ayushprakash1912
NORMAL
2023-01-12T19:02:02.771674+00:00
2023-01-12T19:02:02.771721+00:00
84
false
# Intuition\nWe need to maintain the sessions of different token ids and need a data structure which helps in reduce time by sorting the sessions by their expiry time. \n\n# Approach\nI have used a linked HashMap. TreeMap may also be used. \nBenefit of using a linked HashMap is that it iterated through the key set in ...
1
0
['Ordered Map', 'Java']
0
design-authentication-manager
JS Simple Solution
js-simple-solution-by-edwardfalcon-5hkg
\n/**\n * @param {number} timeToLive\n */\nvar AuthenticationManager = function (timeToLive) {\n this.timeToLive = timeToLive;\n this.currentTime = 0;\n this
edwardfalcon
NORMAL
2022-11-09T17:38:13.779151+00:00
2022-11-09T17:38:13.779192+00:00
187
false
```\n/**\n * @param {number} timeToLive\n */\nvar AuthenticationManager = function (timeToLive) {\n this.timeToLive = timeToLive;\n this.currentTime = 0;\n this.tokens = {};\n};\n\n/**\n * @param {string} tokenId\n * @param {number} currentTime\n * @return {void}\n */\nAuthenticationManager.prototype.generate = func...
1
0
['Hash Table', 'JavaScript']
0
design-authentication-manager
C++ Single Map Solution
c-single-map-solution-by-rahul_v_2001-nnt0
This Solution is Also works very fine.\n\nclass AuthenticationManager {\npublic:\n int n;\n AuthenticationManager(int timeToLive) {\n n = timeToLiv
rahul_v_2001
NORMAL
2022-09-10T17:28:34.632214+00:00
2022-09-10T17:28:34.632252+00:00
760
false
This Solution is Also works very fine.\n```\nclass AuthenticationManager {\npublic:\n int n;\n AuthenticationManager(int timeToLive) {\n n = timeToLive;\n }\n unordered_map<string, int> mp;\n void generate(string tokenId, int currentTime) {\n if(mp.find(tokenId) == mp.end()){\n m...
1
0
[]
1
design-authentication-manager
C++ easy solution using stl
c-easy-solution-using-stl-by-mananagrawa-zjdl
\nclass AuthenticationManager {\n int timeToLive;\n unordered_map<string, int> tokens;\npublic:\n AuthenticationManager(int timeToLive) {\n this
mananagrawal26
NORMAL
2022-07-16T12:36:53.580432+00:00
2022-07-16T12:36:53.580462+00:00
609
false
```\nclass AuthenticationManager {\n int timeToLive;\n unordered_map<string, int> tokens;\npublic:\n AuthenticationManager(int timeToLive) {\n this->timeToLive = timeToLive;\n }\n \n void generate(string tokenId, int currentTime) {\n tokens[tokenId] = currentTime;\n }\n \n void ...
1
0
['C', 'C++']
0
design-authentication-manager
[Rust] Token HashMap
rust-token-hashmap-by-kurosuha-imzs
rust\nuse std::{\n cell::RefCell,\n cmp::Ordering,\n collections::hash_map::Entry::Occupied,\n collections::{hash_map::Entry::Vacant, BTreeSet},\n
kurosuha
NORMAL
2022-06-28T06:26:43.637932+00:00
2022-06-28T06:26:43.637982+00:00
97
false
```rust\nuse std::{\n cell::RefCell,\n cmp::Ordering,\n collections::hash_map::Entry::Occupied,\n collections::{hash_map::Entry::Vacant, BTreeSet},\n collections::{BTreeMap, BinaryHeap, HashMap, HashSet, VecDeque},\n rc::Rc,\n};\n\n\n\nstruct AuthenticationManager {\n time_to_live: i32,\n tokens...
1
0
[]
1
design-authentication-manager
C++ (simple hash map design)
c-simple-hash-map-design-by-dakre-545n
\nclass AuthenticationManager {\n int ttl_;\n unordered_map<string, int> s_;\npublic:\n AuthenticationManager(int ttl): ttl_(ttl) {\n \n }\n
dakre
NORMAL
2022-06-23T00:31:52.743543+00:00
2022-06-23T00:32:06.884882+00:00
121
false
```\nclass AuthenticationManager {\n int ttl_;\n unordered_map<string, int> s_;\npublic:\n AuthenticationManager(int ttl): ttl_(ttl) {\n \n }\n \n void generate(string tid, int ct) {\n s_[tid] = ct;\n }\n \n void renew(string tid, int ct) {\n if (s_.find(tid) == s_.end())...
1
0
['C']
0
design-authentication-manager
Simple and readable Java solution (HashMap)
simple-and-readable-java-solution-hashma-yhs2
\nclass AuthenticationManager {\n private int ttl;\n private Map<String, Integer> map;\n\n public AuthenticationManager(int timeToLive) {\n this
RuslanVdovychenko
NORMAL
2022-06-18T15:30:58.197493+00:00
2022-06-18T15:30:58.197523+00:00
371
false
```\nclass AuthenticationManager {\n private int ttl;\n private Map<String, Integer> map;\n\n public AuthenticationManager(int timeToLive) {\n this.ttl = timeToLive;\n this.map = new HashMap<>();\n }\n \n public void generate(String tokenId, int currentTime) {\n map.put(tokenId, c...
1
0
['Java']
0
design-authentication-manager
Go language using FibonacciHeap
go-language-using-fibonacciheap-by-andri-wi00
\n// Heap Node.\ntype Node struct {\n\t// \u0421\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0435 \u0443\u0437\u043B\u0430.\n\tx string\n\t// \u041A\u043B\
andribas404
NORMAL
2022-03-31T08:31:18.071773+00:00
2022-03-31T08:31:18.071801+00:00
119
false
```\n// Heap Node.\ntype Node struct {\n\t// \u0421\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0435 \u0443\u0437\u043B\u0430.\n\tx string\n\t// \u041A\u043B\u044E\u0447\n\tkey int\n\t// \u041F\u0440\u0435\u0434\u043E\u043A \u0443\u0437\u043B\u0430\n\tparent *Node\n\t// \u041B\u0435\u0432\u044B\u0439 \u0431\u0440\...
1
0
['Go']
1
design-authentication-manager
✅ [Solution] Swift: Design Authentication Manager
solution-swift-design-authentication-man-ab95
swift\nclass AuthenticationManager {\n \n private struct Token {\n let id: String\n let time: Int\n }\n \n private let timeToLive:I
AsahiOcean
NORMAL
2022-03-31T05:41:01.149347+00:00
2022-03-31T05:41:01.149378+00:00
1,126
false
```swift\nclass AuthenticationManager {\n \n private struct Token {\n let id: String\n let time: Int\n }\n \n private let timeToLive:Int\n private var tokens: [Token] = []\n private var unexpTokens: [String:Int] = [:]\n \n init(_ timeToLive: Int) {\n self.timeToLive = tim...
1
0
['Swift']
0
design-authentication-manager
Java TimeMap and AuthMap using TreeMap
java-timemap-and-authmap-using-treemap-b-dxa6
\nclass AuthenticationManager {\n int ttl;\n TreeMap<String,Integer>authMap;\n TreeMap<Integer,String>timeMap;\n public AuthenticationManager(int ti
vikas_belida_09
NORMAL
2022-03-30T03:26:07.581865+00:00
2022-03-30T03:26:07.581906+00:00
116
false
```\nclass AuthenticationManager {\n int ttl;\n TreeMap<String,Integer>authMap;\n TreeMap<Integer,String>timeMap;\n public AuthenticationManager(int timeToLive) {\n ttl=timeToLive;\n authMap=new TreeMap<>();\n timeMap=new TreeMap<>();\n }\n \n public void generate(String tokenI...
1
0
['Java']
1
design-authentication-manager
Java Clean Code
java-clean-code-by-fllght-kc96
```\nprivate final int timeToLive;\n private final Map tokens;\n\n public AuthenticationManager(int timeToLive) {\n this.timeToLive = timeToLive;\n
FLlGHT
NORMAL
2022-03-19T11:22:44.271583+00:00
2022-03-19T11:22:44.271630+00:00
73
false
```\nprivate final int timeToLive;\n private final Map<String, Integer> tokens;\n\n public AuthenticationManager(int timeToLive) {\n this.timeToLive = timeToLive;\n this.tokens = new HashMap<>();\n }\n\n public void generate(String tokenId, int currentTime) {\n tokens.put(tokenId, curre...
1
0
['Java']
0
design-authentication-manager
Python | SortedList
python-sortedlist-by-lyili-8wsk
\nfrom sortedcontainers import SortedList\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n
lyili
NORMAL
2022-01-24T04:59:56.071618+00:00
2022-01-24T04:59:56.071666+00:00
117
false
```\nfrom sortedcontainers import SortedList\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n self.tokenExpireTime = defaultdict(int)\n self.sortedExpireTime = SortedList()\n \n\n def generate(self, tokenId: str, currentTime: int) ...
1
0
[]
0
design-authentication-manager
Java Solution
java-solution-by-jxie418-zy2o
\nclass AuthenticationManager {\n private int timeToLive = 0;\n private Map<String, Integer> map = new HashMap<>();\n\n public AuthenticationManager(in
jxie418
NORMAL
2021-08-07T17:43:42.515523+00:00
2021-08-07T17:43:42.515551+00:00
143
false
```\nclass AuthenticationManager {\n private int timeToLive = 0;\n private Map<String, Integer> map = new HashMap<>();\n\n public AuthenticationManager(int timeToLive) {\n this.timeToLive = timeToLive;\n }\n \n public void generate(String tokenId, int currentTime) {\n map.put(tokenId, cu...
1
0
[]
1
design-authentication-manager
C++ single map solution
c-single-map-solution-by-aparna_g-vvbi
\nclass AuthenticationManager {\npublic:\n int lifetime;\n unordered_map<string , int> id_time; \n //id , time it expires \n AuthenticationManager(i
aparna_g
NORMAL
2021-07-10T19:36:36.054878+00:00
2021-07-10T19:36:36.054922+00:00
136
false
```\nclass AuthenticationManager {\npublic:\n int lifetime;\n unordered_map<string , int> id_time; \n //id , time it expires \n AuthenticationManager(int timeToLive) {\n lifetime = timeToLive;\n }\n \n void generate(string tokenId, int curr) {\n id_time[tokenId] = curr + lifetime;\n ...
1
0
['C', 'C++']
0
design-authentication-manager
My Java Solution using HashMap Straight forward approach
my-java-solution-using-hashmap-straight-dh2fg
\nclass AuthenticationManager {\n\n private Map<String, Integer> map;\n private int timeToLive;\n public AuthenticationManager(int timeToLive) {\n
vrohith
NORMAL
2021-03-31T07:33:33.831336+00:00
2021-03-31T07:33:33.831365+00:00
148
false
```\nclass AuthenticationManager {\n\n private Map<String, Integer> map;\n private int timeToLive;\n public AuthenticationManager(int timeToLive) {\n map = new HashMap<>(); \n this.timeToLive = timeToLive;\n }\n \n public void generate(String tokenId, int currentTime) {\n map.p...
1
0
['Design', 'Java']
0
design-authentication-manager
Python using LinkedHashmap
python-using-linkedhashmap-by-msk200-733g
\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.cache = OrderedDict() #linkedHashmap usi
msk200
NORMAL
2021-03-25T18:28:55.471848+00:00
2021-03-25T18:28:55.471880+00:00
157
false
```\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.ttl = timeToLive\n self.cache = OrderedDict() #linkedHashmap using in LRU cache\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n self.cache[tokenId] = currentTime + self.ttl\n \n def r...
1
0
[]
0
design-authentication-manager
Java Simple code using HashMap
java-simple-code-using-hashmap-by-champd-uho8
\nclass AuthenticationManager {\n int time;\n HashMap<String,Integer> arr=new HashMap<String,Integer>();\n public AuthenticationManager(int timeToLive)
champdev
NORMAL
2021-03-21T03:20:32.269779+00:00
2021-03-21T03:20:32.269805+00:00
94
false
```\nclass AuthenticationManager {\n int time;\n HashMap<String,Integer> arr=new HashMap<String,Integer>();\n public AuthenticationManager(int timeToLive) {\n time=timeToLive;\n }\n \n public void generate(String tokenId, int currentTime) {\n arr.put(tokenId,currentTime+time);//put token...
1
0
['Java']
0
design-authentication-manager
C++ simple code | easy to understand |using map
c-simple-code-easy-to-understand-using-m-04na
\nclass AuthenticationManager {\npublic:\n int live;\n map<string,int>m;\n AuthenticationManager(int timeToLive) {\n live = timeToLive;\n }\n
srinivasteja18
NORMAL
2021-03-21T02:17:20.664610+00:00
2021-03-21T02:17:20.664641+00:00
37
false
```\nclass AuthenticationManager {\npublic:\n int live;\n map<string,int>m;\n AuthenticationManager(int timeToLive) {\n live = timeToLive;\n }\n void generate(string t, int time) {\n m[t] = time;\n }\n void renew(string t, int time) {\n if(m.find(t) != m.end()){\n if...
1
0
[]
0
design-authentication-manager
CPP||easy solution ||fast
cppeasy-solution-fast-by-ashish_200088-yf3x
\nclass AuthenticationManager {\npublic:\n int t;\n map<string,int>m1;\n AuthenticationManager(int timeToLive) {\n t=timeToLive;\n }\n \n
ashish_200088
NORMAL
2021-03-20T18:25:55.346752+00:00
2021-03-20T18:25:55.346782+00:00
48
false
```\nclass AuthenticationManager {\npublic:\n int t;\n map<string,int>m1;\n AuthenticationManager(int timeToLive) {\n t=timeToLive;\n }\n \n void generate(string tokenId, int currentTime) {\n m1[tokenId]=currentTime+t;\n }\n \n void renew(string tokenId, int currentTime) {\n ...
1
0
[]
0
design-authentication-manager
Java Solution Using HashMap
java-solution-using-hashmap-by-sriram-nu-qffk
Note: Make sure to remove the unnecessary tokens in the renew function and countUnexpiredTokens function to avoid TLE.\n\nclass AuthenticationManager {\n Map
sriram-nuthi
NORMAL
2021-03-20T17:51:45.908940+00:00
2021-03-20T17:51:45.908989+00:00
62
false
Note: Make sure to remove the unnecessary tokens in the renew function and countUnexpiredTokens function to avoid TLE.\n```\nclass AuthenticationManager {\n Map<String, Integer> tokens=new HashMap<>();\n int timeToLive;\n public AuthenticationManager(int timeToLive) {\n this.timeToLive=timeToLive;\n ...
1
0
[]
0
design-authentication-manager
[Python] Priority queue O(NlogN) / deque O(N)
python-priority-queue-onlogn-deque-on-by-h78b
During the contest I used priority que but then I realized time is strictly increasing\ncan just use deque to make it faster ( and the logic is the same)\n\ncla
b99202050
NORMAL
2021-03-20T16:23:40.496607+00:00
2021-03-20T17:09:51.470412+00:00
66
false
During the contest I used priority que but then I realized time is strictly increasing\ncan just use deque to make it faster ( and the logic is the same)\n```\nclass AuthenticationManager:\n def __init__(self, timeToLive: int):\n self.state = defaultdict(int) ### self.state[tokenId] > 0 means active \n ...
1
0
[]
0
design-authentication-manager
Single map Very easy C++ solution
single-map-very-easy-c-solution-by-anike-pl7c
```\nclass AuthenticationManager {\npublic:\n int time;\n unordered_mapm;\n AuthenticationManager(int timeToLive) {\n time = timeToLive;\n }\
aniket_jain_
NORMAL
2021-03-20T16:08:25.711950+00:00
2021-03-20T16:08:41.633546+00:00
58
false
```\nclass AuthenticationManager {\npublic:\n int time;\n unordered_map<string,int>m;\n AuthenticationManager(int timeToLive) {\n time = timeToLive;\n }\n \n void generate(string tokenId, int currentTime) {\n m[tokenId] = currentTime;\n }\n \n void renew(string tokenId, int curr...
1
1
[]
0
design-authentication-manager
Java solution - straight forward
java-solution-straight-forward-by-akiram-iuda
\nclass AuthenticationManager {\n int ttl = 0;\n Map<String, Integer> map;\n\n public AuthenticationManager(int timeToLive) {\n this.ttl = timeT
akiramonster
NORMAL
2021-03-20T16:07:52.763040+00:00
2021-03-20T16:07:52.763090+00:00
75
false
```\nclass AuthenticationManager {\n int ttl = 0;\n Map<String, Integer> map;\n\n public AuthenticationManager(int timeToLive) {\n this.ttl = timeToLive;\n this.map = new HashMap<>();\n }\n\n public void generate(String tokenId, int currentTime) {\n map.put(tokenId, currentTime);\n ...
1
1
[]
0
design-authentication-manager
Unordered Map Solution C++
unordered-map-solution-c-by-kunalsuri-5tha
\nclass AuthenticationManager {\npublic:\n unordered_map<string, int> map;\n int expired, tol;\n AuthenticationManager(int timeToLive) {\n this-
kunalsuri
NORMAL
2021-03-20T16:07:24.757833+00:00
2021-03-20T16:07:24.757895+00:00
95
false
```\nclass AuthenticationManager {\npublic:\n unordered_map<string, int> map;\n int expired, tol;\n AuthenticationManager(int timeToLive) {\n this->tol = timeToLive;\n expired = 0;\n }\n \n void generate(string tokenId, int currentTime) {\n map[tokenId] = currentTime + this->tol;\...
1
0
['C']
0
design-authentication-manager
[Python3] dict(HashMap)
python3-dicthashmap-by-zonda_yang-tptf
python\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n self.tokens = dict()\n \n
zonda_yang
NORMAL
2021-03-20T16:04:45.612223+00:00
2021-03-20T16:04:45.612250+00:00
135
false
```python\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n self.tokens = dict()\n \n def generate(self, tokenId: str, currentTime: int) -> None:\n self.tokens[tokenId] = currentTime + self.timeToLive\n \n def renew(self, ...
1
0
[]
1
design-authentication-manager
[Python3] hash map
python3-hash-map-by-ye15-bpvt
\n\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n self.tokens = {}\n\n def generate
ye15
NORMAL
2021-03-20T16:01:25.776672+00:00
2021-03-21T00:36:20.277368+00:00
146
false
\n```\nclass AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n self.timeToLive = timeToLive\n self.tokens = {}\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n self.tokens[tokenId] = currentTime + self.timeToLive\n\n def renew(self, tokenId: str, currentTim...
1
0
['Python3']
0
design-authentication-manager
🗺 C++ 2 maps (time + name)
c-2-maps-time-name-by-claytonjwong-1797
\nclass AuthenticationManager {\n int K; // time-to-live\n using Set = unordered_set<string>;\n using TimeMap = map<int, Set>;\n using NameMap = uno
claytonjwong
NORMAL
2021-03-20T16:00:55.862982+00:00
2021-03-20T17:22:26.542068+00:00
170
false
```\nclass AuthenticationManager {\n int K; // time-to-live\n using Set = unordered_set<string>;\n using TimeMap = map<int, Set>;\n using NameMap = unordered_map<string, int>;\n TimeMap timeMap;\n NameMap nameMap;\n void processExpiry(int t) {\n auto last = timeMap.upper_bound(t); // < t\n ...
1
0
[]
1
design-authentication-manager
Java HashMap
java-hashmap-by-vikrant_pc-h40f
\nclass AuthenticationManager {\n int timeToLive;\n Map<String, Integer> map = new HashMap<>();\n\n public AuthenticationManager(int timeToLive) {\n
vikrant_pc
NORMAL
2021-03-20T16:00:55.589953+00:00
2021-03-20T16:00:55.589981+00:00
125
false
```\nclass AuthenticationManager {\n int timeToLive;\n Map<String, Integer> map = new HashMap<>();\n\n public AuthenticationManager(int timeToLive) {\n this.timeToLive=timeToLive;\n }\n \n public void generate(String tokenId, int currentTime) {\n map.put(tokenId, currentTime);\n }\n ...
1
1
[]
0
design-authentication-manager
Java AC Solution | HashMap
java-ac-solution-hashmap-by-kyuhiladaala-5vww
IntuitionApproachComplexity Time complexity: generate() - O(1) renew() - O(1) countUnexpiredTokens() - O(n), where n is the number of distinct tokens stored in
kyuHilaDaalaNa
NORMAL
2025-04-11T06:07:17.171554+00:00
2025-04-11T06:07:17.171554+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: generate() - O(1) renew() - O(1) countUnexpiredTokens() - O(n), where n is the number of distinct tokens stored in tokenExpiryTime <!-- Ad...
0
0
['Java']
0
design-authentication-manager
Design of Authentication Manager || CPP
design-of-authentication-manager-cpp-by-878si
Complexity Time complexity: O(1) for all the methods of AuthenticationManager Space complexity: O(1) Code
ShashidharAngadi
NORMAL
2025-04-03T19:23:42.257851+00:00
2025-04-03T19:23:42.257851+00:00
3
false
# Complexity - Time complexity: O(1) for all the methods of AuthenticationManager - Space complexity: O(1) # Code ```cpp [] class AuthenticationManager { private: int timeToLive; unordered_map<string,pair<int,int>> tokenTime; public: AuthenticationManager(int timeToLive) { this->timeToLive = t...
0
0
['C++']
0
design-authentication-manager
Simple Python Solution - Dictionary and Queue
simple-python-solution-dictionary-and-qu-7i7r
null
kschinella
NORMAL
2025-03-29T11:13:34.871009+00:00
2025-03-29T11:13:34.871009+00:00
2
false
```python [] class AuthenticationManager(object): def __init__(self, timeToLive): """ :type timeToLive: int """ self.timeToLive = timeToLive self.tokens = deque() self.tokensMap = {} def generate(self, tokenId, currentTime): """ :type tokenId: st...
0
0
['Python']
0
design-authentication-manager
Python solution O(n)
python-solution-on-by-kavya_171998-aisx
IntuitionFollow the question line by lineComplexity Time complexity: O(n) Space complexity: O(n) Code
kavya_171998
NORMAL
2025-03-23T13:17:21.938748+00:00
2025-03-23T13:17:21.938748+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Follow the question line by line # 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 ```python3 [] class Authen...
0
0
['Python3']
0
design-authentication-manager
My Java solution using HashMap
my-java-solution-using-hashmap-by-pooja2-hg19
IntuitionCould n't understand why is this listed in Linkedlist The first thought that came up is to use a map to store token id and expiration time of each toke
pooja2345
NORMAL
2025-03-21T12:13:06.197557+00:00
2025-03-21T12:15:23.466535+00:00
6
false
# Intuition Could n't understand why is this listed in Linkedlist The first thought that came up is to use a map to store token id and expiration time of each token ** do not forget to check its expiration time before renewing the token ** # Approach 1. Use a hashmap 2. store its tokenId as key & expiration time as...
0
0
['Java']
0