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
smallest-subsequence-of-distinct-characters
show my thinking process
show-my-thinking-process-by-bupt_wc-oyz0
consider s = \'ecbacaba\', ans = \'eacb\'\nwhy the first letter ans is not \'a\'? since there are only one \'e\' and its index is smaller than the first \'a\'\n
bupt_wc
NORMAL
2019-06-09T04:05:57.619692+00:00
2019-06-09T04:05:57.619737+00:00
8,116
false
consider s = \'ecbacaba\', ans = \'eacb\'\nwhy the first letter ans is not \'a\'? since there are only one \'e\' and its index is smaller than the first \'a\'\nNow we find the key point!\n\nfor example, s = \'cdadabcc\', `s` contains `a, b, c, d`\nindex[\'a\'] = [2, 4]\nindex[\'b\'] = [5]\nindex[\'c\'] = [0, 6, 7]\nind...
111
3
[]
10
smallest-subsequence-of-distinct-characters
Easy C++ solution , explained
easy-c-solution-explained-by-ishankgupta-urvf
Here greedy approach is applied to solve the question.\nWe\'ll take the stack and a frequency vector and visited vector.\nIf the coming character is visted befo
ishankgupta1356
NORMAL
2020-10-11T11:53:00.064477+00:00
2020-10-11T11:53:00.064510+00:00
4,116
false
Here greedy approach is applied to solve the question.\nWe\'ll take the stack and a frequency vector and visited vector.\nIf the coming character is visted before then we\'ll just decrease its frequency and move on to next character in string.\nWe\'ll only fill stack in lexicographically order and when we encounter lex...
35
2
['Stack']
1
smallest-subsequence-of-distinct-characters
Java Solution using Stack
java-solution-using-stack-by-credit_card-qbak
\n public String smallestSubsequence(String s) {\n //character frequency\n int[] count = new int[26];\n for(char c : s.toCharArray()){\n
credit_card
NORMAL
2020-10-11T08:43:56.346847+00:00
2020-10-11T08:47:09.283320+00:00
3,585
false
```\n public String smallestSubsequence(String s) {\n //character frequency\n int[] count = new int[26];\n for(char c : s.toCharArray()){\n count[c-\'a\']++;\n }\n //to keep track of visited character so that we don\'t use them if present in answer\n boolean[] vis...
27
2
['Stack', 'Java']
2
smallest-subsequence-of-distinct-characters
Python solution
python-solution-by-grter2-dr68
Time complexity = O(26 * n) = O(n)\nThe idea is to keep track of last index of each character and use it to check if we can pop the character on top of the sta
grter2
NORMAL
2019-06-09T04:06:25.692812+00:00
2019-06-11T04:43:58.568461+00:00
2,496
false
Time complexity = O(26 * n) = O(n)\nThe idea is to keep track of last index of each character and use it to check if we can pop the character on top of the stack.\n```\nclass Solution(object):\n def smallestSubsequence(self, text):\n """\n :type text: str\n :rtype: str\n """\n las...
26
0
[]
4
smallest-subsequence-of-distinct-characters
[c++][Runtime: 0 ms, faster than 100.00%][easy understanding]
cruntime-0-ms-faster-than-10000easy-unde-rcer
\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n stack<char> st;\n\t\t//visited will contain if s[i] is present in current resul
rajat_gupta_
NORMAL
2020-10-16T17:57:38.183672+00:00
2020-10-16T17:57:38.183716+00:00
1,773
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n stack<char> st;\n\t\t//visited will contain if s[i] is present in current result Stack\n vector<int> visited(26,0),cnt(26,0);\n for(int i=0;i<s.size();i++) cnt[s[i]-\'a\']++; //count the number of occurences of s[i]\n ...
22
0
['Stack', 'C']
3
smallest-subsequence-of-distinct-characters
C++ double 100% greedy with explanations
c-double-100-greedy-with-explanations-by-l353
we first count the occurance of each letter\n2. loop throught the given string again\n\ta. if current char if less than the back of our current result, and ther
mrquin
NORMAL
2019-06-09T05:34:49.740403+00:00
2019-06-09T05:34:49.740431+00:00
2,059
false
1. we first count the occurance of each letter\n2. loop throught the given string again\n\ta. if current char if less than the back of our current result, and there are more same letter as current back, we pop the back of current result.\n3. use another vector to remember if any letter has been used already, so we use ...
18
1
[]
4
smallest-subsequence-of-distinct-characters
Stack || Java || Easy Approach with explanation
stack-java-easy-approach-with-explanatio-svjr
\nclass Solution\n{//T->O(n) , S->O(n)\n public String smallestSubsequenceString s)\n {\n Stack<Character> stack=new Stack<>();//for storing the ch
swapnilGhosh
NORMAL
2021-06-27T06:39:27.259903+00:00
2021-06-27T06:39:27.259939+00:00
1,637
false
```\nclass Solution\n{//T->O(n) , S->O(n)\n public String smallestSubsequenceString s)\n {\n Stack<Character> stack=new Stack<>();//for storing the character in lexiographical orer\n int[] freq=new int[26];//for calculating the frequency of the alphabet \n boolean[] exists=new boolean[26];//a...
16
0
['Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
Java monotonic increasing stack solution
java-monotonic-increasing-stack-solution-23ea
This approach is remembering the frequency in the string, and using a monotonic increasing stack to make sure the char in the stack is monotonic increasing in l
samhan616
NORMAL
2019-06-09T04:21:12.786163+00:00
2019-06-09T06:04:43.005421+00:00
2,288
false
This approach is remembering the frequency in the string, and using a monotonic increasing stack to make sure the char in the stack is monotonic increasing in lexicographical order.\n```\nclass Solution {\n public String smallestSubsequence(String text) {\n\t\tchar[] arr = text.toCharArray();\n \n\t\tMap<Char...
15
2
[]
6
smallest-subsequence-of-distinct-characters
Python stack
python-stack-by-venkat8096-jhg1
\n# C \u2B55 D E \u262F\nclass Solution:\n def removeDuplicateLetters(self, s: str) -> str:\n d = Counter(s)\n visited = set()\n stack =
venkat8096
NORMAL
2020-10-11T09:55:07.651521+00:00
2020-10-11T10:06:31.490848+00:00
2,702
false
```\n# C \u2B55 D E \u262F\nclass Solution:\n def removeDuplicateLetters(self, s: str) -> str:\n d = Counter(s)\n visited = set()\n stack = []\n for i in range(len(s)):\n d[s[i]] -= 1\n if s[i] not in visited:\n while stack and stack[-1] > s[i] and d[s...
11
0
['Stack', 'Python', 'Python3']
0
smallest-subsequence-of-distinct-characters
O(1) Creative Solution | Beats 100% | 🥁
o1-creative-solution-beats-100-by-dar8gf-m1ta
Intuition & ApproachI'm the rock band drummer, and I took a creative approach to writing code. It's also one of my first programs ever. I was also drunk, but I
dar8gFIvMs
NORMAL
2025-01-28T21:04:42.787688+00:00
2025-01-28T21:04:42.787688+00:00
334
false
# Intuition & Approach I'm the rock band drummer, and I took a creative approach to writing code. It's also one of my first programs ever. I was also drunk, but I sobered up while writing this ;) <!-- Describe your first thoughts on how to solve this problem. --> # Complexity - **Time complexity:$$O(1)$$** <!-- Add yo...
10
0
['Python3']
5
smallest-subsequence-of-distinct-characters
[java] [stack] [map] [4ms]
java-stack-map-4ms-by-trevor-akshay-s3zc
```\nclass Solution {\n public String smallestSubsequence(String s) {\n \n Deque stack = new LinkedList<>();\n Map freq = new HashMap<>();\n
trevor-akshay
NORMAL
2021-02-13T05:23:10.898284+00:00
2021-02-13T05:23:10.898330+00:00
735
false
```\nclass Solution {\n public String smallestSubsequence(String s) {\n \n Deque<Character> stack = new LinkedList<>();\n Map<Character,Integer> freq = new HashMap<>();\n for(char c : s.toCharArray())\n freq.put(c,freq.getOrDefault(c,0)+1);\n\n for(char c : s.toCharArray()){//abac...
7
0
['Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
Python Stack Solution Time: O(N) Space: O(1)
python-stack-solution-time-on-space-o1-b-1bgx
Thoughts on the problem: \n1). I feel like I\'ve seen this problem before. It\'s literally the same problem as 316. https://leetcode.com/problems/remove-duplica
rosemelon
NORMAL
2019-06-09T08:00:06.732700+00:00
2019-06-09T08:00:17.839741+00:00
766
false
Thoughts on the problem: \n1). I feel like I\'ve seen this problem before. It\'s literally the same problem as 316. https://leetcode.com/problems/remove-duplicate-letters/ Funny enough, that problem is labeled hard while this is labeled medium. Maybe there is difficulty deflation as more problems come out? You can lite...
7
0
[]
2
smallest-subsequence-of-distinct-characters
C++ faster than 100%, Map based
c-faster-than-100-map-based-by-welivefre-lcc8
Map based approach:\nThings to remember while adding or removing a character in the final string (fi)\nAdd the character if it is not present in the string till
welivefree
NORMAL
2020-10-11T08:15:59.393588+00:00
2020-10-11T08:15:59.393627+00:00
931
false
Map based approach:\nThings to remember while adding or removing a character in the final string (fi)\nAdd the character if it is not present in the string till now.\nRemove if:\n1. Their are more occurances of the same character ahead (Check using map)\n2. Next character in string s (s[i]) is greater than the last cha...
6
0
[]
0
smallest-subsequence-of-distinct-characters
Python: Easy! Simple Solution using Stack || Time O(n)
python-easy-simple-solution-using-stack-huvdn
\nclass Solution:\n def smallestSubsequence(self, text: str) -> str:\n countMap = collections.defaultdict(int)\n stack = []\n selected =
sameerkhurd
NORMAL
2020-09-01T07:17:09.843721+00:00
2020-09-01T07:17:09.843751+00:00
1,561
false
```\nclass Solution:\n def smallestSubsequence(self, text: str) -> str:\n countMap = collections.defaultdict(int)\n stack = []\n selected = set()\n\n for c in text:\n countMap[c] += 1\n\n for c in text:\n countMap[c] -= 1\n if c not in selected:\n ...
6
0
['Python', 'Python3']
1
smallest-subsequence-of-distinct-characters
[C++] Stack-based Solution Explained, 100% Time, ~50% Space
c-stack-based-solution-explained-100-tim-2oei
Now we have a tricky one to rein in, since we might be tempted to go for some approaches that would collapse once you factor in some specific scenarios.\n\nMy s
ajna
NORMAL
2020-10-12T22:55:07.038980+00:00
2020-10-12T22:55:07.039027+00:00
818
false
Now we have a tricky one to rein in, since we might be tempted to go for some approaches that would collapse once you factor in some specific scenarios.\n\nMy solution might not be the perfect one, but I found it to be rather understandable and, not secondarily, performing enough, so allow me to go into more detail abo...
5
0
['String', 'Stack', 'C', 'C++']
2
smallest-subsequence-of-distinct-characters
CPP | EASY | 100% BEATS TIME AND MEM | SMALL
cpp-easy-100-beats-time-and-mem-small-by-pgon
\nstring smallestSubsequence(string text) {\n\tstack<char> st;\n\tvector<int> last(256, 0), seen(256, 0);\n\tfor(int i = 0; i < text.size(); i++)\n\t\tlast[text
hidden13
NORMAL
2019-07-27T12:34:27.725538+00:00
2019-07-27T12:34:27.725576+00:00
1,525
false
```\nstring smallestSubsequence(string text) {\n\tstack<char> st;\n\tvector<int> last(256, 0), seen(256, 0);\n\tfor(int i = 0; i < text.size(); i++)\n\t\tlast[text[i]] = i;\n\tfor(int i = 0; i < text.size(); i++){\n\t\tif(seen[text[i]])\n\t\t\tcontinue;\n\n\t\twhile(st.size() and st.top() > text[i] and last[st.top()] >...
5
0
['Array', 'Stack', 'Greedy', 'C', 'C++']
0
smallest-subsequence-of-distinct-characters
Python stack solution with explanation
python-stack-solution-with-explanation-b-gqvz
The solution is exactly the same as for 316. Remove Duplicate Letters.\n\nSave the temporary result into a stack.\nThe stack properties:\n(1) stack can be split
otoc
NORMAL
2019-06-10T01:07:36.782966+00:00
2019-06-10T03:00:13.259116+00:00
591
false
The solution is exactly the same as for [316. Remove Duplicate Letters.](https://leetcode.com/problems/remove-duplicate-letters/discuss/308977/Python-stack-solution-with-explanation)\n\nSave the temporary result into a stack.\nThe stack properties:\n(1) stack can be splitted to several segments\n(2) for each segment, t...
5
0
[]
1
smallest-subsequence-of-distinct-characters
✅☑[C++] || Without Stack || EXPLAINED🔥
c-without-stack-explained-by-marksphilip-9gvj
PLEASE UPVOTE IF IT HELPED\n\n#### Same Approach in this question too: https://leetcode.com/problems/remove-duplicate-letters/solutions/4093499/c-without-stack-
MarkSPhilip31
NORMAL
2023-09-26T18:43:15.639244+00:00
2023-09-27T07:20:05.934946+00:00
516
false
# *PLEASE UPVOTE IF IT HELPED*\n\n#### **Same Approach in this question too:** https://leetcode.com/problems/remove-duplicate-letters/solutions/4093499/c-without-stack-explained/\n\n---\n\n# Approach\n\n***(Also explained in the code)***\n\n#### **Step-by-Step Explanation:**\n\n1. Initialize two vectors, `count` and `u...
4
0
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'C++']
1
smallest-subsequence-of-distinct-characters
C++ using bitmasking and stack with detailed explainatio
c-using-bitmasking-and-stack-with-detail-kuzk
\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n // to keep count of number of each characters in string\n vector<int> co
ishanrai05
NORMAL
2020-10-11T21:14:17.768380+00:00
2020-10-11T21:14:56.608843+00:00
335
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n // to keep count of number of each characters in string\n vector<int> count(26);\n \n // bit mask to mark the characters that are already present in the stack\n int visited=0;\n \n // we will us...
4
0
[]
1
smallest-subsequence-of-distinct-characters
Python and Java solution.
python-and-java-solution-by-aadesh_hemwa-an7s
Steps:\n1. a dictionary/map with Last occurance of each character in the String.\n2. a stack that will help us keep track of the last inserted Character.\n3. fo
aadesh_hemwani
NORMAL
2020-10-11T11:07:18.444090+00:00
2020-10-12T14:59:41.640698+00:00
477
false
**Steps:**\n1. a dictionary/map with Last occurance of each character in the String.\n2. a stack that will help us keep track of the last inserted Character.\n3. for each character, we check if we have pushed it into the stack earlier, we use a set for Fast Lookups.\n4. if the character is present in SET do nothing wit...
4
1
[]
1
smallest-subsequence-of-distinct-characters
1ms, beats 100% JAVA solution with explanation
1ms-beats-100-java-solution-with-explana-a4ru
\n// solution is pretty simple and straight forward\n// first we count the frequency of each char in the string\n// then we put each char of the string in the s
anishrajan25
NORMAL
2020-09-23T13:24:20.039530+00:00
2020-09-23T13:32:27.769168+00:00
639
false
```\n// solution is pretty simple and straight forward\n// first we count the frequency of each char in the string\n// then we put each char of the string in the string res(the string that we\'ll be returning)\n// if we find a char x (in text) that is smaller than the last char in our res string\n// then we remove the ...
4
2
['Java']
0
smallest-subsequence-of-distinct-characters
C++ Solution with Detailed Explanation
c-solution-with-detailed-explanation-by-etf6n
Problem is to remove duplicates and output a string with unique characters while maintaing the smallest(lexicographically) permutation of all possible subsequen
rootkonda
NORMAL
2020-05-21T14:25:34.192424+00:00
2020-05-21T14:25:34.192472+00:00
364
false
Problem is to remove duplicates and output a string with unique characters while maintaing the smallest(lexicographically) permutation of all possible subsequences of distinct characters.\n\n1. We have to just keep adding the unique characters to the answer and while adding them we have to check if the character to be ...
4
0
[]
1
smallest-subsequence-of-distinct-characters
python stack
python-stack-by-nightybear-qywg
python\nclass Solution:\n \'\'\'\n Time complexity : O(n)\n Space complexity : O(n)\n \'\'\'\n def smallestSubsequence(self, text: str) -> str:\n
nightybear
NORMAL
2020-05-17T08:14:00.518030+00:00
2020-05-17T08:14:00.518065+00:00
386
false
```python\nclass Solution:\n \'\'\'\n Time complexity : O(n)\n Space complexity : O(n)\n \'\'\'\n def smallestSubsequence(self, text: str) -> str:\n count = collections.Counter(text)\n visited, stack = set(), []\n \n for ch in text:\n count[ch] -= 1\n if ...
4
0
['Stack', 'Python3']
1
smallest-subsequence-of-distinct-characters
Basic Explanation
basic-explanation-by-be-humble-extn
\n/*\n Using Monotonic Increasing Stack\n \n Example : cdadabcc\n\t\n Character Count : \n c->3\n d->2\n a->2\n b->1\n \n\tIterating
be-humble
NORMAL
2020-03-16T17:34:34.522668+00:00
2020-03-16T17:36:40.180083+00:00
391
false
```\n/*\n Using Monotonic Increasing Stack\n \n Example : cdadabcc\n\t\n Character Count : \n c->3\n d->2\n a->2\n b->1\n \n\tIterating to the given input string one by one : \n\t(Popping element from the stack only when element freq. is greater than one)\n\t\n "c" : c \n "d" : c d\n ...
4
0
[]
1
smallest-subsequence-of-distinct-characters
Java | Stack | Greedy | O(n) Time and Memory
java-stack-greedy-on-time-and-memory-by-cvzzs
\nclass Solution {\n public String smallestSubsequence(String text) {\n StringBuilder sb = new StringBuilder(); \n Stack<Character> st = new St
tacoman
NORMAL
2019-09-29T06:52:19.441686+00:00
2019-09-29T06:52:19.441735+00:00
890
false
```\nclass Solution {\n public String smallestSubsequence(String text) {\n StringBuilder sb = new StringBuilder(); \n Stack<Character> st = new Stack<>();\n boolean[] visited = new boolean[26]; \n int[] counts = new int[26];\n for(char ch : text.toCharArray()) counts[ch-\'a\']++; \...
4
0
[]
0
smallest-subsequence-of-distinct-characters
Runtime Beats 3ms🔥 | 2 Solutions : Monotonic Stack | O(1) Space | 🔥Self Explanatory Comments🔥
runtime-beats-3ms-2-solutions-monotonic-f8666
\uD83D\uDE0A ~ \uD835\uDE52\uD835\uDE5E\uD835\uDE69\uD835\uDE5D \u2764\uFE0F \uD835\uDE57\uD835\uDE6E \uD835\uDE43\uD835\uDE5E\uD835\uDE67\uD835\uDE5A\uD835\uDE
hirenjoshi
NORMAL
2023-10-10T08:39:46.985854+00:00
2023-12-26T04:44:42.656051+00:00
368
false
\uD83D\uDE0A ~ \uD835\uDE52\uD835\uDE5E\uD835\uDE69\uD835\uDE5D \u2764\uFE0F \uD835\uDE57\uD835\uDE6E \uD835\uDE43\uD835\uDE5E\uD835\uDE67\uD835\uDE5A\uD835\uDE63\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n***Hey There It\'s Easy! Just Take A Look At The Code And Comments Within ...
3
0
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
✅EASY C++ SOLUTION using STACK✅
easy-c-solution-using-stack-by-2005115-ebho
PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT\n# CONNECT WITH ME\n### https://www.linkedin.com/in/pratay-nandy-9ba57b229/\n#### https://www.instagram.com/pratay_nand
2005115
NORMAL
2023-09-26T08:00:01.135297+00:00
2023-09-26T08:00:01.135321+00:00
741
false
# **PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT**\n# **CONNECT WITH ME**\n### **[https://www.linkedin.com/in/pratay-nandy-9ba57b229/]()**\n#### **[https://www.instagram.com/pratay_nandy/]()**\n\n# Approach\nThe provided C++ code is an implementation of the "Smallest Subsequence" problem. The goal of this problem is to rem...
3
0
['C++']
0
smallest-subsequence-of-distinct-characters
🏆O(N)🏆 || ✅Explained in Video✅ || 🔥Begineer friendly🔥
on-explained-in-video-begineer-friendly-pzzzn
Intuition\nVideo link for better understaning:\n\nhttps://youtu.be/rU5p0MRm5zU?si=Fy_mT3DgCZeT-X9i\n\n\n# Complexity\n- Time complexity:\n O(N)\n\n- Space comp
rajh_3399
NORMAL
2023-09-26T06:42:56.145954+00:00
2023-09-26T06:42:56.145973+00:00
198
false
# Intuition\n**Video link for better understaning:**\n\n[https://youtu.be/rU5p0MRm5zU?si=Fy_mT3DgCZeT-X9i]()\n\n\n# Complexity\n- Time complexity:\n O(N)\n\n- Space complexity:\n O(26)\n\n# Code\n```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n int n = s.size();\n string result; ...
3
0
['Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
C++ EASY AND CLEAN SOLUTION USING STACK
c-easy-and-clean-solution-using-stack-by-vh34
Code\n\nclass Solution {\npublic:\n string smallestSubsequence(string text) {\n vector<int> freq(26,0);\n vector<int> vis(26,0);\n stack
arpiii_7474
NORMAL
2023-08-02T06:13:40.297396+00:00
2023-08-02T06:13:40.297426+00:00
628
false
# Code\n```\nclass Solution {\npublic:\n string smallestSubsequence(string text) {\n vector<int> freq(26,0);\n vector<int> vis(26,0);\n stack<char> st;\n for(auto it:text) freq[it-\'a\']++;\n for(int i=0;i<text.size();i++){\n char c=text[i];\n freq[c-\'a\']--;...
3
0
['C++']
0
smallest-subsequence-of-distinct-characters
✅✅Faster || Easy To Understand || C++ Code
faster-easy-to-understand-c-code-by-__kr-el1y
Using Monotonic Stack\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n string smallestSubsequence(string str) {\n
__KR_SHANU_IITG
NORMAL
2022-10-05T19:10:21.763697+00:00
2022-10-05T19:10:21.763734+00:00
1,975
false
* ***Using Monotonic Stack***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n string smallestSubsequence(string str) {\n \n int n = str.size();\n \n // declare a stack, this will store the character in increasing order\n \n...
3
0
['Stack', 'C', 'C++']
1
smallest-subsequence-of-distinct-characters
C++ ||Explained || Stack || Greedy || Easy-Understanding
c-explained-stack-greedy-easy-understand-94ji
\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n \n // in string type of subsequence problem \n \n //stack
KR_SK_01_In
NORMAL
2022-10-05T18:40:14.880863+00:00
2022-10-05T18:40:14.880910+00:00
1,236
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n \n // in string type of subsequence problem \n \n //stack is always going to be a option \n \n //condition of popping -> curr character(s[i]) , popping character (stk.top())\n \n // i) po...
3
0
['Stack', 'Greedy', 'C', 'C++']
1
smallest-subsequence-of-distinct-characters
✅[C++] Using Stack | Monotonic for characters
c-using-stack-monotonic-for-characters-b-m4di
Concept Used : Monotonic Stack\nSince, we are asked to find a subsequence having all the characters and that too in lexicographical order, therefore stack and p
biT_Legion
NORMAL
2022-06-30T20:44:01.082942+00:00
2022-06-30T20:44:01.082968+00:00
476
false
#### Concept Used : Monotonic Stack\nSince, we are asked to find a subsequence having all the characters and that too in lexicographical order, therefore stack and priority queue should come to your mind. Now, we cannot maintain the relative order with priority queue since it places the smallest at top, but if we need ...
3
0
['Stack', 'C', 'Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
[C++] | Unordered Map | Easy Understanding
c-unordered-map-easy-understanding-by-pr-jnym
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n unordered_mapmp;\n \n for(int i=0;ivisited(26,false);\n
pranali_lahoti
NORMAL
2022-03-18T18:16:35.448401+00:00
2022-03-18T18:16:35.448451+00:00
569
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n unordered_map<char,int>mp;\n \n for(int i=0;i<s.length();i++)mp[s[i]]=i; //store last index of occurance\n \n vector<bool>visited(26,false);\n \n string result = "";\n for(int i=0;i<s.len...
3
0
['Array', 'C', 'C++']
0
smallest-subsequence-of-distinct-characters
JAVASCRIPT ||Effective Solution || Easy To Understand || With Explanation ||Beginner Friendly||
javascript-effective-solution-easy-to-un-rwbn
\nvar removeDuplicateLetters = function(s) {\n let stk = []; // Create a stack ie, an array\n for(let i = 0; i < s.length; i++){ //loop through the string
VaishnaviRachakonda
NORMAL
2022-03-18T12:46:07.586967+00:00
2022-03-18T12:46:07.587000+00:00
333
false
```\nvar removeDuplicateLetters = function(s) {\n let stk = []; // Create a stack ie, an array\n for(let i = 0; i < s.length; i++){ //loop through the string\n let letter = s[i]; \n if(stk.includes(letter)) //if the stk already contains the letter skip \n continue;\n while(stk[stk...
3
1
['Monotonic Stack', 'JavaScript']
1
smallest-subsequence-of-distinct-characters
Stack Solution 0(n)
stack-solution-0n-by-itz_pankaj-qpy9
From the input string, we are trying to greedily build a monotonically increasing result string. If the next character is smaller than the back of the result st
itz_pankaj
NORMAL
2021-05-29T06:37:46.325311+00:00
2021-05-29T06:37:46.325340+00:00
213
false
From the input string, we are trying to greedily build a monotonically increasing result string. If the next character is smaller than the back of the result string, we remove larger characters from the back providing there are more occurrences of that character later in the input string.\n\n**Time Complexity:**\nTime ...
3
0
[]
1
smallest-subsequence-of-distinct-characters
[Python3] stack O(N)
python3-stack-on-by-ye15-0gt2
Algo\nScan through s via a stack. If the current character is not in stack, we pop out characters in stack from the top that are larger than the current one and
ye15
NORMAL
2020-10-14T17:45:45.303188+00:00
2021-01-14T03:41:11.783117+00:00
367
false
**Algo**\nScan through `s` via a `stack`. If the current character is not in stack, we pop out characters in stack from the top that are larger than the current one and are still available later in `s`. \n\n**Implementation**\n```\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n loc = {x: i ...
3
0
['Python3']
1
smallest-subsequence-of-distinct-characters
Tail Recursion in Java
tail-recursion-in-java-by-namandeept-a259
Idea : Always consider the first character alphabetically which will give yes to the trailing output based on the content stored in the set, and append that cha
namandeept
NORMAL
2020-10-11T17:52:24.983665+00:00
2020-10-11T17:52:24.983702+00:00
454
false
**Idea** : Always consider the first character alphabetically which will give yes to the trailing output based on the content stored in the set, and append that character to the new String and remove that character from the present set. \nCode :\n```\nclass Solution {\n public boolean contains(Set<Character>set,Stri...
3
0
['Greedy', 'Recursion', 'Java']
1
smallest-subsequence-of-distinct-characters
C++, O(n) time complexity and O(1) memory
c-on-time-complexity-and-o1-memory-by-hu-men3
\nclass Solution {\npublic:\n string smallestSubsequence(string str) {\n string res;\n unordered_map<char, int> m;\n \n for (auto
huawenli
NORMAL
2020-09-04T03:32:32.540836+00:00
2020-09-04T03:32:32.540887+00:00
383
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string str) {\n string res;\n unordered_map<char, int> m;\n \n for (auto c: str) m[c]++;\n if (str.size() == m.size()) return str;\n \n for (int i = 0; i < str.size(); i++) {\n while (res.size() > ...
3
1
[]
0
smallest-subsequence-of-distinct-characters
Python solution
python-solution-by-hkm001-cgat
\n s = []\n for i,t in enumerate(text):\n if t not in s:\n while s and ord(t) <= ord(s[-1]) and s[-1] in text[i+1:]:\n
hkm001
NORMAL
2019-07-26T06:22:13.413645+00:00
2019-07-26T06:22:13.413676+00:00
338
false
```\n s = []\n for i,t in enumerate(text):\n if t not in s:\n while s and ord(t) <= ord(s[-1]) and s[-1] in text[i+1:]:\n s.pop()\n s.append(t)\n \n return \'\'.join(s)\n```
3
0
[]
0
smallest-subsequence-of-distinct-characters
An TLE backtrack solution
an-tle-backtrack-solution-by-unclemario-e4w2
Brute force solution with backtrack, spent an hour on this solution back in contest, finally did not worked out.\nThe algorithm works well except time complexit
unclemario
NORMAL
2019-06-09T19:58:18.955522+00:00
2019-06-09T20:00:45.932708+00:00
167
false
Brute force solution with backtrack, spent an hour on this solution back in contest, finally did not worked out.\nThe algorithm works well except time complexity is too high when input is long.\nAround half of cases passed.\nPut here to provide another idea.\n```\n\tString rst = "zzzzzzzzzzzzzzzzzzzzzzz";\n\n\tpublic S...
3
1
[]
0
smallest-subsequence-of-distinct-characters
Smallest Subsequence of Distinct Characters
smallest-subsequence-of-distinct-charact-easl
Complexity Time complexity: O(N) Space complexity: O(1) Code
Ansh1707
NORMAL
2025-04-06T21:54:17.359557+00:00
2025-04-06T21:54:17.359557+00:00
15
false
# Complexity - Time complexity: O(N) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python [] class Solution(object): def smallestSubsequence(self, s): """ :type s: str :rtype: str ""...
2
0
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'Python']
0
smallest-subsequence-of-distinct-characters
Problem BreakDown || Intuition Explained || Java
problem-breakdown-intuition-explained-ja-5x27
Similar solution on 316 leetcodeProblem BreakdownWhat is Lexicographically Smaller ?A string a is lexicographically smaller than a string b if in the first posi
dsuryaprakash89
NORMAL
2025-03-27T23:44:01.017462+00:00
2025-03-27T23:44:01.017462+00:00
59
false
## Similar solution on [316 leetcode](https://leetcode.com/problems/remove-duplicate-letters/solutions/6587779/problem-breakdown-intuition-explined-ja-wwdy/) # Problem Breakdown #### What is Lexicographically Smaller ? A string `a` is lexicographically smaller than a string b if in the first position where `a` and `...
2
0
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
🚀 Optimized Solution - Smallest Subsequence of Distinct Characters (Beats 100% in All Languages)
optimized-solution-smallest-subsequence-1x2bc
IntuitionThe goal is to find the smallest lexicographical order string by removing duplicate letters while maintaining the relative order of characters. To achi
Harshit___at___work
NORMAL
2025-03-02T05:58:28.711507+00:00
2025-03-02T05:59:11.612327+00:00
174
false
# Intuition The goal is to find the smallest lexicographical order string by removing duplicate letters while maintaining the relative order of characters. To achieve this, we use a **monotonic stack** approach to ensure that the resultant string is in sorted order and contains only unique letters. # Approach 1. **F...
2
0
['Hash Table', 'String', 'Stack', 'C++', 'Java', 'Python3']
0
smallest-subsequence-of-distinct-characters
Beginner Friendly Simple C++ Code
beginner-friendly-simple-c-code-by-mabdu-gdru
IntuitionTo find the lexicographically smallest subsequence of a string that contains all the distinct characters exactly once, we need to ensure two things:We
mAbdullah6829
NORMAL
2024-12-16T17:43:18.930404+00:00
2024-12-16T17:43:18.930404+00:00
245
false
# Intuition\nTo find the lexicographically smallest subsequence of a string that contains all the distinct characters exactly once, we need to ensure two things:\n\nWe must include every distinct character in the resulting subsequence.\nThe sequence must be in lexicographical order. To achieve this, we need to track th...
2
0
['C++']
0
smallest-subsequence-of-distinct-characters
EASY||4 STEPS DETAIL APPROACH || SAME AS 316
easy4-steps-detail-approach-same-as-316-j982h
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can come up with the idea that for lexicographic we need a stack maybe but here the
Abhishekkant135
NORMAL
2024-01-10T04:15:47.442182+00:00
2024-03-07T05:11:13.475289+00:00
512
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can come up with the idea that for lexicographic we need a stack maybe but here the problem arises in removing , how do you know that the elements you are removing from stack are present later in string , might be the case that they ar...
2
0
['Stack', 'Java']
2
smallest-subsequence-of-distinct-characters
Beats 99.33% 🔥|| Simple and Easy Approach Using string
beats-9933-simple-and-easy-approach-usin-qqjs
\n\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to find the lexicographically smallest subsequence of distinct char
rahulstrive
NORMAL
2024-01-01T11:15:16.400896+00:00
2024-01-01T11:15:16.400928+00:00
506
false
\n![image.png](https://assets.leetcode.com/users/images/d5101daf-e86c-433f-8a77-92c60565fa3e_1704106524.6674483.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to find the lexicographically smallest subsequence of distinct characters\n that appears in the same order...
2
0
['String', 'Monotonic Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
Solution with using map and set
solution-with-using-map-and-set-by-anime-t9to
\n\n# Code\n\nclass Solution {\n public String smallestSubsequence(String s) {\n Map<Character,Integer> map = new HashMap<>();\n for(int i = 0;
animesh23
NORMAL
2023-10-07T02:58:58.571381+00:00
2023-10-07T02:58:58.571409+00:00
986
false
\n\n# Code\n```\nclass Solution {\n public String smallestSubsequence(String s) {\n Map<Character,Integer> map = new HashMap<>();\n for(int i = 0;i < s.length();i++){\n map.put(s.charAt(i),map.getOrDefault(s.charAt(i),0) + 1);\n }\n Set<Character> set = new HashSet<>();\n ...
2
0
['Hash Table', 'Stack', 'Monotonic Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
Easy - Beginner Friendly || Stack || Hashmap || Monotonic Stack || Greedy || C++
easy-beginner-friendly-stack-hashmap-mon-coqg
Code\ncpp\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n unordered_map<char,int>last;\n unordered_map<char,bool>taken;\n
kushagra_2k24
NORMAL
2023-09-26T04:14:48.760477+00:00
2023-09-26T04:14:48.760504+00:00
722
false
# Code\n```cpp\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n unordered_map<char,int>last;\n unordered_map<char,bool>taken;\n stack<char>st;\n string ans="";\n for(int i=0;i<s.size();i++)\n last[s[i]]=i;\n for(int i=0;i<s.size();i++)\n ...
2
0
['Hash Table', 'String', 'Stack', 'Greedy', 'Monotonic Stack', 'C++']
1
smallest-subsequence-of-distinct-characters
C++ || Monotonic Stack || Easy Solution
c-monotonic-stack-easy-solution-by-saif2-i6l5
\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n
saif25
NORMAL
2023-07-09T15:28:27.747198+00:00
2023-07-09T15:28:27.747215+00:00
642
false
\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> vis(26,0);\n unordered_map<char,int> mp;\n for(auto ch : s) mp[ch]++;\n string ans="";\n for(int i=0;i<s.size();i++)...
2
0
['String', 'Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
JAVA Solution | Stack
java-solution-stack-by-sourin_bruh-nswk
Please upvote this solution as well as this :D\n\nclass Solution {\n public String smallestSubsequence(String s) {\n int n = s.length();\n bool
sourin_bruh
NORMAL
2022-10-10T18:27:56.667204+00:00
2022-10-10T18:29:55.004254+00:00
416
false
### Please upvote this solution as well as *[this](https://leetcode.com/problems/remove-duplicate-letters/discuss/2687478/JAVA-Solution-or-Stack)* :D\n```\nclass Solution {\n public String smallestSubsequence(String s) {\n int n = s.length();\n boolean[] visited = new boolean[26];\n int[] lastIn...
2
0
['Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
Easy Python solution in O(n) Time Complexity
easy-python-solution-in-on-time-complexi-fp0d
\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n s=list(s)\n d={}\n for i in range(len(s)):\n d[s[i]]=i\n
aastha1916
NORMAL
2022-10-04T06:53:06.669179+00:00
2022-10-04T06:53:06.669225+00:00
516
false
```\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n s=list(s)\n d={}\n for i in range(len(s)):\n d[s[i]]=i\n stack=[]\n for i in range(len(s)):\n if s[i] in stack:\n continue\n while len(stack)!=0 and d[stack[-1]]>i...
2
0
['Stack', 'Python']
1
smallest-subsequence-of-distinct-characters
100% FASTER 99.97% SPACE EFFICIENT EXPLAINED!!!
100-faster-9997-space-efficient-explaine-x7zi
PLS UPVOTE if you like the SOLUTION:)\n\nTHE QUESTION IS exactly same as REMOVE DUPLICATE LETTERS so you can try it also:)\n\nIDEA:-\n\n We use a STACK in the f
Ryuga8150
NORMAL
2022-09-08T19:11:58.485556+00:00
2022-09-08T19:11:58.485626+00:00
405
false
**PLS UPVOTE if you like the SOLUTION:)**\n\nTHE QUESTION IS exactly same as REMOVE DUPLICATE LETTERS so you can try it also:)\n\n**IDEA:-**\n\n* We use a STACK in the form of a string for this problem.\n* Also we use a vector of bool vec whose purpose is to determine which distinct elements are present in the stack cu...
2
0
['String', 'Stack', 'C']
0
smallest-subsequence-of-distinct-characters
Simple Python Solution || beats 98%
simple-python-solution-beats-98-by-b1601-9zio
\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n stack, seen = [], set()\n last = {c:idx for idx,c in enumerate(s)}\n
b160106
NORMAL
2022-09-01T10:25:09.945117+00:00
2022-09-01T10:25:09.945157+00:00
292
false
```\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n stack, seen = [], set()\n last = {c:idx for idx,c in enumerate(s)}\n for idx, char in enumerate(s):\n if char in seen:\n continue\n while stack and stack[-1] > char and idx < last[stack[-1...
2
0
['Python']
0
smallest-subsequence-of-distinct-characters
✅✅Faster || Easy To Understand || C++ Code
faster-easy-to-understand-c-code-by-__kr-g1zk
Using Stack && Unordered Map\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n string smallestSubsequence(string str)
__KR_SHANU_IITG
NORMAL
2022-08-05T09:51:45.314341+00:00
2022-08-05T09:51:45.314382+00:00
242
false
* ***Using Stack && Unordered Map***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n string smallestSubsequence(string str) {\n \n int n = str.size();\n \n // count store the frequency of element\n \n vector<int> cou...
2
0
['Stack', 'C', 'C++']
0
smallest-subsequence-of-distinct-characters
Python | Monotonic stack, Set, and Counter
python-monotonic-stack-set-and-counter-b-6myg
\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n\t\t# count how many of each character we have available in `s`\n charCount = Count
sr_vrd
NORMAL
2022-06-08T21:08:35.052317+00:00
2022-06-08T21:08:35.052344+00:00
591
false
```\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n\t\t# count how many of each character we have available in `s`\n charCount = Counter(s)\n charsInStack, charStack = set(), []\n \n for i, char in enumerate(s):\n\t\t\t# if char is not currently in charStack, we remove ...
2
0
['Monotonic Stack', 'Ordered Set', 'Python']
1
smallest-subsequence-of-distinct-characters
Without Stack
without-stack-by-shubhammishra115-0oy7
\n\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n unordered_map<char, int> map;\n for (int i = 0; i < s.size(); i++)\n
shubhammishra115
NORMAL
2022-03-18T17:13:06.449206+00:00
2022-03-18T17:13:06.449238+00:00
213
false
\n```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n unordered_map<char, int> map;\n for (int i = 0; i < s.size(); i++)\n map[s[i]]++;\n string ans = "";\n vector<bool> visited(26, false);\n for (int i = 0; i < s.size(); i++)\n {\n ...
2
0
['C', 'C++']
0
smallest-subsequence-of-distinct-characters
C++ || Code with Explanation || Why use Stack?
c-code-with-explanation-why-use-stack-by-l7b4
Brief Overview:\nThe aim is to find the lexicographically shortest subsequence having distinct letters.\nThere would exist various permutations of subsequences
anuragkiitb
NORMAL
2022-03-18T15:52:44.508041+00:00
2022-03-18T16:09:13.740606+00:00
113
false
**Brief Overview:**\nThe aim is to find the lexicographically shortest subsequence having distinct letters.\nThere would exist various permutations of subsequences that would have distinct letters. For instance if the String is "bcabc" , following are the subsequences possible: { "bca" , "cab" , "bac" ,"abc" }, out of...
2
0
['Stack']
0
smallest-subsequence-of-distinct-characters
java solution using stack with comments
java-solution-using-stack-with-comments-qsfvp
Detail can be found here->\nhttps://leetcode.com/problems/remove-duplicate-letters/discuss/1860486/java-solution-using-stack-with-comments\n\n\n public String s
kushguptacse
NORMAL
2022-03-18T11:44:10.985546+00:00
2022-03-18T11:47:22.828499+00:00
525
false
Detail can be found here->\nhttps://leetcode.com/problems/remove-duplicate-letters/discuss/1860486/java-solution-using-stack-with-comments\n\n```\n public String smallestSubsequence(String s) {\n\t\t// hold last index of every character.\n\t\tint[] lastIndex = new int[26];\n\t\t// visited array to store every char valu...
2
0
['Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
Simple C++ Solution || 100% faster ||
simple-c-solution-100-faster-by-vishwaje-b8ig
\n\nclass Solution {\n \npublic:\n \n string smallestSubsequence(string s) {\n \n vector<int> cand(256, 0);\n vector<bool> visited(
Vishwajeet_Pawar
NORMAL
2022-03-18T05:59:04.619664+00:00
2022-03-18T05:59:04.619710+00:00
337
false
```\n\nclass Solution {\n \npublic:\n \n string smallestSubsequence(string s) {\n \n vector<int> cand(256, 0);\n vector<bool> visited(256, false);\n\n for(auto&k:s)\n cand[k]++ ;\n \n string res = "0" ;\n \n for(auto&k:s)\n {\n ...
2
0
['C', 'C++']
0
smallest-subsequence-of-distinct-characters
JS & TS simple solution using stack
js-ts-simple-solution-using-stack-by-jin-sswv
This solution is based on this solution.\n\n\nfunction smallestSubsequence(s: string): string {\n const stack = [];\n \n for (let i = 0; i < s.length;
JinZihang
NORMAL
2022-03-18T03:37:49.278389+00:00
2022-03-18T03:37:49.278431+00:00
266
false
This solution is based on [this solution](http://leetcode.com/problems/remove-duplicate-letters/discuss/977608/Use-stack-to-solve-by-JS-94.89-fast-100-less-memory-with-explaination).\n\n```\nfunction smallestSubsequence(s: string): string {\n const stack = [];\n \n for (let i = 0; i < s.length; i++) {\n ...
2
0
['Stack', 'TypeScript', 'JavaScript']
0
smallest-subsequence-of-distinct-characters
Detailed explanation of logic with code
detailed-explanation-of-logic-with-code-lh3ux
The lexicographic part is the trouble maker in an otherwise simple problem.\nWe don\'t just want to remove the duplicates, but we want to remove duplicates in a
me_abhishek92
NORMAL
2021-12-08T09:45:05.649397+00:00
2021-12-08T09:45:05.649426+00:00
210
false
The lexicographic part is the trouble maker in an otherwise simple problem.\nWe don\'t just want to remove the duplicates, but we want to remove duplicates in a manner that the resultant string is lexicographically smallest.\n\nLet\'s try to get to the solution using an example.\n\ns = "bcabc"\nHere we have 4 possible ...
2
0
['Stack']
1
smallest-subsequence-of-distinct-characters
C++, 100% solution easy
c-100-solution-easy-by-abivilion-8f17
\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> freq(26,0);\n for(char c : s){\n freq[c-\'a\']++;
abivilion
NORMAL
2021-11-07T12:14:16.228025+00:00
2021-11-07T12:14:16.228050+00:00
355
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> freq(26,0);\n for(char c : s){\n freq[c-\'a\']++;\n }\n vector<int> visited(26, 0);\n \n string ret = "";\n \n for(int i = 0 ; i < s.length(); i++){\n \n...
2
0
['C', 'C++']
0
smallest-subsequence-of-distinct-characters
C++ solution || Greedy || Stack
c-solution-greedy-stack-by-ariyanlaskar-ib3y
\nstring smallestSubsequence(string s) {\n string ans="";\n map<char,bool>exists;\n map<char,int>freq;\n for(int i=0;i<s.length();i++
Ariyanlaskar
NORMAL
2021-08-25T05:13:35.981195+00:00
2021-08-25T05:13:35.981248+00:00
263
false
```\nstring smallestSubsequence(string s) {\n string ans="";\n map<char,bool>exists;\n map<char,int>freq;\n for(int i=0;i<s.length();i++){\n exists[s[i]]=false;\n freq[s[i]]++;\n }\n stack<char>st;\n st.push(s[0]);\n exists[s[0]]=true;\n ...
2
0
['Stack', 'Greedy']
0
smallest-subsequence-of-distinct-characters
100% easy c++
100-easy-c-by-anurag05683-hi5c
\n# if you like this code please do upvote \nint n=s.length();\n\tvector frequency(26,0);`` // datatype = int\n vector visited(26,false); // data type
anurag05683
NORMAL
2021-08-10T18:54:38.397950+00:00
2021-08-10T18:58:17.024001+00:00
284
false
\n# if you like this code please do upvote \nint n=s.length();\n\tvector<int> frequency(26,0);`` // datatype = int\n vector<int> visited(26,false); // data type = int \n stack<char> st; // char datatype\n \n for(int i=0;i<n;i++)\n frequency[s[i]-\'a\']++;\n \n fo...
2
0
['Stack', 'C']
0
smallest-subsequence-of-distinct-characters
[JavaScript] 10 lines solution (100%,80%)
javascript-10-lines-solution-10080-by-05-1436
Runtime: 72 ms, faster than 100.00% of JavaScript online submissions for Smallest Subsequence of Distinct Characters.\nMemory Usage: 39.4 MB, less than 80.00% o
0533806
NORMAL
2021-05-28T09:31:26.003811+00:00
2021-05-28T09:33:25.989005+00:00
385
false
Runtime: 72 ms, faster than 100.00% of JavaScript online submissions for Smallest Subsequence of Distinct Characters.\nMemory Usage: 39.4 MB, less than 80.00% of JavaScript online submissions for Smallest Subsequence of Distinct Characters.\n```\nvar smallestSubsequence = function(s) {\n let stack = [];\n for(let i...
2
1
['JavaScript']
0
smallest-subsequence-of-distinct-characters
python STACK O(N) time complexity O(K) space complexity easy to read
python-stack-on-time-complexity-ok-space-8hgb
\ndef smallestSubsequence(self, chars: str) -> str:\n current_string_chars = set()\n stack = []\n hm = Counter(chars)\n\n for char i
GSWE
NORMAL
2021-05-20T03:41:47.868551+00:00
2021-05-20T04:06:22.513718+00:00
111
false
```\ndef smallestSubsequence(self, chars: str) -> str:\n current_string_chars = set()\n stack = []\n hm = Counter(chars)\n\n for char in chars:\n while stack and char < stack[-1] and char not in current_string_chars and hm[stack[-1]] > 0:\n current_string_chars.remo...
2
0
[]
0
smallest-subsequence-of-distinct-characters
Easy C++ solution using Stack
easy-c-solution-using-stack-by-vaibhav27-hr7x
```\nstring smallestSubsequence(string str) {\n int lastIndex[26] = {0};\n bool charUsed[26] = {false};\n \n stack s;\n \n
vaibhav277
NORMAL
2021-02-20T10:41:10.982807+00:00
2021-02-20T10:41:10.982841+00:00
185
false
```\nstring smallestSubsequence(string str) {\n int lastIndex[26] = {0};\n bool charUsed[26] = {false};\n \n stack<char> s;\n \n for(int i=0;i<str.size();i++){\n lastIndex[str[i]-\'a\'] = i;\n }\n \n for(int i=0;i<str.size();i++){\n ch...
2
0
[]
0
smallest-subsequence-of-distinct-characters
C++ 0ms O(n) using string as stack
c-0ms-on-using-string-as-stack-by-rishab-shoe
\nstring smallestSubsequence(string text) {\n if(text.length()==0)\n return text;\n vector<int> freq(26,0);\n for(char &ch : tex
rishabhsp98
NORMAL
2020-08-03T06:40:58.917632+00:00
2020-08-04T12:45:09.205744+00:00
343
false
``` \nstring smallestSubsequence(string text) {\n if(text.length()==0)\n return text;\n vector<int> freq(26,0);\n for(char &ch : text)\n freq[ch-\'a\']++;\n \n vector<bool> seen(26,0);\n string ans="0";\n for(char &ch: text)\n {\n ...
2
1
['C']
0
smallest-subsequence-of-distinct-characters
Java O(n) O(1) (beats 100%)
java-on-o1-beats-100-by-rohitvish3094-d4s4
```\n// Solution - Time Complexity O(n) and space complexity O(1) (Here we have used arrays of length 26 making it of constant space)\n \n //if le
rohitvish3094
NORMAL
2020-07-16T05:39:34.189839+00:00
2020-07-16T05:39:34.189876+00:00
261
false
```\n// Solution - Time Complexity O(n) and space complexity O(1) (Here we have used arrays of length 26 making it of constant space)\n \n //if length of the string is 1 or 0 return that string\n if(s.length()<=1)\n return s;\n \n int len=s.length();\n // This will h...
2
0
[]
0
smallest-subsequence-of-distinct-characters
[PYTHON 3] Stacks | Dictionary | Easy to Read Solution
python-3-stacks-dictionary-easy-to-read-x4156
\nclass Solution:\n def smallestSubsequence(self, text: str) -> str:\n stack , counter , visited = [] , {} , {}\n for letter in text:\n
mohamedimranps
NORMAL
2020-06-14T16:33:43.617645+00:00
2020-06-14T16:33:43.617674+00:00
600
false
```\nclass Solution:\n def smallestSubsequence(self, text: str) -> str:\n stack , counter , visited = [] , {} , {}\n for letter in text:\n if letter not in visited:\n visited[letter] = False\n counter[letter] = 1\n else:\n counter[lette...
2
0
['Python3']
0
smallest-subsequence-of-distinct-characters
Python Solution w/ Counter and Stack
python-solution-w-counter-and-stack-by-s-hckm
\nclass Solution:\n def smallestSubsequence(self, text: str) -> str:\n count = Counter(text); visited = {}; st = [] # stack\n \n for cu
seank
NORMAL
2020-05-31T04:54:52.239285+00:00
2020-05-31T04:54:52.239317+00:00
207
false
```\nclass Solution:\n def smallestSubsequence(self, text: str) -> str:\n count = Counter(text); visited = {}; st = [] # stack\n \n for curr in text:\n count[curr] -= 1\n if curr in visited and visited[curr]: continue\n \n while st:\n ...
2
0
[]
1
smallest-subsequence-of-distinct-characters
C++ | Hash-map | Clean and readable
c-hash-map-clean-and-readable-by-wh0ami-lfbc
Intuition:\n1) Store frequency of characters.\n2) Start making a resultant string where in if we see that incoming character is smaller than the already added l
wh0ami
NORMAL
2020-05-20T18:27:07.799188+00:00
2020-05-21T09:01:33.636923+00:00
236
false
**Intuition:**\n1) Store frequency of characters.\n2) Start making a resultant string where in if we see that incoming character is smaller than the already added last one then we pop the last character in resultant string if there we can get them later.\n\n```\nclass Solution {\npublic:\n string smallestSubsequence...
2
0
[]
0
smallest-subsequence-of-distinct-characters
C++ Concise 100%
c-concise-100-by-ritikmishra-2l7v
class Solution {\npublic:\n string smallestSubsequence(string text) {\n \n string str="";\n vector count(26,0);\n vector used(26,
ritikmishra
NORMAL
2020-04-25T10:44:10.098975+00:00
2020-04-25T10:44:10.099028+00:00
435
false
class Solution {\npublic:\n string smallestSubsequence(string text) {\n \n string str="";\n vector<int> count(26,0);\n vector<bool> used(26,false);\n for (auto i:text)\n count[i-\'a\']++;\n \n for (auto i:text)\n {\n count[i-\'a\']...
2
0
['C', 'C++']
1
smallest-subsequence-of-distinct-characters
Easy Python Stack 100%-100%
easy-python-stack-100-100-by-rooch-j0n6
python\nclass Solution:\n def smallestSubsequence(self, S):\n indexLast = {S[i]: i for i in range(len(S))}\n stack = []\n for i in range
rooch
NORMAL
2020-04-02T15:57:58.312018+00:00
2020-04-02T15:57:58.312070+00:00
131
false
```python\nclass Solution:\n def smallestSubsequence(self, S):\n indexLast = {S[i]: i for i in range(len(S))}\n stack = []\n for i in range(len(S)):\n if S[i] in stack: continue\n\n while stack and stack[-1] > S[i] and i < indexLast[stack[-1]]:\n stack.pop()\...
2
1
[]
0
smallest-subsequence-of-distinct-characters
C++ 100% time and space solution
c-100-time-and-space-solution-by-jasperj-0ewj
\tclass Solution {\n\tpublic:\n\t\tstring smallestSubsequence(string text) {\n\t\t\tunordered_map m;\n\t\t\tfor(int i=0;i<text.size();i++){\n\t\t\t\tm[text[i]]=
jasperjoe
NORMAL
2020-03-10T12:34:16.933183+00:00
2020-03-10T12:34:16.933216+00:00
433
false
\tclass Solution {\n\tpublic:\n\t\tstring smallestSubsequence(string text) {\n\t\t\tunordered_map<char,int> m;\n\t\t\tfor(int i=0;i<text.size();i++){\n\t\t\t\tm[text[i]]=i;\n\t\t\t}\n\t\t\tstring ans;\n\t\t\tunordered_set<char> visited;\n\t\t\tfor(int i=0;i<text.size();i++){\n\t\t\t\twhile(!visited.count(text[i]) && !a...
2
0
['C', 'C++']
0
smallest-subsequence-of-distinct-characters
Python3 concise solution with stack beats 95%
python3-concise-solution-with-stack-beat-ab3o
\tclass Solution:\n\t\tdef smallestSubsequence(self, text: str) -> str: \n\t\t\tdict={}\n\t\t\tfor i in range(len(text)):\n\t\t\t\tdict[text[i]]=i\n\t\t\
jasperjoe
NORMAL
2019-06-16T00:22:54.683230+00:00
2019-06-16T00:22:54.683272+00:00
510
false
\tclass Solution:\n\t\tdef smallestSubsequence(self, text: str) -> str: \n\t\t\tdict={}\n\t\t\tfor i in range(len(text)):\n\t\t\t\tdict[text[i]]=i\n\t\t\tstack=[]\n\t\t\tfor i in range(len(text)):\n\t\t\t\tif text[i] in stack:\n\t\t\t\t\tcontinue\n\t\t\t\twhile stack and stack[-1]>text[i] and dict[stack[-1]]>i:\...
2
0
['Stack', 'Python3']
1
smallest-subsequence-of-distinct-characters
Java greedy solution
java-greedy-solution-by-demonmikalis-6hrh
We use greedy method here, first iterate all the characters in text, if we find the current one is smaller than already added ones, the push the current in the
demonmikalis
NORMAL
2019-06-14T00:04:09.564295+00:00
2019-06-14T00:04:09.564362+00:00
405
false
We use greedy method here, first iterate all the characters in text, if we find the current one is smaller than already added ones, the push the current in the front and pop back the already added\n```\n public String smallestSubsequence(String text) {\n\t\t int[] count = new int[26];\n\t\t for(int i=0;i<text.length();...
2
0
[]
0
smallest-subsequence-of-distinct-characters
O(N^2) solution with bitmasks
on2-solution-with-bitmasks-by-todor91-20jo
For each position save set with all characters after that position and\nsave set with needed characters. And in each iteration find the minimal\ncharacter that
todor91
NORMAL
2019-06-13T10:16:41.118651+00:00
2019-06-13T10:18:14.562655+00:00
259
false
For each position save set with all characters after that position and\nsave set with needed characters. And in each iteration find the minimal\ncharacter that has set with all needed characters and erase the needed character.\n```\n bool isSubset(int big, int small) {\n for (int i = 0; i < 30; ++i) {\n ...
2
0
[]
1
smallest-subsequence-of-distinct-characters
Java Solution - Greedy (1ms, 100%)
java-solution-greedy-1ms-100-by-extreman-6wka
First we find out the list of distinct chars with acs order.\nFor each char, if all other chars can be found after the char, then accept the char and remove it
extremania
NORMAL
2019-06-11T07:28:53.257344+00:00
2019-06-11T07:34:12.748997+00:00
242
false
First we find out the list of distinct chars with acs order.\nFor each char, if all other chars can be found after the char, then accept the char and remove it from the list, else try next char.\n\n```\nclass Solution {\n\tString check(String str, char c, List<Character> clist) {\n\t\tint idx = str.indexOf(c);\n\t\tStr...
2
0
[]
0
smallest-subsequence-of-distinct-characters
Java solution using stack with explanation
java-solution-using-stack-with-explanati-6kv7
Use a stack to maintain a running sequence of smallest subsequence. \n2. Iterate over the test string and check in the queue 1. if the character is visites befo
siddhantiitbmittal3
NORMAL
2019-06-09T21:53:44.239311+00:00
2019-06-10T02:22:30.403596+00:00
312
false
1. Use a stack to maintain a running sequence of smallest subsequence. \n2. Iterate over the test string and check in the queue 1. if the character is visites before 2. if the character is smaller than the head of the queue 3. if the head of the queue is has more occurence later.\n3. if all the above condition we remov...
2
0
[]
0
smallest-subsequence-of-distinct-characters
Simple Java Solution✅💻
simple-java-solution-by-rubiksolve-aoje
Code
RubikSolve
NORMAL
2025-04-03T16:01:39.352487+00:00
2025-04-03T16:01:39.352487+00:00
32
false
# Code ```java [] import java.util.*; class Solution { public String smallestSubsequence(String s) { Map<Character, Integer> freq = new HashMap<>(); Set<Character> set = new HashSet<>(); Stack<Character> stack = new Stack<>(); for (char ch : s.toCharArray()) { freq.put...
1
0
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'Java']
0
smallest-subsequence-of-distinct-characters
✅ 100% Accepted | Easy Approach | JAVA & C++ 💎
100-accepted-easy-approach-java-c-by-ora-wx3s
IntuitionIntuition that i got is that... That if i pick a character then what is the probability that the character will reappear in the future and it will give
Orangjustice777
NORMAL
2025-01-21T12:54:20.516790+00:00
2025-01-21T12:54:20.516790+00:00
192
false
![Screenshot 2025-01-21 at 5.56.12 PM.png](https://assets.leetcode.com/users/images/222672d4-ed1d-4a66-b175-14bb4612899d_1737462396.4398003.png) # Intuition <!-- Describe your first thoughts on how to solve this problem. --> Intuition that i got is that... That if i pick a character then what is the probability that t...
1
0
['Java']
0
smallest-subsequence-of-distinct-characters
same question as leetcode 316
same-question-as-leetcode-316-by-gayatri-vzy5
# Intuition \n\n\n\n\n\n# Complexity\n- Time complexity: O(N)\n\n\n- Space complexity: O(1)\n\n\n# Code\ncpp []\nclass Solution {\npublic:\n string smalles
Gayatrik_22
NORMAL
2024-10-09T06:23:03.586429+00:00
2024-10-09T06:23:03.586464+00:00
32
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)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space compl...
1
0
['String', 'Stack', 'Greedy', 'Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
beats 100% user with cpp
beats-100-user-with-cpp-by-sakshi_chaudh-uduc
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
sakshi_chaudhary1703
NORMAL
2024-09-20T16:46:59.841802+00:00
2024-09-20T16:46:59.841836+00:00
256
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['C++']
0
smallest-subsequence-of-distinct-characters
beats 100% user with cpp with TC explaination
beats-100-user-with-cpp-with-tc-explaina-fznb
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
gyuyul
NORMAL
2024-08-31T05:55:32.129491+00:00
2024-08-31T05:55:32.129524+00:00
99
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:\na bit of confusion that may arise is that there are nested for loop \nso time complexity should be quadratic.If this question arise...
1
0
['C++']
0
smallest-subsequence-of-distinct-characters
Searching wether the element we are removing can be removed or not?
searching-wether-the-element-we-are-remo-gvth
Writing the solution so that it stays in my find and for future reference.\n# Intuition\n Describe your first thoughts on how to solve this problem. \nMontonic
ronitroushan21102
NORMAL
2023-09-26T18:45:35.835991+00:00
2023-09-26T18:45:35.836012+00:00
89
false
Writing the solution so that it stays in my find and for future reference.\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMontonic stack idea comes into the mind when the core idea behind a monotonic stack is to maintain a stack of elements in such a way that the elements in the sta...
1
0
['C++']
0
smallest-subsequence-of-distinct-characters
Beats 100% C++ | Monotonic Stack
beats-100-c-monotonic-stack-by-aglakshya-myof
Approach\nWe have to choose the biggest element at as last as possible,\nfor that we keep a track of when every element is occuring last in the array.\nNow we h
aglakshya02
NORMAL
2023-09-26T16:00:31.759669+00:00
2023-09-26T16:08:56.168174+00:00
4
false
# Approach\nWe have to choose the biggest element at as last as possible,\nfor that we keep a track of when every element is occuring last in the array.\nNow we have to keep the order as monotonic as possible so we decide to use a monotonic stack.\nWhile pushing any element we check that - \n* it should not be already ...
1
0
['Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
🔥Beats 100% | EASY | Clean Code | Stack | C++ |
beats-100-easy-clean-code-stack-c-by-ant-hyh0
Code\n\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n stack<char> st;\n unordered_map<char, int> last_occ;\n unor
Antim_Sankalp
NORMAL
2023-09-26T09:48:20.565160+00:00
2023-09-26T09:48:20.565181+00:00
6
false
# Code\n```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n stack<char> st;\n unordered_map<char, int> last_occ;\n unordered_set<char> visit;\n\n for (int i = 0; i < s.size(); i++)\n {\n last_occ[s[i]] = i;\n }\n\n for (int i = 0; i < ...
1
0
['String', 'Stack', 'Monotonic Stack', 'C++']
0
smallest-subsequence-of-distinct-characters
C++ Easy 0ms faster || stack
c-easy-0ms-faster-stack-by-mdadnan28713-74au
\n\n# Code\n\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> last(26,-1);\n int n=s.length();\n for(in
mdadnan28713
NORMAL
2023-08-24T14:46:12.692721+00:00
2024-02-23T17:09:49.550019+00:00
14
false
\n\n# Code\n```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> last(26,-1);\n int n=s.length();\n for(int i=0;i<n;i++){\n last[s[i]-\'a\']=i;\n }\n vector<bool> visited(26,false);\n stack<char> st;\n for(int i=0;i<n;i++){\...
1
0
['Stack', 'Greedy', 'C++']
0
smallest-subsequence-of-distinct-characters
Easy Python Solution
easy-python-solution-by-rajatganguly-3sg6
```\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n d={v:k for k,v in enumerate(s)}\n stack=[]\n for k,v in enumerate
RajatGanguly
NORMAL
2022-11-08T10:10:12.798069+00:00
2022-11-08T10:10:12.798114+00:00
89
false
```\nclass Solution:\n def smallestSubsequence(self, s: str) -> str:\n d={v:k for k,v in enumerate(s)}\n stack=[]\n for k,v in enumerate(s):\n if v not in stack:\n while stack and stack[-1]>v and d[stack[-1]]>k:\n stack.pop()\n stack.ap...
1
0
['Stack', 'Python', 'Python3']
0
smallest-subsequence-of-distinct-characters
Python Easy Monotonic Stack
python-easy-monotonic-stack-by-anu1rag-52ix
Intuition\ncheckout https://leetcode.com/problems/remove-duplicate-letters/solutions/2666355/python-easy-stack-o-n/\n Describe your first thoughts on how to sol
anu1rag
NORMAL
2022-10-05T22:09:58.599780+00:00
2022-10-05T22:09:58.599819+00:00
53
false
# Intuition\ncheckout https://leetcode.com/problems/remove-duplicate-letters/solutions/2666355/python-easy-stack-o-n/\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 comple...
1
0
['Stack', 'Monotonic Stack', 'Python3']
0
smallest-subsequence-of-distinct-characters
C++ Approach Using Stack , Unorderd_map and Set
c-approach-using-stack-unorderd_map-and-pfbj8
The Below solution uses stack , unordered_map and set into its implementation\n\nstring smallestSubsequence(string s)\n {\n stack<char>st;\n se
geekyleetcoder
NORMAL
2022-10-03T18:57:51.172425+00:00
2022-10-03T18:57:51.172462+00:00
161
false
The Below solution uses stack , unordered_map and set into its implementation\n```\nstring smallestSubsequence(string s)\n {\n stack<char>st;\n set<char>se;\n unordered_map<char,int>mp;\n string res = "";\n int n = s.length();\n for(int i=0;i<n;i++)\n {\n m...
1
0
['Stack', 'Ordered Set', 'C++']
0
smallest-subsequence-of-distinct-characters
Simplest Fastest Quickest JAVA Solution via Stack all himself by Lord Noddy
simplest-fastest-quickest-java-solution-a2ls4
\nclass Solution {\n public String smallestSubsequence(String s) {\n int [] lastIndex=new int[26];\n for(int i=0;i<s.length();i++)\n
2001640100013
NORMAL
2022-09-28T06:53:55.838097+00:00
2022-09-28T06:53:55.838145+00:00
1,016
false
```\nclass Solution {\n public String smallestSubsequence(String s) {\n int [] lastIndex=new int[26];\n for(int i=0;i<s.length();i++)\n lastIndex[s.charAt(i)-\'a\'] = i;\n boolean [] seen=new boolean[26];\n Stack<Integer> st=new Stack<>();\n \n for(int i=0...
1
0
['Monotonic Stack', 'Java']
1
smallest-subsequence-of-distinct-characters
Easy Python solution with stack & set
easy-python-solution-with-stack-set-by-s-bqjb
\tclass Solution:\n\t\tdef smallestSubsequence(self, s: str) -> str:\n\t\t\tnew = {}\n\t\t\tfor i in range(len(s)):\n\t\t\t\tnew[s[i]]=i\n\t\t\tstak,seen=[],set
SaiManoj1234
NORMAL
2022-09-10T11:37:12.137308+00:00
2022-09-10T11:37:12.137336+00:00
496
false
\tclass Solution:\n\t\tdef smallestSubsequence(self, s: str) -> str:\n\t\t\tnew = {}\n\t\t\tfor i in range(len(s)):\n\t\t\t\tnew[s[i]]=i\n\t\t\tstak,seen=[],set()\n\t\t\tfor i in range(len(s)):\n\t\t\t\tif s[i] not in seen:\n\t\t\t\t\twhile stak and new[stak[-1]]>i and stak[-1]>s[i]:\n\t\t\t\t\t\tseen.remove(stak[-1])\...
1
0
[]
0
smallest-subsequence-of-distinct-characters
Smallest Subsequence of Distinct Characters (easiest explanation)
smallest-subsequence-of-distinct-charact-rzis
\nstring smallestSubsequence(string s) {\n// we will take the stack which will store the elements so that we can delete the \n// useless element
amandeep0210
NORMAL
2022-08-26T17:56:06.716859+00:00
2022-08-26T17:56:06.716916+00:00
116
false
```\nstring smallestSubsequence(string s) {\n// we will take the stack which will store the elements so that we can delete the \n// useless elements.\n stack<char> st;\n// now we will make a map which will store the frequency of each element\n unordered_map<char, int> freq;\n ...
1
0
[]
0
smallest-subsequence-of-distinct-characters
[C++] || MonoStack
c-monostack-by-rahul921-lemd
\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n string ans = "" ;\n int f[26] = {} , taken[26] = {} ;\n for(auto
rahul921
NORMAL
2022-08-24T16:48:08.453041+00:00
2022-08-24T16:48:08.453083+00:00
221
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n string ans = "" ;\n int f[26] = {} , taken[26] = {} ;\n for(auto &x : s) ++f[x-\'a\'] ;\n \n for(auto &x : s){\n --f[x-\'a\'] ;\n while(ans.size() and x < ans.back() and f[ans.back() - \...
1
0
['C']
0
smallest-subsequence-of-distinct-characters
beats 100% , idea is to think as per the frequency whether it can add to result or not
beats-100-idea-is-to-think-as-per-the-fr-whgm
\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> a(26,0);\n \n int u = 0;\n for(auto i: s)\n
mr_stark
NORMAL
2022-08-05T13:05:51.465385+00:00
2022-08-05T13:05:51.465418+00:00
34
false
```\nclass Solution {\npublic:\n string smallestSubsequence(string s) {\n vector<int> a(26,0);\n \n int u = 0;\n for(auto i: s)\n {\n a[i-\'a\']++;\n if(a[i-\'a\']==1)\n u++;\n }\n \n string ans = "";\n map<char,bool>...
1
0
[]
0
smallest-subsequence-of-distinct-characters
C++ solution using stack
c-solution-using-stack-by-ephemeral_live-pjqf
Dry Run\nINPUT - "cbacdcbc"\n\n\ni = 0\nans = \'c\'\nExplaination - Since c not considered\n\n\n\ni = 1\nans = \'b\'\nExplaination - Since c is present afterwar
ephemeral_lives
NORMAL
2022-07-11T08:26:47.541182+00:00
2022-07-11T08:26:47.541220+00:00
106
false
Dry Run\nINPUT - "cbacdcbc"\n\n```\ni = 0\nans = \'c\'\nExplaination - Since c not considered\n```\n\n```\ni = 1\nans = \'b\'\nExplaination - Since c is present afterwards, we can remove the c added before\n```\n\n```\ni = 2\nans = \'a\'\nExplaination - Since b is present afterwards, we can remove the b added before\n`...
1
0
['Stack', 'C']
1
product-sales-analysis-iii
SIMPLE | USING CTE & MIN() & Group By & Inner Join
simple-using-cte-min-group-by-inner-join-0owd
Complexity\nTime complexity: O(N)^2\nwhere N is the number of rows satisfying the conditions.\n\n# Space complexity: \nO(1)^2\n\n# Code\n\n# Write your MySQL qu
bamshankar130295
NORMAL
2024-04-16T07:33:04.064142+00:00
2024-04-16T07:33:04.064172+00:00
15,218
false
# Complexity\nTime complexity: O(N)^2\nwhere N is the number of rows satisfying the conditions.\n\n# Space complexity: \nO(1)^2\n\n# Code\n```\n# Write your MySQL query statement below\n\nWITH CTE AS (\n SELECT product_id, MIN(year) AS minyear FROM Sales \n GROUP BY product_id \n)\n\nSELECT s.product_id, s.year A...
74
0
['MySQL', 'MS SQL Server', 'PostgreSQL']
5
product-sales-analysis-iii
✅EASY MYSQL SOLUTION
easy-mysql-solution-by-swayam28-pcgn
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
swayam28
NORMAL
2024-08-16T08:00:34.739236+00:00
2024-08-16T08:00:34.739263+00:00
14,590
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)$$ --...
68
0
['MySQL']
6