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
reveal-cards-in-increasing-order
[Java] Easy 100% solution using a queue + explanation
java-easy-100-solution-using-a-queue-exp-qrcj
\nclass Solution {\n public int[] deckRevealedIncreasing(int[] deck) {\n Arrays.sort(deck);\n\n Queue<Integer> queue = new LinkedList<>();\n\n
YTchouar
NORMAL
2024-02-08T06:56:14.585280+00:00
2024-02-08T06:56:14.585299+00:00
338
false
```\nclass Solution {\n public int[] deckRevealedIncreasing(int[] deck) {\n Arrays.sort(deck);\n\n Queue<Integer> queue = new LinkedList<>();\n\n for(int i = deck.length - 1; i >= 0; --i) {\n if(queue.size() > 0)\n queue.add(queue.poll());\n queue.add(deck[i]...
4
0
['Java']
0
reveal-cards-in-increasing-order
Ruby Solution
ruby-solution-by-purandhar999-6ufz
\n# Code\n\ndef deck_revealed_increasing(deck)\n res = [deck.sort!.pop]\n deck.reverse_each { |x| res = [x, res.pop] + res }\n res\nend\n
Purandhar999
NORMAL
2023-11-24T06:47:23.695253+00:00
2023-11-24T06:47:23.695276+00:00
48
false
\n# Code\n```\ndef deck_revealed_increasing(deck)\n res = [deck.sort!.pop]\n deck.reverse_each { |x| res = [x, res.pop] + res }\n res\nend\n```
4
0
['Ruby']
0
reveal-cards-in-increasing-order
----- Beginner friendly approach 4 lines of logic code with 0ms + Notes -----
beginner-friendly-approach-4-lines-of-lo-5lvo
Have a look at the pattern before moving to the code - \n\ninput array - [17,13,11,2,3,5,7]\nsorted array - [2,3,5,7,11,13,17]\noutput array -[2,13,3,11,5,17,7]
HarryBad
NORMAL
2022-09-01T11:27:48.010941+00:00
2022-09-01T12:18:20.031285+00:00
586
false
Have a look at the pattern before moving to the code - \n\ninput array - [17,13,11,2,3,5,7]\nsorted array - [2,3,5,7,11,13,17]\noutput array -[2,13,3,11,5,17,7]\n\nHave a look at this pattern (taken from explanation) - \n\n[17] -pick the (n-1)th element from sorted array and add to front.\n[13,17]. ...
4
0
['Queue', 'C++']
0
reveal-cards-in-increasing-order
C++ || reverse engineering || Deque
c-reverse-engineering-deque-by-mr_optimi-hwaa
We will appreach this question in reverse order.\nAs we want to reveal in sorted orde (smaller to larger), we sort the vector in (larger to smaller).\nNow in pl
mr_optimizer
NORMAL
2021-10-14T15:40:12.253653+00:00
2021-10-14T15:40:12.253689+00:00
275
false
We will appreach this question in reverse order.\nAs we want to reveal in sorted orde (smaller to larger), we sort the vector in (larger to smaller).\nNow in place of revealing from front, we push new the card in front, and in place of pushing our card from top to bottom, we take card from back and put in onto top.\n\n...
4
0
['Queue', 'C']
0
reveal-cards-in-increasing-order
c++ 8ms simple solution
c-8ms-simple-solution-by-kkchengaf-7kju
Basically after placing a number in answer array, just leave one empty space to represent an unrevealed card, repeat the process and fill up all empty space lat
kkchengaf
NORMAL
2020-02-10T03:00:15.787330+00:00
2020-02-10T03:00:30.831944+00:00
699
false
Basically after placing a number in answer array, just leave one empty space to represent an unrevealed card, repeat the process and fill up all empty space later in the same manner. Below is a direct implementation of the idea. \n\n```\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& dec...
4
0
['C', 'C++']
1
reveal-cards-in-increasing-order
100%%%% beatsssss Easy Solution very very very veryyyyyyyyyyyyy
100-beatsssss-easy-solution-very-very-ve-oxjw
Intuition\nDesi approch\nSee the explannation of the testcase.\nLook.(From below of the testcase)\nYou see the pattern that new number from the vector in increa
ShivanshGoel1611
NORMAL
2024-06-24T08:34:16.312146+00:00
2024-06-24T08:34:16.312182+00:00
6
false
# Intuition\n*Desi approch*\nSee the explannation of the testcase.\nLook.(From below of the testcase)\nYou see the pattern that new number from the vector in increasing order come in the new array and the back element of previous array is next one of new array and rest from starting of previous array come as\nitis...\n...
3
0
['Queue', 'C++']
0
reveal-cards-in-increasing-order
✅✅FULL DETAILED EXPLANATION ||BEATS 98 PERCENT✅✅
full-detailed-explanation-beats-98-perce-7pbe
Intuition\n Describe your first thoughts on how to solve this problem. \n# guys you need to fry run pls upvote man , I write so much and you guys are so weirs y
Abhishekkant135
NORMAL
2024-04-10T17:58:25.018870+00:00
2024-04-10T17:58:25.018926+00:00
26
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n# guys you need to fry run pls upvote man , I write so much and you guys are so weirs you dont even upvote me.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n**Steps:**\n\n1. **Initialization:**\n - `int n = d...
3
0
['Simulation', 'Java']
0
reveal-cards-in-increasing-order
E☠💀💯 Faster✅💯Lesser🧠🎯C++✅Python3✅Java✅C✅Python✅💥🔥💫Explained☠💥🔥 Beats 💯
e-fasterlessercpython3javacpythonexplain-svaa
Intuition\n\n\n\n\nC++ []\n#define ll long long\n#define vi vector<int>\n#define vvi vector<vi>\n#define vl vector<long>\n#define vvl vector<vl>\n#define all(n)
Edwards310
NORMAL
2024-04-10T15:22:44.965107+00:00
2024-05-03T16:13:36.741514+00:00
47
false
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/cdf62d0d-aea6-44b6-b607-27cb8cf1de24_1712762336.4983914.jpeg)\n![Screenshot 2024-04-10 204723.png](https://assets.leetcode.com/users/images/bf2d2ede-dddc-4417-afbb-fe15ea101fdc_1712762344.5396209.png)\n![Screenshot 2024-04-10 205058.png](https:/...
3
0
['Array', 'Queue', 'C', 'Simulation', 'Python', 'C++', 'Java', 'Python3']
1
reveal-cards-in-increasing-order
C# Solution for Reveal Cards In Increasing Order Problem
c-solution-for-reveal-cards-in-increasin-eu1e
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this solution is to use a queue to keep track of the indices of th
Aman_Raj_Sinha
NORMAL
2024-04-10T11:12:43.254320+00:00
2024-04-10T11:12:43.254347+00:00
202
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this solution is to use a queue to keep track of the indices of the result array. By simulating the card revealing process, we assign cards to the corresponding indices in the result array while ensuring that the orde...
3
0
['C#']
1
reveal-cards-in-increasing-order
Beats 100% users || Easy & beginner friendly approach || O(nlogn) complexity
beats-100-users-easy-beginner-friendly-a-98w8
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nJust observe the pattern backward how cards the drawn from the deck.We have to us
SoumyaAdhikary
NORMAL
2024-04-10T06:56:58.172387+00:00
2024-04-10T07:08:33.217410+00:00
94
false
![Screenshot 2024-04-10 121839.png](https://assets.leetcode.com/users/images/4e36232e-6c19-4645-acc3-83a414bb17aa_1712732195.0062523.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust observe the pattern backward how cards the drawn from the deck.We have to use a dequq to do ...
3
0
['C++']
1
reveal-cards-in-increasing-order
Simple Bottom-up approach || Simulation || C++
simple-bottom-up-approach-simulation-c-b-bocd
Intuition\n Describe your first thoughts on how to solve this problem. \nAfter some dry-run, my intuition started out like this. (Bottom-up-approach)\n- conside
Aryan_Marwaha
NORMAL
2024-04-10T06:28:47.741808+00:00
2024-04-10T06:28:47.741841+00:00
54
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAfter some dry-run, my intuition started out like this. **(Bottom-up-approach)**\n- consider the rectangular portion to be a sliding window (deque).\n- start from bottom and work up your way to top.\n<div align="center">\n <img src="ht...
3
0
['Sliding Window', 'Simulation', 'C++']
0
reveal-cards-in-increasing-order
✅ Java || Simulation || Time O(nlog(n)) || Space O(n) || Easy Explained ✅
java-simulation-time-onlogn-space-on-eas-c13k
Intuition\nThe problem asks us to reveal cards in a specific order to make them appear in increasing order when read from left to right. Initially, all cards ar
0xsonu
NORMAL
2024-04-10T05:26:25.101599+00:00
2024-04-10T05:26:25.101631+00:00
26
false
# Intuition\nThe problem asks us to reveal cards in a specific order to make them appear in increasing order when read from left to right. Initially, all cards are facing down. We need to simulate the process of revealing cards according to the given rules.\n\n# Approach\n1. **Sorting:** First, we sort the given deck o...
3
0
['Array', 'Queue', 'Sorting', 'Simulation', 'Java']
0
reveal-cards-in-increasing-order
Python | Easy
python-easy-by-khosiyat-6zku
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:\n # Sort the d
Khosiyat
NORMAL
2024-04-10T05:18:58.677133+00:00
2024-04-10T05:18:58.677151+00:00
351
false
[see the Successfully Accepted Submission](https://leetcode.com/problems/reveal-cards-in-increasing-order/submissions/1228249497/?envType=daily-question&envId=2024-04-10)\n\n# Code\n```\nclass Solution:\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:\n # Sort the deck\n deck.sort()\n ...
3
0
['Python3']
1
reveal-cards-in-increasing-order
✅ 🔥Interview solution | No Duque/queue | With basic looping | 100% faster ✅ 🔥
interview-solution-no-duquequeue-with-ba-x89t
Hi,\n\nMy approach is to adhere to the fundamentals and implement our logic, rather than relying on a queue/deque, which may not satisfy the interviewer.\n\nUnd
Surendaar
NORMAL
2024-04-10T05:17:35.038550+00:00
2024-04-10T06:39:04.041760+00:00
363
false
Hi,\n\nMy approach is to adhere to the fundamentals and implement our logic, rather than relying on a queue/deque, which may not satisfy the interviewer.\n\n**Understand:**\nWe need the result array to be in sorted order, so we should place the values such that if we place an element in an empty index, the next element...
3
0
['Sorting', 'Java']
1
reveal-cards-in-increasing-order
No Queue Needed, O(1) space, 0ms C++ beats 100%
no-queue-needed-o1-space-0ms-c-beats-100-dhc7
\n//https://hyper-meta.blogspot.com/\n#pragma GCC target("avx,mmx,sse2,sse3,sse4")\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;
yjian012
NORMAL
2024-04-10T03:08:35.710584+00:00
2024-04-11T10:02:05.539842+00:00
82
false
```\n//https://hyper-meta.blogspot.com/\n#pragma GCC target("avx,mmx,sse2,sse3,sse4")\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n const int sz=deck.size();\n sort(deck.begin(),deck.e...
3
0
['C++']
0
reveal-cards-in-increasing-order
Strictly O(N) Math Solution W/O any queue
strictly-on-math-solution-wo-any-queue-b-rkr5
Intuition\n Describe your first thoughts on how to solve this problem. \nEvery time we are removing half of the cards we just have to figure out which those car
arnavbssaini
NORMAL
2023-09-04T19:35:15.933672+00:00
2023-09-04T19:56:22.159671+00:00
239
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEvery time we are removing half of the cards we just have to figure out which those cards are.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTake the very first cycle, we will reveal all the even numbered index c...
3
0
['Java']
0
reveal-cards-in-increasing-order
JavaScript 91.84% faster | Simplest solution with explanation O(n) | Queue| Beg to Adv
javascript-9184-faster-simplest-solution-ly2q
\n\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n\n# Code\n\n/**\n * @param {number[]} deck\n * @return {number[]}\n */\nvar deckRevealedI
rlakshay14
NORMAL
2023-07-20T19:57:19.823805+00:00
2023-07-20T19:57:19.823834+00:00
188
false
![image.png](https://assets.leetcode.com/users/images/588cb9a1-9030-4451-856a-00ba176550a5_1689882121.4767842.png)\n\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n\n# Code\n```\n/**\n * @param {number[]} deck\n * @return {number[]}\n */\nvar deckRevealedIncreasing = function(deck) {\n let stack...
3
0
['Queue', 'JavaScript']
2
reveal-cards-in-increasing-order
c++ Solution using Queue | 100% faster | 0ms
c-solution-using-queue-100-faster-0ms-by-yv75
This solution takes an input vector deck and sorts it in increasing order. It then uses a queue to store the indices of the elements in the deck. The algorithm
teja_swaroop
NORMAL
2023-07-09T06:46:56.766942+00:00
2023-07-09T08:31:43.529632+00:00
336
false
This solution takes an input vector deck and sorts it in increasing order. It then uses a queue to store the indices of the elements in the deck. The algorithm iterates through the deck and assigns the sorted values to the corresponding indices in a result vector.\n\nThe queue is processed until it becomes empty. At ea...
3
0
['Array', 'Queue', 'C', 'Sorting']
0
reveal-cards-in-increasing-order
Solution
solution-by-deleted_user-g4lb
C++ []\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n queue<int>q;\n int n=deck.size();\n sort(d
deleted_user
NORMAL
2023-05-16T04:15:45.896721+00:00
2023-05-16T04:29:10.015372+00:00
933
false
```C++ []\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n queue<int>q;\n int n=deck.size();\n sort(deck.begin(),deck.end());;\n for(int i=0;i<n;i++)\n q.push(i);\n vector<int>res(n,0);\n int i=0;\n while(!q.empty() && i<n)...
3
0
['C++', 'Java', 'Python3']
1
reveal-cards-in-increasing-order
Java - Solution (add first ,skipping second approach)
java-solution-add-first-skipping-second-xbq4k
\npublic int[] deckRevealedIncreasing(int[] deck) {\n Arrays.sort(deck);\n int n = deck.length;\n Queue<Integer> q = new LinkedList<>();\n
shubhankar01
NORMAL
2022-08-14T12:16:51.290513+00:00
2022-08-14T12:16:51.290543+00:00
667
false
```\npublic int[] deckRevealedIncreasing(int[] deck) {\n Arrays.sort(deck);\n int n = deck.length;\n Queue<Integer> q = new LinkedList<>();\n for(int i = 0; i < n; i++) q.offer(i);\n int ans[] = new int[deck.length];\n for(int i = 0;i < n; i++){\n ans[q.poll()] = dec...
3
0
['Java']
0
reveal-cards-in-increasing-order
[C++] With detailed explanation - Without using deque
c-with-detailed-explanation-without-usin-t453
Logic :\nBasically, here I am taking an element from sorted vector deck one by one and putting it into res vector where 0 is present with one gap.\n\nExample :
isha_070_
NORMAL
2021-06-30T15:11:57.953579+00:00
2021-06-30T20:34:08.863421+00:00
110
false
# **Logic :**\nBasically, here I am taking an element from sorted vector ```deck``` one by one and putting it into ```res``` vector where ```0``` is present with one gap.\n\n**Example :** ```17,13,11,2,3,5,7```\n\nAfter sorting: ```2,3,5,7,11,13,17```\n* Initially:\nres -> ```2,0,0,0,0,0,0```\nPutting smallest element ...
3
0
[]
1
reveal-cards-in-increasing-order
C++ | 100% faster | easy
c-100-faster-easy-by-armangupta48-iyma
\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n queue<int> q;\n for(int i = 0;i<deck.size();i++)\n
armangupta48
NORMAL
2021-05-09T20:43:51.330864+00:00
2021-05-09T20:43:51.330911+00:00
403
false
```\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n queue<int> q;\n for(int i = 0;i<deck.size();i++)\n {\n q.push(i);\n }\n vector<int> ans(deck.size());\n sort(deck.begin(),deck.end());\n for(int card:deck)\n {...
3
0
['C', 'C++']
1
reveal-cards-in-increasing-order
python explained the logic in detail with an example
python-explained-the-logic-in-detail-wit-xfuk
To solve this problem, we can first observe the example, and try to reverse this process:\n\nWe get the deck in the order [17,13,11,2,3,5,7] (this order doesn\'
shuashua2019
NORMAL
2021-04-07T13:36:55.580476+00:00
2021-04-07T13:36:55.580517+00:00
263
false
To solve this problem, we can first observe the example, and try to reverse this process:\n```\nWe get the deck in the order [17,13,11,2,3,5,7] (this order doesn\'t matter), and reorder it.\nAfter reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.\nWe reveal 2, and move 13 to the bottom....
3
0
['Python3']
2
reveal-cards-in-increasing-order
[PYTHON 3] Using Deque - Beats 97 %
python-3-using-deque-beats-97-by-mohamed-ayyp
\nclass Solution:\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:\n deck.sort(reverse = True)\n queue = deque()\n for
mohamedimranps
NORMAL
2020-04-25T06:43:50.303595+00:00
2020-04-25T06:43:50.303634+00:00
458
false
```\nclass Solution:\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:\n deck.sort(reverse = True)\n queue = deque()\n for card in deck:\n if queue:\n queue.appendleft(queue.pop())\n queue.appendleft(card)\n return queue\n```
3
0
['Queue', 'Python3']
1
reveal-cards-in-increasing-order
[Python] 100% O(NlogN)
python-100-onlogn-by-mantasltu-c010
```\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:\n deck.sort()\n res = collections.deque()\n res.append(deck.pop())
mantasltu
NORMAL
2019-08-26T22:15:31.612249+00:00
2019-08-26T22:22:11.156231+00:00
283
false
```\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:\n deck.sort()\n res = collections.deque()\n res.append(deck.pop())\n while deck:\n res.appendleft(res.pop())\n res.appendleft(deck.pop())\n return list(res)
3
0
[]
0
reveal-cards-in-increasing-order
Easy solution with queue by reverse engineering - beats 99.83%
easy-solution-with-queue-by-reverse-engi-zi00
input - [2,3,5,7,11,13,17] (just sort the input that you get)\n\nThe last number that you wanna get is the last number in the array - (17)\n\nThe penultimate nu
nyubee
NORMAL
2019-02-26T05:31:53.274043+00:00
2019-02-26T05:31:53.274089+00:00
481
false
input - [2,3,5,7,11,13,17] (just sort the input that you get)\n\nThe last number that you wanna get is the last number in the array - (17)\n\nThe penultimate number is 13. So put 13 on top of 17 (13,17) and bring the last number to top (17,13). Now while you perform the action with (17,13), you will place 17 in the bot...
3
0
['Queue']
1
reveal-cards-in-increasing-order
C++ beats 100% using deque with explanation
c-beats-100-using-deque-with-explanation-0lrx
In this question, we can find the rules from samples that it pop the first element and move the second element to last. So if want to get the correct answer, we
robotzhao
NORMAL
2019-02-16T16:53:34.226632+00:00
2019-06-11T12:43:22.995151+00:00
242
false
In this question, we can find the rules from samples that it pop the first element and move the second element to last. So if want to get the correct answer, we can do the steps contrary to the rules:\nSort the deck, push elements at the front of the deque from large to small and move the last element to the second eve...
3
1
[]
0
reveal-cards-in-increasing-order
C++ 8ms 99% solution (with detail algorithm)
c-8ms-99-solution-with-detail-algorithm-b0h0l
\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n //Algorithm:\n //The behavior of the question is compos
sjwu
NORMAL
2018-12-22T15:06:57.926767+00:00
2018-12-22T15:06:57.926837+00:00
457
false
```\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n //Algorithm:\n //The behavior of the question is composed of two steps.\n //1. Take the front element out from current vector\n //2. Move the second element to the end of current vector\n //S...
3
0
[]
1
reveal-cards-in-increasing-order
C++ easy and clear way using deque
c-easy-and-clear-way-using-deque-by-teck-inxk
c++\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n vector<int> res;\n \n sort(deck.rbegin(), dec
tecknight
NORMAL
2018-12-02T10:30:35.877200+00:00
2018-12-02T10:30:35.877242+00:00
428
false
```c++\nclass Solution {\npublic:\n vector<int> deckRevealedIncreasing(vector<int>& deck) {\n vector<int> res;\n \n sort(deck.rbegin(), deck.rend());\n deque<int> dq;\n \n dq.push_back(deck[0]);\n \n for(int i=1;i<deck.size();i++)\n {\n dq.pus...
3
1
[]
2
reveal-cards-in-increasing-order
C++ solution with auxiliary queue
c-solution-with-auxiliary-queue-by-kmshi-4xwn
Sort array.\nUse a queue to keep track of indices.\n\n```\nvector deckRevealedIncreasing(vector& deck) {\n\t\t//result array\n std::vector res(deck.size(
kmshihabuddin
NORMAL
2018-12-02T04:04:51.213709+00:00
2018-12-02T04:04:51.213761+00:00
259
false
Sort array.\nUse a queue to keep track of indices.\n\n```\nvector<int> deckRevealedIncreasing(vector<int>& deck) {\n\t\t//result array\n std::vector<int> res(deck.size(),0);\n \n std::sort(deck.begin(),deck.end());\n \n\t\t//queue of card indices\n std::queue<int> indices;\n fo...
3
0
[]
1
reveal-cards-in-increasing-order
USING QUEUE || TC = O(N), SC = O(N)
using-queue-tc-on-sc-on-by-dkvmah7yog-q741
IntuitionApproachComplexity Time complexity: O(N) Space complexity: O(N) Code
DkVMAH7YOG
NORMAL
2025-03-27T17:25:10.668392+00:00
2025-03-27T17:25:10.668392+00:00
42
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(N) - Space complexity: O(N) # Code ```cpp [] class Solution { public: vector<int> deckRevealedIncreasing(vector<int>& deck) { ...
2
0
['Array', 'Queue', 'Sorting', 'Simulation', 'C++']
0
reveal-cards-in-increasing-order
Beginner Level Solution And Explanation
beginner-level-solution-and-explanation-sx30f
Algorithm Sort the Deck: Sort the deck array in ascending order. Initialize an Index Queue: Create a queue containing indices ( 0 ) to ( n-1 ), where ( n ) is t
yadav_sanjay
NORMAL
2025-01-04T07:44:31.453856+00:00
2025-01-04T07:44:31.453856+00:00
123
false
### Algorithm 1. **Sort the Deck**: Sort the `deck` array in ascending order. 2. **Initialize an Index Queue**: Create a queue containing indices \( 0 \) to \( n-1 \), where \( n \) is the length of the deck. 3. **Simulate the Process**: - Assign the smallest card (from the sorted deck) to the position at t...
2
0
['Array', 'Queue', 'Simulation', 'Python', 'C++', 'Java']
0
reveal-cards-in-increasing-order
C++ Easy Solution with full Explanation || Time Complexity O(n)
c-easy-solution-with-full-explanation-ti-943j
Intuition\n Describe your first thoughts on how to solve this problem. \n this solution sorts the deck, arranges the cards in a way that they can be revealed in
uy_154788
NORMAL
2024-04-10T19:11:52.450180+00:00
2024-04-10T19:11:52.450216+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n this solution sorts the deck, arranges the cards in a way that they can be revealed in increasing order, and then rearranges them according to the specified pattern to achieve the final result.\n\n\n# Approach\n<!-- Describe your approac...
2
0
['C++']
0
reveal-cards-in-increasing-order
Beats 86.41% of users with java || Easy solution using queue
beats-8641-of-users-with-java-easy-solut-8u95
\n\n# Approach\n1. Sort the deck:* First, sort the given deck array in increasing order. This allows us to reveal the cards in increasing order.\n\n*2. Initiali
DEEPAK_10439
NORMAL
2024-04-10T16:28:04.845479+00:00
2024-04-10T16:28:04.845514+00:00
130
false
\n\n# Approach\n**1. **Sort the deck:**** First, sort the given deck array in increasing order. This allows us to reveal the cards in increasing order.\n\n**2. Initialize a Queue:** Initialize a queue (let\'s call it indexQueue) to keep track of the indices of the cards in the revealed deck. Populate the queue with the...
2
0
['Java']
1
reveal-cards-in-increasing-order
Reverse Simulation | Java | C++
reverse-simulation-java-c-by-lazy_potato-3u9x
Intuition, approach, and complexity dicussed in video solution in detail.\nhttps://youtu.be/tqLlQHxL0nc\n# Code\n\nJava:\n\njava\nclass Solution {\n public i
Lazy_Potato_
NORMAL
2024-04-10T16:10:45.856037+00:00
2024-04-10T16:10:45.856066+00:00
80
false
# Intuition, approach, and complexity dicussed in video solution in detail.\nhttps://youtu.be/tqLlQHxL0nc\n# Code\n\nJava:\n\n```java\nclass Solution {\n public int[] deckRevealedIncreasing(int[] deck) {\n Arrays.sort(deck);\n Deque<Integer> cardQ = new ArrayDeque<>();\n int size = deck.length;\...
2
0
['Array', 'Queue', 'Sorting', 'Simulation', 'C++', 'Java']
1
reveal-cards-in-increasing-order
Easy Solution || without Queue || pattern identification || O(n * logn)
easy-solution-without-queue-pattern-iden-vv2e
Intuition\npattern identification by analyzing testcases \n Describe your first thoughts on how to solve this problem. \n\n# Approach\ntestcase :- 2 13 3 11 5 1
Kiraa71
NORMAL
2024-04-10T15:48:02.054283+00:00
2024-04-11T02:27:44.113531+00:00
7
false
# Intuition\npattern identification by analyzing testcases \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\ntestcase :- 2 13 3 11 5 17 7 \n\nafter_all_operation :- 2 13 3 11 5 17 7 13 11 17 13 17 \napproach :- first pick last two number and store in ans array and after that alternate...
2
0
['C++']
1
reveal-cards-in-increasing-order
Beats 100% Using C++ | Detailed solution | BOOM BRAIN
beats-100-using-c-detailed-solution-boom-06t9
Intuition\nAfter all elements were sorted, just put them to the right index. \n\n# Approach\n- Create an array of index, just even indexes are revealed first.\n
xuankhuongw
NORMAL
2024-04-10T15:02:53.912060+00:00
2024-04-10T15:03:44.271730+00:00
19
false
# Intuition\nAfter all elements were sorted, just put them to the right index. \n\n# Approach\n- Create an array of index, just even indexes are revealed first.\n- It\'s kind of hard to describe my solution, let\'s see some example.\n- In index-array, if index of element in index-array is even, add deck at this index t...
2
0
['C++']
0
reveal-cards-in-increasing-order
C++ || Beats 100% || Queue || Priority Queue
c-beats-100-queue-priority-queue-by-kush-ufej
Approach\n\nHere we must remeber the index we left earlier therefor queue will be best to store them as if we need them we pop() them else we reinsert the unuse
kushal_019
NORMAL
2024-04-10T12:18:35.772437+00:00
2024-04-10T12:18:35.772460+00:00
30
false
# Approach\n\nHere we must remeber the index we left earlier therefor queue will be best to store them as if we need them we pop() them else we reinsert the unused indexes.\nalso we use priority queue to always add smallest element first.\nwe also used a flag called "flip" to keep a track weather i flip the card or app...
2
0
['Queue', 'Heap (Priority Queue)', 'C++']
0
reveal-cards-in-increasing-order
EASY CPP SOLUTION 💡🔥 || EASY TO UNDERSTOOD🚀
easy-cpp-solution-easy-to-understood-by-nagwn
\n\n# Approach\n\n## 1.Vector Initialization:\nThe code initializes a new vector v with the same elements as the input deck. This is done by using the construct
himanshu_dhage
NORMAL
2024-04-10T12:16:30.131656+00:00
2024-04-10T12:16:30.131688+00:00
9
false
\n\n# Approach\n\n## **1.Vector Initialization:**\n**The code initializes a new vector v with the same elements as the input deck. This is done by using the constructor of the vector class that accepts two iterators pointing to the beginning and end of the range to be copied.\nThe resize() function is then called to re...
2
0
['Array', 'Queue', 'Sorting', 'Simulation', 'C++']
0
reveal-cards-in-increasing-order
QUEUE + SORTING || Solution of reveal cards in increasing order problem
queue-sorting-solution-of-reveal-cards-i-lz5d
This was a daily challenge for April 10th 2024.\n# Queue\nTo solve this problem we use the queue structure\n# Definition\nLike a stack, the queue is a linear da
tiwafuj
NORMAL
2024-04-10T11:05:26.782822+00:00
2024-04-10T11:15:41.776188+00:00
84
false
# This was a daily challenge for April 10th 2024.\n# Queue\nTo solve this problem we use the queue structure\n# Definition\nLike a stack, the queue is a linear data structure that stores items in a First In First Out (FIFO) manner. With a queue, the least recently added item is removed first. A good example of a queue ...
2
0
['Array', 'Queue', 'Sorting', 'Simulation', 'Python3']
0
reveal-cards-in-increasing-order
EASY || JAVA || SORTING || USING QUEUES !!!
easy-java-sorting-using-queues-by-va-run-kdqi
Intuition:\nThe problem is to reveal the cards in increasing order based on their unique integers. To accomplish this, we can simulate the process of revealing
va-run-6626
NORMAL
2024-04-10T10:33:21.966356+00:00
2024-04-10T10:33:21.966406+00:00
63
false
# Intuition:\nThe problem is to reveal the cards in increasing order based on their unique integers. To accomplish this, we can simulate the process of revealing cards as described in the problem statement. The essential steps involve sorting the deck initially and then iteratively revealing the cards while maintaining...
2
0
['Array', 'Queue', 'Simulation', 'Java']
0
reveal-cards-in-increasing-order
🔥 C++ || 2 interview approaches using simulator vector, queue - best explanation and example
c-2-interview-approaches-using-simulator-jk93
2 solutions\n1. First solution: using queue\n2. Second solution: using simulator vector\n\n# First Approach\n- Look at an example to explore the solution and de
minhle3003
NORMAL
2024-04-10T10:28:43.219044+00:00
2024-04-10T10:28:43.219075+00:00
10
false
# 2 solutions\n1. First solution: using queue\n2. Second solution: using simulator vector\n\n# First Approach\n- Look at an example to explore the solution and decide which data structures that you use:\n1. First, sorting the deck helps us to start with the smallest card.\n2. Pop the front element and push it at the en...
2
0
['C++']
0
reveal-cards-in-increasing-order
Easy C++ solution for beginners || Easy intuitive and explained approach
easy-c-solution-for-beginners-easy-intui-h1pa
Intuition\n Describe your first thoughts on how to solve this problem. \nThis C++ solution implements the deckRevealedIncreasing function, which takes a vector
deleted_user
NORMAL
2024-04-10T10:13:05.977263+00:00
2024-04-10T10:13:05.977289+00:00
50
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis C++ solution implements the deckRevealedIncreasing function, which takes a vector of integers representing a deck of cards and returns a vector where the cards are revealed in increasing order. The intuition behind this solution is t...
2
0
['Array', 'Queue', 'Sorting', 'Simulation', 'C++']
0
reveal-cards-in-increasing-order
Scala: simple Queue simulation with indices
scala-simple-queue-simulation-with-indic-v6hs
Code\n\nobject Solution {\n def deckRevealedIncreasing(deck: Array[Int]): Array[Int] = {\n val q = collection.mutable.Queue.range(0, deck.length)\n \n
SerhiyShaman
NORMAL
2024-04-10T08:58:18.932125+00:00
2024-04-10T08:58:18.932161+00:00
11
false
# Code\n```\nobject Solution {\n def deckRevealedIncreasing(deck: Array[Int]): Array[Int] = {\n val q = collection.mutable.Queue.range(0, deck.length)\n \n deck.sorted.foreach { c => \n deck(q.dequeue) = c\n if (q.nonEmpty) q.enqueue(q.dequeue)\n }\n\n deck\n }\n}\n```
2
0
['Scala']
0
reveal-cards-in-increasing-order
2 Easy Interview Approaches ✅ || using Dequeue👍 || Without Dequeue 🔥|| C++ || Java || Python
2-easy-interview-approaches-using-dequeu-k0pq
\n\n# Approach 1\n Describe your approach to solving the problem. \nusing dequeue \n\n# Complexity\n- Time complexity: O(nlogn)\n Add your time complexity here,
naman_malik
NORMAL
2024-04-10T08:54:57.156023+00:00
2024-04-10T08:54:57.156048+00:00
138
false
![Runtime complexity.png](https://assets.leetcode.com/users/images/9f245e16-6c14-4f55-8b02-4413b99739c8_1712738954.6540618.png)\n\n# Approach 1\n<!-- Describe your approach to solving the problem. -->\nusing dequeue \n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n...
2
0
['Array', 'Queue', 'Swift', 'C', 'Python', 'C++', 'Java', 'Rust', 'Kotlin', 'JavaScript']
0
reveal-cards-in-increasing-order
Simple solution
simple-solution-by-techtinkerer-q71b
Intuition\njust put indexes in queue from 1 to n and do what is said. After put values in the indices of the answer vector.\n Describe your first thoughts on ho
TechTinkerer
NORMAL
2024-04-10T07:17:09.958068+00:00
2024-04-10T07:17:09.958090+00:00
8
false
# Intuition\njust put indexes in queue from 1 to n and do what is said. After put values in the indices of the answer vector.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(...
2
0
['Greedy', 'Queue', 'Simulation', 'C++']
0
reveal-cards-in-increasing-order
Easy and Beginner Friendly || Beats 100%
easy-and-beginner-friendly-beats-100-by-mii9i
\n\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nAfter looking to the problem,we can see that we have to start from last ie, we
adrijchakraborty7
NORMAL
2024-04-10T06:21:56.295941+00:00
2024-04-10T12:35:28.842414+00:00
102
false
\n![image.png](https://assets.leetcode.com/users/images/82a11530-e65b-40ce-b5a9-416380e9265c_1712729335.0336792.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAfter looking to the problem,we can see that we have to start from last ie, we will sort the array and start with the ...
2
0
['C']
0
time-based-key-value-store
C++ 3 lines, hash map + map
c-3-lines-hash-map-map-by-votrubac-e4ui
We use hash map to lookup ordered {timestamp, value} pairs by key in O(1). Then, we use binary search to find the value with a timestamp less or equal than the
votrubac
NORMAL
2019-01-27T04:03:00.480601+00:00
2019-07-29T17:18:35.051867+00:00
56,316
false
We use hash map to lookup ordered ```{timestamp, value}``` pairs by key in O(1). Then, we use binary search to find the value with a timestamp less or equal than the requested one.\n```\nunordered_map<string, map<int, string>> m;\nvoid set(string key, string value, int timestamp) {\n m[key].insert({ timestamp, value }...
331
7
[]
42
time-based-key-value-store
TreeMap Solution Java
treemap-solution-java-by-poorvank-dq9b
\npublic class TimeMap {\n\n private Map<String,TreeMap<Integer,String>> map;\n\n /** Initialize your data structure here. */\n public TimeMap() {\n
poorvank
NORMAL
2019-01-27T04:02:54.033868+00:00
2019-01-27T04:02:54.033921+00:00
36,141
false
```\npublic class TimeMap {\n\n private Map<String,TreeMap<Integer,String>> map;\n\n /** Initialize your data structure here. */\n public TimeMap() {\n map = new HashMap<>();\n }\n\n public void set(String key, String value, int timestamp) {\n if(!map.containsKey(key)) {\n map.pu...
250
5
[]
26
time-based-key-value-store
[Python] Dict and Binary search Implementation
python-dict-and-binary-search-implementa-5r46
Most of the solution here doesn\'t give you the binary search implementation, but you propabaly needs to write it during the interview...\n\n\nclass TimeMap(obj
yidong_w
NORMAL
2019-01-28T23:30:38.837300+00:00
2019-01-28T23:30:38.837378+00:00
33,058
false
Most of the solution here doesn\'t give you the binary search implementation, but you propabaly needs to write it during the interview...\n\n```\nclass TimeMap(object):\n\n def __init__(self):\n self.dic = collections.defaultdict(list)\n \n\n def set(self, key, value, timestamp):\n self.dic[k...
220
7
[]
21
time-based-key-value-store
Java beats 100%
java-beats-100-by-ramankes-09g1
\nclass Data {\n String val;\n int time;\n Data(String val, int time) {\n this.val = val;\n this.time = time;\n }\n}\nclass TimeMap {\
ramankes
NORMAL
2019-02-25T23:01:35.076938+00:00
2019-02-25T23:01:35.076993+00:00
23,572
false
```\nclass Data {\n String val;\n int time;\n Data(String val, int time) {\n this.val = val;\n this.time = time;\n }\n}\nclass TimeMap {\n\n /** Initialize your data structure here. */\n Map<String, List<Data>> map;\n public TimeMap() {\n map = new HashMap<String, List<Data>>()...
152
3
[]
19
time-based-key-value-store
Python concise 6-liner
python-concise-6-liner-by-cenkay-775v
\nclass TimeMap:\n\n def __init__(self):\n self.times = collections.defaultdict(list)\n self.values = collections.defaultdict(list)\n\n def
cenkay
NORMAL
2019-03-02T13:07:52.133181+00:00
2019-03-02T13:07:52.133243+00:00
14,977
false
```\nclass TimeMap:\n\n def __init__(self):\n self.times = collections.defaultdict(list)\n self.values = collections.defaultdict(list)\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n self.times[key].append(timestamp)\n self.values[key].append(value)\n\n def get(se...
79
3
[]
12
time-based-key-value-store
C++ unordered_map + Binary Search(last occurrence)
c-unordered_map-binary-searchlast-occurr-5uwg
\nclass TimeMap {\npublic:\n /** Initialize your data structure here. */\n unordered_map<string, vector<pair<int, string>>> m;\n TimeMap() {\n \
dawar
NORMAL
2019-05-26T09:31:19.890868+00:00
2020-04-25T06:21:05.495465+00:00
8,801
false
```\nclass TimeMap {\npublic:\n /** Initialize your data structure here. */\n unordered_map<string, vector<pair<int, string>>> m;\n TimeMap() {\n \n }\n \n void set(string key, string value, int timestamp) {\n m[key].push_back({timestamp, value});\n }\n \n string get(string key,...
52
1
[]
10
time-based-key-value-store
✅Three Simple Java Solutions
three-simple-java-solutions-by-ahmedna12-nbcw
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
ahmedna126
NORMAL
2023-09-29T09:25:24.815388+00:00
2023-11-07T11:35:14.737732+00:00
5,428
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)$$ --...
51
0
['Hash Table', 'Binary Search', 'Tree', 'Java']
5
time-based-key-value-store
Clearly Explained Python Solution Using Binary Search | Time complexity O(log n)
clearly-explained-python-solution-using-54i85
Problem Description\n\nThe problem requires implementing a time-based key-value store where you can set a key-value pair with an associated timestamp and retrie
KhadimHussainDev
NORMAL
2024-04-14T15:36:58.093691+00:00
2024-04-14T15:36:58.093725+00:00
6,843
false
## Problem Description\n\nThe problem requires implementing a time-based key-value store where you can set a key-value pair with an associated timestamp and retrieve the value of a key at a specific timestamp.\n\n## Approach Explanation\n\nThis solution uses a dictionary (`self.dic`) to store key-value pairs where each...
47
0
['Binary Search', 'Python3']
3
time-based-key-value-store
Java binary search & treemap solution
java-binary-search-treemap-solution-by-t-8fjm
Binary search:\n\nclass TimeMap {\n\n class Node {\n String value;\n int timestamp;\n Node(String value, int timestamp) {\n t
tankztc
NORMAL
2019-04-27T21:42:28.240822+00:00
2019-04-27T21:42:28.240868+00:00
9,002
false
Binary search:\n```\nclass TimeMap {\n\n class Node {\n String value;\n int timestamp;\n Node(String value, int timestamp) {\n this.value = value;\n this.timestamp = timestamp;\n }\n }\n \n Map<String, List<Node>> map;\n /** Initialize your data structure...
39
1
[]
6
time-based-key-value-store
Python clean solution, binary search
python-clean-solution-binary-search-by-j-zjce
\nclass TimeMap(object):\n\n def __init__(self):\n self.map = collections.defaultdict(list)\n \n\n def set(self, key, value, timestamp):\n
jdjw
NORMAL
2019-10-19T19:34:42.055918+00:00
2019-10-19T19:34:59.665888+00:00
7,409
false
```\nclass TimeMap(object):\n\n def __init__(self):\n self.map = collections.defaultdict(list)\n \n\n def set(self, key, value, timestamp):\n self.map[key].append((timestamp, value))\n \n\n def get(self, key, timestamp):\n values = self.map[key]\n if not values: return...
30
0
['Binary Tree', 'Python']
4
time-based-key-value-store
Time Based Key-Value Store || 95.83% FASTER || 3 LINE C++CODE || RUNTIME: 333 ms
time-based-key-value-store-9583-faster-3-7ziw
SHIVAM DAILY LEETCODE SOLUTIONS || CHECK : https://bit.ly/leetcode-solutions\nRuntime: 333 ms, faster than 95.83% of C++ online submissions for Time Based Key-V
shivambit
NORMAL
2022-10-06T04:44:16.705571+00:00
2022-10-06T04:45:44.809574+00:00
5,719
false
**SHIVAM DAILY LEETCODE SOLUTIONS || CHECK : [https://bit.ly/leetcode-solutions](https://bit.ly/leetcode-solutions)\nRuntime: 333 ms, faster than 95.83% of C++ online submissions for Time Based Key-Value Store.\nMemory Usage: 130.7 MB, less than 29.45% of C++ online submissions for Time Based Key-Value Store.**\n\n```\...
25
1
['C', 'C++']
4
time-based-key-value-store
Easy C++ [[ 7 Lines of Code ]]
easy-c-7-lines-of-code-by-code_report-nsvm
```\nclass TimeMap {\npublic:\n /* Initialize your data structure here. /\n unordered_map> m;\n\n TimeMap() {}\n\n void set(string key, string value, in
code_report
NORMAL
2019-01-27T04:01:53.843852+00:00
2019-01-27T04:01:53.843919+00:00
5,257
false
```\nclass TimeMap {\npublic:\n /** Initialize your data structure here. */\n unordered_map<string, map<int, string>> m;\n\n TimeMap() {}\n\n void set(string key, string value, int timestamp) {\n auto& inner_map = m[key];\n inner_map[-timestamp] = value;\n }\n\n string get(string key, int timestam...
24
1
[]
7
time-based-key-value-store
Python Binary Search Solution
python-binary-search-solution-by-anch999-u2t3
The idea is using binary search to find the closest timestamp_prev in TimeMap\n\n\nclass TimeMap:\n\n def __init__(self):\n self._dic = defaultdict(li
anch9999
NORMAL
2019-05-18T08:25:25.377103+00:00
2019-08-22T04:01:24.156379+00:00
5,986
false
The idea is using binary search to find the closest timestamp_prev in TimeMap\n\n```\nclass TimeMap:\n\n def __init__(self):\n self._dic = defaultdict(list)\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n self._dic[key].append((value, timestamp,))\n\n def get(self, key: str, ti...
20
0
[]
4
time-based-key-value-store
[Python3] Clean and efficient code - O(1), O(log n)
python3-clean-and-efficient-code-o1-olog-n858
Code\npython\nclass TimeMap:\n def __init__(self):\n self.meta = collections.defaultdict(list)\n self.data = collections.defaultdict(list)\n\n
spark9625
NORMAL
2021-05-22T09:58:32.711356+00:00
2021-05-22T10:07:13.957134+00:00
5,516
false
## Code\n```python\nclass TimeMap:\n def __init__(self):\n self.meta = collections.defaultdict(list)\n self.data = collections.defaultdict(list)\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n self.meta[key].append(timestamp)\n self.data[key].append(value)\n\n def...
19
0
['Binary Tree', 'Python', 'Python3']
3
time-based-key-value-store
Javascript map
javascript-map-by-acassara-nupc
javascript\nvar TimeMap = function() {\n this.map = new Map();\n};\n\nTimeMap.prototype.set = function(key, value, timestamp) {\n if (!this.map.has(key))
acassara
NORMAL
2019-11-10T18:05:21.006027+00:00
2019-11-10T18:05:33.452530+00:00
3,853
false
```javascript\nvar TimeMap = function() {\n this.map = new Map();\n};\n\nTimeMap.prototype.set = function(key, value, timestamp) {\n if (!this.map.has(key)) this.map.set(key, []);\n this.map.get(key)[timestamp] = value;\n};\n\nTimeMap.prototype.get = function(key, timestamp) {\n if (!this.map.has(key)) retu...
18
2
['JavaScript']
5
time-based-key-value-store
3 Solutions | Binary | Linear {fastest} | Tree | Easy to understand | 95% beat | Java
3-solutions-binary-linear-fastest-tree-e-60g6
Intuition\n\n1. As we need to find the values corresponding to a key: HashMap would be the choice\n2. We need to find those values whose timestampPrev <= times
nits2010
NORMAL
2019-09-14T11:18:54.250228+00:00
2019-09-14T11:21:05.523429+00:00
2,727
false
**Intuition**\n\n1. As we need to find the values corresponding to a key: `HashMap` would be the choice\n2. We need to find those values whose `timestampPrev <= timestamp`. i.e. means we need to store all the values of a key of different timestamp. Since we are looking `timestampPrev <= timestamp` then keeping those v...
17
0
['Binary Search', 'Tree']
2
time-based-key-value-store
Short python binary search solution
short-python-binary-search-solution-by-c-s3er
The idea is to have a map, with the values as a list with timestamp attached.\nFor get, its then a simple binary search in the list.\n\n\nfrom collections impor
Cubicon
NORMAL
2019-01-27T04:01:13.986104+00:00
2020-03-02T16:52:08.468038+00:00
5,220
false
The idea is to have a map, with the values as a list with timestamp attached.\nFor get, its then a simple binary search in the list.\n\n```\nfrom collections import defaultdict\nfrom bisect import bisect_right\n\nclass TimeMap:\n def __init__(self):\n self.ktimestamp = defaultdict(list)\n self.kv = def...
16
5
[]
9
time-based-key-value-store
Java TreeMap solution. Time O(logn), Space O(n)
java-treemap-solution-time-ologn-space-o-7ldz
A two dimensional hashmap. The second dimension is sorted. \n\n\n\nclass TimeMap {\n private static final String DEFAULT_VALUE = "";\n private final HashM
edickcoding
NORMAL
2021-09-12T23:06:59.889231+00:00
2021-09-12T23:06:59.889263+00:00
3,520
false
A two dimensional hashmap. The second dimension is sorted. \n\n\n```\nclass TimeMap {\n private static final String DEFAULT_VALUE = "";\n private final HashMap<String, TreeMap<Integer, String>> map;\n\n /** Initialize your data structure here. */\n public TimeMap() {\n map = new HashMap<>();\n }\n...
14
1
['Tree', 'Java']
2
time-based-key-value-store
Commented | Easy to UnderStand | Faster | 100% less memory | JavaScript Solution
commented-easy-to-understand-faster-100-majyd
Please do upvote, it motivates me to write more such posts\uD83D\uDE03\n\n\nTimeMap.prototype.set = function(key, value, timestamp) {\n let obj = this.obj;\n
mrmagician
NORMAL
2019-12-02T23:22:43.706595+00:00
2019-12-02T23:22:43.706649+00:00
2,034
false
**Please do upvote, it motivates me to write more such posts\uD83D\uDE03**\n\n```\nTimeMap.prototype.set = function(key, value, timestamp) {\n let obj = this.obj;\n if(!obj[key]){\n obj[key] = [];\n }\n obj[key].push([value, timestamp]); \n};\n\n\nTimeMap.prototype.get = function(key, timestamp) {\n...
14
1
['Binary Search', 'JavaScript']
1
time-based-key-value-store
Beats 99%✅ | O( log n )✅ | C++ (Step by step explanation)
beats-99-o-log-n-c-step-by-step-explanat-pffq
Intuition\nThe problem requires designing a data structure to store key-value pairs with associated timestamps and efficiently retrieve the value for a given ke
monster0Freason
NORMAL
2023-10-16T15:14:52.521892+00:00
2023-10-16T17:14:31.581561+00:00
1,058
false
# Intuition\nThe problem requires designing a data structure to store key-value pairs with associated timestamps and efficiently retrieve the value for a given key at a specific timestamp. To achieve this, we use an unordered_map to map keys to vectors of pairs, where each pair contains a value and a timestamp. The pri...
13
0
['Binary Search', 'C++']
2
time-based-key-value-store
Easy to read C++ solution, Binary search with hashMap
easy-to-read-c-solution-binary-search-wi-p6kk
\nclass TimeMap {\nprivate:\n unordered_map<string, vector<pair<string, int>>> map; // key, {value, timestamp}\n \n string searchVal(vector<pair<string
tinfu330
NORMAL
2021-11-03T16:04:50.699384+00:00
2021-11-03T16:09:50.384880+00:00
3,002
false
```\nclass TimeMap {\nprivate:\n unordered_map<string, vector<pair<string, int>>> map; // key, {value, timestamp}\n \n string searchVal(vector<pair<string, int>> &vec, const int &timestamp) {\n int low = 0;\n int high = vec.size() - 1;\n \n while (low <= high) {\n int mid...
12
0
['C', 'Binary Tree', 'C++']
3
time-based-key-value-store
Python Line BY Line Perfect Explanations - Fast & Well Commented(Using DefaultDict)
python-line-by-line-perfect-explanations-cz3i
```\nclass TimeMap:\n\n def init(self):\n #Declare Default Dictionary because we want to append [values,timestamp] to the key\n self.d = defaul
iamkshitij77
NORMAL
2021-05-12T12:52:16.979705+00:00
2021-05-12T12:52:16.979735+00:00
3,748
false
```\nclass TimeMap:\n\n def __init__(self):\n #Declare Default Dictionary because we want to append [values,timestamp] to the key\n self.d = defaultdict(list)\n """\n Initialize your data structure here.\n """\n \n\n def set(self, key: str, value: str, timestamp: int) -> ...
12
1
['Binary Tree', 'Python', 'Python3']
2
time-based-key-value-store
Javascript | Binary Search
javascript-binary-search-by-shekhar90-n33j
\n\nvar TimeMap = function () {\n this.map = new Map();\n};\n\nTimeMap.prototype.set = function (key, value, timestamp) {\n const map = this.map;\n if
shekhar90
NORMAL
2022-05-19T17:44:00.296401+00:00
2022-05-19T17:44:00.297445+00:00
1,304
false
```\n\nvar TimeMap = function () {\n this.map = new Map();\n};\n\nTimeMap.prototype.set = function (key, value, timestamp) {\n const map = this.map;\n if (!map.has(key)) map.set(key, []);\n map.get(key).push([value, timestamp]);\n};\n\nTimeMap.prototype.get = function (key, timestamp) {\n const arr = thi...
11
0
['Binary Tree', 'JavaScript']
0
time-based-key-value-store
Python solution
python-solution-by-aj_to_rescue-qm0p
Using Heaps\n\nfrom heapq import *\nclass TimeMap:\n\n def __init__(self):\n """\n Initialize your data structure here.\n """\n s
aj_to_rescue
NORMAL
2019-12-12T05:47:04.060278+00:00
2019-12-12T05:47:04.060316+00:00
1,642
false
Using Heaps\n```\nfrom heapq import *\nclass TimeMap:\n\n def __init__(self):\n """\n Initialize your data structure here.\n """\n self.times = collections.defaultdict(list)\n \n def set(self, key: str, value: str, timestamp: int) -> None:\n # -1 to make it a maxheap\n ...
11
0
[]
4
time-based-key-value-store
JAVA || 98 % Faster Code || HashMap
java-98-faster-code-hashmap-by-shivrasto-8rsy
\tPLEASE UPVOTE IF YOU LIKE.\n\nclass TimeMap {\n\n Map<String, List<Pair<String, Integer>>> map = new HashMap<>();\n public TimeMap() { }\n \n publ
shivrastogi
NORMAL
2022-10-06T04:45:17.807032+00:00
2022-10-06T04:45:17.807077+00:00
1,308
false
\tPLEASE UPVOTE IF YOU LIKE.\n```\nclass TimeMap {\n\n Map<String, List<Pair<String, Integer>>> map = new HashMap<>();\n public TimeMap() { }\n \n public void set(String key, String value, int timestamp) {\n if(!map.containsKey(key)) {\n map.put(key, new ArrayList<>());\n }\n ...
10
1
['Java']
1
time-based-key-value-store
Beats 99%✅ | O( log n )✅ | Python (Step by step explanation)
beats-99-o-log-n-python-step-by-step-exp-fj3w
Intuition\n Add a brief description of your first thoughts on how to solve this problem. \n\nThe problem involves designing a data structure that allows you to
monster0Freason
NORMAL
2023-10-16T13:20:54.175917+00:00
2023-10-16T17:15:31.871342+00:00
1,288
false
# Intuition\n<!-- Add a brief description of your first thoughts on how to solve this problem. -->\n\nThe problem involves designing a data structure that allows you to set values associated with keys at specific timestamps and retrieve the values at a specified timestamp for a given key. The intuition is to use a data...
9
0
['Binary Search', 'Python3']
2
time-based-key-value-store
C++ || Binary search in map of {string , vector}
c-binary-search-in-map-of-string-vector-cbv7r
\nclass TimeMap {\npublic:\n map<string, vector<pair<int,string>>> mp;\n// TimeMap() {\n \n// }\n \n void set(string key, string value,
ashay028
NORMAL
2022-10-06T12:18:52.732602+00:00
2022-10-06T12:18:52.732639+00:00
354
false
```\nclass TimeMap {\npublic:\n map<string, vector<pair<int,string>>> mp;\n// TimeMap() {\n \n// }\n \n void set(string key, string value, int timestamp) {\n mp[key].push_back({timestamp,value});\n }\n \n string get(string key, int timestamp) {\n string ans="";\n //...
9
0
[]
2
time-based-key-value-store
✅ C++ || Two approaches || Using Binary Search & Map
c-two-approaches-using-binary-search-map-8mag
Using Map\n\nclass TimeMap {\npublic:\n unordered_map<string, map<int, string, greater<int>>> mp;\n TimeMap() {}\n \n void set(string key, string va
mayank888k
NORMAL
2022-05-23T18:39:15.601568+00:00
2022-05-23T18:39:15.601596+00:00
1,394
false
**Using Map**\n```\nclass TimeMap {\npublic:\n unordered_map<string, map<int, string, greater<int>>> mp;\n TimeMap() {}\n \n void set(string key, string value, int timestamp) {\n mp[key][timestamp] = value;\n }\n \n string get(string key, int timestamp) {\n \n auto &v = mp[key]...
9
0
['C', 'Binary Tree', 'C++']
1
time-based-key-value-store
Java || 100% faster || easy solution || binary search
java-100-faster-easy-solution-binary-sea-mog1
\nclass TimeValue {\n String val;\n int timestamp;\n \n public TimeValue(String val, int time){\n this.val = val;\n timestamp = time;\
achyutav
NORMAL
2021-11-20T02:52:49.101325+00:00
2022-02-08T23:38:32.774548+00:00
2,482
false
```\nclass TimeValue {\n String val;\n int timestamp;\n \n public TimeValue(String val, int time){\n this.val = val;\n timestamp = time;\n }\n}\nclass TimeMap {\n Map<String, List<TimeValue>> map;\n public TimeMap() {\n map = new HashMap<>();\n }\n \n public void set(S...
9
0
['Binary Tree', 'Java']
4
time-based-key-value-store
Key Value Store logN solution with explanation
key-value-store-logn-solution-with-expla-ltg1
Intuition\n Describe your first thoughts on how to solve this problem. \nDesign Redis\n# Approach\nBasic set operations, the tricky part here is the get operati
samitmohan
NORMAL
2022-12-11T07:13:26.650916+00:00
2022-12-11T07:13:26.650968+00:00
1,700
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDesign Redis\n# Approach\nBasic set operations, the tricky part here is the get operation which hints at binary search (as it\'s based on increasing timestamp values)\nOther than that, use a simple hashmap to implement a KVS where key = k...
8
0
['Hash Table', 'Binary Search', 'Python3']
1
time-based-key-value-store
python 3 || binSearch || T/S: 99%/97%
python-3-binsearch-ts-9997-by-spaulding-bd2s
\nclass TimeMap:\n def __init__(self):\n\t\n self.values = defaultdict(list)\n self.stamps = defaultdict(list)\n \n def set(self, key: st
Spaulding_
NORMAL
2022-10-06T00:14:08.545901+00:00
2024-05-31T19:54:27.065195+00:00
370
false
```\nclass TimeMap:\n def __init__(self):\n\t\n self.values = defaultdict(list)\n self.stamps = defaultdict(list)\n \n def set(self, key: str, value: str, timestamp: int) -> None:\n\t\n self.values[key].append(value)\n self.stamps[key].append(timestamp)\n return\n \n ...
8
0
['Python']
0
time-based-key-value-store
[JS] Using HashMap and Binary Search
js-using-hashmap-and-binary-search-by-wi-to2v
\nclass TimeMap {\n constructor() { // O(1)\n this.map = new Map(); // SC: O(T)\n }\n set(key, value, timestamp) { // O(1)\n
wintryleo
NORMAL
2021-08-28T12:40:36.814630+00:00
2021-08-28T12:42:09.412427+00:00
1,569
false
```\nclass TimeMap {\n constructor() { // O(1)\n this.map = new Map(); // SC: O(T)\n }\n set(key, value, timestamp) { // O(1)\n const keyVals = this.map.has(key) ? this.map.get(key) : [];\n keyVals.push([timestamp, value]);\n this.map.set(key, keyVals);\n }\n ...
8
0
['Binary Tree', 'JavaScript']
3
time-based-key-value-store
c++, supper short, map and unordered_map
c-supper-short-map-and-unordered_map-by-bjb3g
\nclass TimeMap {\nprivate:\n unordered_map<string, map<int, string>> m;\npublic:\n /** Initialize your data structure here. */\n TimeMap() {\n
huawenli
NORMAL
2020-05-13T05:52:56.461467+00:00
2020-05-13T05:52:56.461505+00:00
771
false
```\nclass TimeMap {\nprivate:\n unordered_map<string, map<int, string>> m;\npublic:\n /** Initialize your data structure here. */\n TimeMap() {\n \n }\n \n void set(string key, string value, int timestamp) {\n m[key][timestamp] = value;\n }\n \n string get(string key, int times...
8
0
[]
3
time-based-key-value-store
Beats 91.26% java. Modified Binary Search Explanation with Pics
beats-9126-java-modified-binary-search-e-liu7
Intuition\n Describe your first thoughts on how to solve this problem. \nBinary search\n\nExplanation for the modified binary search:\n\n\n\n Conventionaly we p
dhanush_kannan_dk
NORMAL
2024-10-02T19:15:03.765439+00:00
2024-10-02T19:28:16.267285+00:00
949
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBinary search\n\nExplanation for the modified binary search:\n![leetcode.png](https://assets.leetcode.com/users/images/3d1ee98b-3c2a-47f4-aa62-c89b2404be40_1727897196.1514618.png)\n\n\n* Conventionaly we push the left to right.\n* When we...
7
0
['Java']
2
time-based-key-value-store
c++ || 3 line code || binary search in map of pair in 1 line
c-3-line-code-binary-search-in-map-of-pa-283d
\n\n# Code\n\nclass TimeMap {\npublic:\n map<pair<string , int> , string > mp;\n\n TimeMap() {}\n\n void set(string key, string val, int tt) { mp[{key
amankatiyar783597
NORMAL
2023-03-28T13:49:45.815922+00:00
2023-03-28T13:57:14.256099+00:00
1,087
false
\n\n# Code\n```\nclass TimeMap {\npublic:\n map<pair<string , int> , string > mp;\n\n TimeMap() {}\n\n void set(string key, string val, int tt) { mp[{key , tt}] = val; }\n\n string get(string key, int tt) {\n auto it = mp.lower_bound({key,tt});\n if(it != mp.end()) if((*it).first.first == key ...
7
1
['C++']
0
time-based-key-value-store
Python3 - HashMap and Binary Search Solution.
python3-hashmap-and-binary-search-soluti-g338
\nclass TimeMap:\n\n def __init__(self):\n self.s_v = {}\n self.s_t = {}\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n
yukkk
NORMAL
2022-10-06T15:56:10.259813+00:00
2022-10-06T15:56:10.259857+00:00
2,340
false
```\nclass TimeMap:\n\n def __init__(self):\n self.s_v = {}\n self.s_t = {}\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n self.s_v.setdefault(key, []).append(value)\n self.s_t.setdefault(key, []).append(timestamp)\n\n def get(self, key: str, timestamp: int) -> s...
7
0
['Binary Tree', 'Python', 'Python3']
0
time-based-key-value-store
Java || HashMap + TreeMap Solution
java-hashmap-treemap-solution-by-kadamyo-1rd8
\nclass TimeMap {\n HashMap<String,TreeMap<Integer,String>> hm;\n public TimeMap() {\n hm=new HashMap<>();\n }\n \n public void set(String
kadamyogesh7218
NORMAL
2022-10-06T05:37:41.531432+00:00
2022-10-06T05:37:41.531467+00:00
1,271
false
```\nclass TimeMap {\n HashMap<String,TreeMap<Integer,String>> hm;\n public TimeMap() {\n hm=new HashMap<>();\n }\n \n public void set(String key, String value, int timestamp) {\n if(!hm.containsKey(key)){\n TreeMap<Integer,String> hm2=new TreeMap<>();\n hm2.put(timest...
7
0
['Tree', 'Java']
2
time-based-key-value-store
[EXPLAINED] Using TypeScript, Runtime Beats 94.74%, Memory Beats 42.10%
explained-using-typescript-runtime-beats-ba2r
Intuition\nStore values with timestamps in sorted order for each key. Use binary search to efficiently find the most recent value before the queried timestamp.
r9n
NORMAL
2024-08-22T00:48:44.868857+00:00
2024-08-22T00:48:44.868878+00:00
423
false
# Intuition\nStore values with timestamps in sorted order for each key. Use binary search to efficiently find the most recent value before the queried timestamp. This ensures quick lookups and updates.\n\n# Approach\nData Storage: Use a Map where each key maps to a sorted list of timestamp-value pairs.\n\nInsertion: Ad...
6
0
['TypeScript']
1
time-based-key-value-store
Java | Hash map and Binary Search | Explained
java-hash-map-and-binary-search-explaine-xm0c
Intuition\nWe need to search values by key and timestamp.\nFirst of all let\'s bucket all relevant entires together by key, we will do this with a hash map.\n\n
nadaralp
NORMAL
2022-10-06T05:08:17.753261+00:00
2022-10-06T05:08:17.753305+00:00
386
false
# Intuition\nWe need to search values by `key` and `timestamp`.\nFirst of all let\'s bucket all relevant entires together by key, we will do this with a `hash map`.\n\nNow every key has many timestamps with values, we can have an array to represent that. Because the timestamp come in `increasing` order, the insert to o...
6
0
['Java']
0
time-based-key-value-store
JAVA || USING HASHMAP & UPPERBOUND
java-using-hashmap-upperbound-by-flyroko-r1hw
\n\n class pair{\n int x;\n String y;\n pair(int x1,String y1){\n x=x1;\n y=y1;\n }\n}\n \n\t class TimeMap {\n Map>
flyRoko123
NORMAL
2022-08-12T07:39:39.074898+00:00
2022-08-12T07:39:39.074927+00:00
172
false
\n\n class pair{\n int x;\n String y;\n pair(int x1,String y1){\n x=x1;\n y=y1;\n }\n}\n \n\t class TimeMap {\n Map<String,List<pair>> m;\n Map<Integer,String> m1;\n public TimeMap() {\n m=new HashMap<>();\n m1=new HashMap<>();\n }\n \n public ...
6
0
[]
0
time-based-key-value-store
Java TreeMap Solution
java-treemap-solution-by-ortez1-v6xg
\nclass TimeMap {\n Map<String, TreeMap<Integer, String>> map = new HashMap<>();\n\n public void set(String key, String value, int timestamp) {\n map.putIf
ortez1
NORMAL
2022-01-19T03:45:12.130419+00:00
2022-01-19T03:45:12.130454+00:00
616
false
```\nclass TimeMap {\n Map<String, TreeMap<Integer, String>> map = new HashMap<>();\n\n public void set(String key, String value, int timestamp) {\n map.putIfAbsent(key, new TreeMap<>());\n map.get(key).put(timestamp, value);\n }\n\n public String get(String key, int timestamp) {\n if (!map.containsKey(key...
6
0
['Java']
0
time-based-key-value-store
Map with Binary Search Approach || C++ Clean Code
map-with-binary-search-approach-c-clean-szvad
Code :\n\n\nclass TimeMap {\n\t// Map { key, vec[timestamp, value] }\n unordered_map<string,vector<pair<int, string>>> mp; \npublic: \n \n static bool
i_quasar
NORMAL
2021-10-10T15:27:45.332638+00:00
2021-10-10T15:27:45.332683+00:00
694
false
# Code :\n\n```\nclass TimeMap {\n\t// Map { key, vec[timestamp, value] }\n unordered_map<string,vector<pair<int, string>>> mp; \npublic: \n \n static bool compare(const int& val, const pair<int, string>& a) {\n return a.first > val;\n }\n\n TimeMap() {\n \n }\n \n void set(string ...
6
0
['C', 'Binary Tree']
2
time-based-key-value-store
[Python3/Python] Simple solution using bisect module.
python3python-simple-solution-using-bise-f8it
\nimport bisect\nfrom collections import defaultdict\n\nclass TimeMap:\n\n def __init__(self):\n self.values = defaultdict(list)\n self.timesta
ssshukla26
NORMAL
2021-08-29T03:30:18.446185+00:00
2021-08-29T03:30:18.446210+00:00
1,087
false
```\nimport bisect\nfrom collections import defaultdict\n\nclass TimeMap:\n\n def __init__(self):\n self.values = defaultdict(list)\n self.timestamps = defaultdict(list)\n return\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n self.values[key].append(value)\n ...
6
0
['Python', 'Python3']
1
time-based-key-value-store
simple python solution, beat 99.9%
simple-python-solution-beat-999-by-xiemi-6bcu
```\nclass TimeMap:\n\n def init(self):\n """\n Initialize your data structure here.\n """\n self.dct = {}\n\n def set(self, k
xiemian
NORMAL
2021-03-29T22:20:00.852627+00:00
2021-03-29T22:20:53.186062+00:00
298
false
```\nclass TimeMap:\n\n def __init__(self):\n """\n Initialize your data structure here.\n """\n self.dct = {}\n\n def set(self, key: str, value: str, timestamp: int) -> None:\n if key not in self.dct:\n self.dct[key] = [[timestamp], [value]]\n else:\n ...
6
0
[]
1
time-based-key-value-store
Java Solution Map with Binary Search and Python bisect
java-solution-map-with-binary-search-and-2k7y
Java\n\nclass TimeMap {\n class Tval{\n String val;\n int time;\n Tval(String x, int y){\n val = x; time = y; \n }\n
Big_Hustler
NORMAL
2020-04-27T17:27:09.282930+00:00
2024-01-03T16:13:00.229159+00:00
1,390
false
Java\n```\nclass TimeMap {\n class Tval{\n String val;\n int time;\n Tval(String x, int y){\n val = x; time = y; \n }\n }\n Map<String,ArrayList<Tval>> map;\n /** Initialize your data structure here. */\n public TimeMap() {\n map = new HashMap<>();\n }\n ...
6
0
['Binary Search', 'Java', 'Python3']
0
time-based-key-value-store
Concise HashMap with TreeMap solution in Java
concise-hashmap-with-treemap-solution-in-8ndu
\nclass TimeMap {\n HashMap<String, TreeMap<Integer, String>> timeMap;\n\n public TimeMap() {\n timeMap = new HashMap<String, TreeMap<Integer, Stri
hkolli123
NORMAL
2020-02-26T19:37:57.198687+00:00
2020-02-26T19:37:57.198741+00:00
594
false
```\nclass TimeMap {\n HashMap<String, TreeMap<Integer, String>> timeMap;\n\n public TimeMap() {\n timeMap = new HashMap<String, TreeMap<Integer, String>>();\n }\n \n public void set(String key, String value, int timestamp) {\n timeMap.putIfAbsent(key, new TreeMap<Integer, String>());\n ...
6
0
['Tree', 'Java']
0
time-based-key-value-store
💡JavasScrip Simple Solution w/ Explanation
javasscrip-simple-solution-w-explanation-ffcm
The idea\nfor every key, its value is a series timestamp and a value corresponds to that timestamp, we can store these two information into a array where the ar
aminick
NORMAL
2019-10-21T23:15:28.471769+00:00
2019-10-21T23:15:28.471824+00:00
768
false
#### The idea\nfor every key, its value is a series timestamp and a value corresponds to that timestamp, we can store these two information into a array where the array index is the timestamp. I know this is a bad idea but for this question it is accepected.\n\n``` javascript\nvar TimeMap = function() {\n this.map =...
6
1
['JavaScript']
1
time-based-key-value-store
Rust - BTreeMap + HashMap
rust-btreemap-hashmap-by-dcc-9x3n
It turned out to be slightly faster (~170ms vs ~250ms) to use HashMap<String, BTreeMap<i32, String>> over a BTreeMap<i32, HashMap<String, String>>.\n\nuse std::
dcc
NORMAL
2019-01-29T01:10:30.524321+00:00
2019-01-29T01:10:30.524389+00:00
744
false
It turned out to be slightly faster (~170ms vs ~250ms) to use ```HashMap<String, BTreeMap<i32, String>>``` over a ```BTreeMap<i32, HashMap<String, String>>```.\n```\nuse std::collections::{BTreeMap, HashMap};\n\nstruct TimeMap {\n tm : HashMap<String, BTreeMap<i32, String>>,\n}\n\nimpl TimeMap {\n fn new() -> Sel...
6
1
[]
3
time-based-key-value-store
4 Line solution with Hashmaps And Lowerbound O(logN) in c++
4-line-solution-with-hashmaps-and-lowerb-u2e7
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
vik_97
NORMAL
2024-03-06T20:27:30.130468+00:00
2024-03-06T20:27:30.130501+00:00
617
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
5
0
['Hash Table', 'String', 'Binary Search', 'C++']
1
time-based-key-value-store
[Python] ✅ || Easy Explanation - Mind Map Diagram || Walkthrough from LS - O(n) to BS - O(logn)
python-easy-explanation-mind-map-diagram-aape
Intuition\nWhen first approaching this problem, the key realization is that it closely resembles the task of finding the floor of a target value in a sorted lis
chitralpatil
NORMAL
2024-01-16T23:29:39.669880+00:00
2024-01-16T23:29:39.669899+00:00
772
false
# Intuition\nWhen first approaching this problem, the key realization is that it closely resembles the task of **finding the floor of a target value** in a sorted list, a classic binary search problem. If you\'re familiar with the concept of finding the floor in a binary search, or have solved similar problems, then yo...
5
0
['Hash Table', 'String', 'Binary Search', 'Design', 'Python3']
0
time-based-key-value-store
C++ vector pair solution Solution 389 ms
c-vector-pair-solution-solution-389-ms-b-pi7w
class TimeMap {\npublic:\n vector<pair< string, pair>> v;\n \n TimeMap() \n {\n \n }\n \n void set(string key, string value, int time
Paresh15
NORMAL
2022-10-06T17:20:04.848972+00:00
2022-10-06T17:20:04.849015+00:00
899
false
class TimeMap {\npublic:\n vector<pair< string, pair<string, int>>> v;\n \n TimeMap() \n {\n \n }\n \n void set(string key, string value, int timestamp) \n {\n pair<string, int> p = {value, timestamp};\n pair<string, pair<string, int> > p1 = {key, p};\n v.push_back(p1)...
5
0
[]
2
time-based-key-value-store
✅✅ Using Binary Search || Map of Vector of Pair
using-binary-search-map-of-vector-of-pai-l6mr
\nclass TimeMap {\npublic:\n // Unordered Map of string, vector of pairs\n unordered_map<string,vector<pair<int,string>>> mp;\n TimeMap() {\n \n
Arpit507
NORMAL
2022-10-06T14:12:33.167188+00:00
2022-10-22T06:28:35.101376+00:00
788
false
```\nclass TimeMap {\npublic:\n // Unordered Map of string, vector of pairs\n unordered_map<string,vector<pair<int,string>>> mp;\n TimeMap() {\n \n }\n \n void set(string key, string value, int timestamp) {\n mp[key].push_back({timestamp,value});\n }\n \n string get(string key, ...
5
0
['C', 'Binary Tree']
0
time-based-key-value-store
Java || Using HashMap, TreeMap || Easy Solution
java-using-hashmap-treemap-easy-solution-buun
IF YOU LIKE THE SOLUTION\nPLEASE MAKE SURE TO UPVOTE IT !\n\n\nclass TimeMap {\n \n // HashMap of key(String) corresponding of TreeMap<TimeStamp,Value>>\n
ashutosh_pandey
NORMAL
2022-10-06T08:48:28.655415+00:00
2022-10-06T08:48:28.655448+00:00
498
false
IF YOU LIKE THE SOLUTION\nPLEASE MAKE SURE TO UPVOTE IT !\n\n```\nclass TimeMap {\n \n // HashMap of key(String) corresponding of TreeMap<TimeStamp,Value>>\n HashMap<String,TreeMap<Integer,String>> map;\n \n public TimeMap() {\n map = new HashMap<String,TreeMap<Integer,String>>();\n }\n \n ...
5
0
['Tree', 'Java']
2