id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "struct envelope{\n int width;\n int height;\n};\nclass Solution {\npublic:\n int findCeil(vector<int>heights,int height){\n int l =0,r= heights.size()-1;\n while(l<r){\n int mid =l+(r-l)/2;\n if(heights[mid]>=height){\n r= mid;\n }\n ... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(vector<int>& a, vector<int>& b) {\n return (a[0] == b[0]) ? (a[1] > b[1]) : (a[0] < b[0]);\n }\n\n int fun(vector<int> v, int n) {\n int l = 0, r = v.size(), mid;\n while (l < r) {\n mid = l + (r - l) / 2;\n if... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": " bool sortcol(const vector<int>& v1, const vector<int>& v2)\n{\n if(v1[0]!=v2[0])return (v1[0] < v2[0]);\n return(v1[1] > v2[1]);\n}\nclass Solution {\npublic:\nint bins(vector<int> nums, int val){//найти первое большее\nint l=0,r=nums.size()-1,j;\nwhile(r-l && r-l-1){\n j=(l+r)/2;\n if(nums... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n class comp{\n public:\n bool operator()(const vector<int> &v1,const vector<int> &v2){\n if(v1[0] != v2[0])return v1[0] < v2[0];\n else return v1[1] > v2[1];\n }\n };\n int b_search(vector<int> a,int num){\n int start = 0... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\nstatic bool comp(vector<int>&a, vector<int>&b) {\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n return a[0]<b[0];\n}\nint bs(vector<int>dp, int l, int r, int t) {\n while(l<r) {\n int mid = l+(r-l)/2;\n if(dp[mid]>=t){\n r = mid;\n ... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Seg{\n private:\n int n; vector<int> t;\n void build(vector<int>& a, int v, int tl, int tr){\n if(tl==tr){\n t[v]=a[tl];\n return;\n }\n int tm=(tl+tr)/2;\n build(a,2*v,tl,tm); build(a,2*v+1,tm+1,tr);\n t[v]=max(t[2*v],t[2*v+1]);\n ... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n void update(int idx, vector<int> &tree, int li, int ri, int qIdx, int val) {\n if (ri < li || ri < qIdx || li > qIdx) return;\n if (li == ri) {\n tree[idx] = val;\n return;\n }\n int mid = (li+ri)/2;\n update((2*idx), t... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "bool cmp(vector<int> envelop1, vector<int> &envelop2){\n if(envelop1[0] == envelop2[0]){\n return envelop1.back() > envelop2.back();\n }\n return envelop1[0] < envelop2[0];\n}\n\nclass Solution {\npublic:\n int bSearch(vector<int> &ar, int target){\n int s = 0, e = ar.size()-1;\n\... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(envelopes.begin(), envelopes.end(), [](vector<int> &lhs, vector<int> rhs) {\n return lhs[0] < rhs[0] || (lhs[0] == rhs[0] && lhs[1] > rhs[1]);\n });\n\n vector<int> heights;\n int... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n bool static cmp(vector<int> a1, vector<int> &a2){\n if(a1[0] == a2[0]) return a1[1]> a2[1];\n\n return a1[0]<a2[0];\n }\n\n int maxEnvelopes(vector<vector<int>>& arr) {\n int n =arr.size();\n\n sort(arr.begin(),arr.end(),cmp);\n vecto... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n int n = envelopes.size();\n sort(envelopes.begin(), envelopes.end(), compare);\n vector<int> segTree(4 * 1e5, 0), lazy(4 * 1e5, 0);\n int ans = 1;\n for (int i = 0; i < envelopes.size(); i... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n int n = envelopes.size();\n vector<int> segTree(4 * 1e5, 0), lazy(4 * 1e5, 0);\n vector<vector<int>> buckets(1e5 + 1);\n for (int i = 0; i < n ; i++) {\n buckets[envelopes[i][0]].push_... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "#pragma GCC optimize(\"unroll-loops,O3,Ofast\") //even 10^8+ also works with this\n#pragma GCC target(\"avx2,avx,fma,bmi,bmi2,lzcnt,popcnt\")\ntypedef long long ll;\n \n#define pb push_back\n#define ppb pop_back\n#define ff first\n#define ss second\n#define rt return;\n#define set_bits(a) __builtin_popcoun... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\nprivate:\n bool binarySearch(int start, int end, vector<stack<int>>& stacks, int target) {\n if (start >= end) {\n return false;\n }\n int mid = (start + end) / 2;\n if (stacks[mid].top() == target) {\n return true;\n }\n ... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n const int inf = 1e9 + 20;\n int n = envelopes.size();\n\n sort(envelopes.begin(), envelopes.end(), cmp);\n\n vector<int> h(n + 1, 0);\n h[0] = inf;\n\n for (int i = 0; i < n; ++i){\... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(envelopes.begin(), envelopes.end(), [](auto a, auto b) {\n return a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]);\n });\n\n vector<int> lis{};\n for (int i = 0; i < envelopes.size()... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n static bool comparator(vector<int> a, vector<int> b) {\n if (a[0] == b[0]) {\n return a[1] > b[1];\n }\n \n return a[0] < b[0];\n }\n \n int maxEnvelopes(vector<vector<int>>& envelopes) {\n \n //sorted width in inc... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(envelopes.begin(),envelopes.end(),[](auto lhs,auto rhs){\n if(lhs[0]==rhs[0]){\n return lhs[1]>rhs[1];\n } \n return lhs[0]<rhs[0];\n });\n\n // retu... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n int n=envelopes.size();\n sort(envelopes.begin(),envelopes.end(),[&](vector<int>a,vector<int>b){\n if(a[0]==b[0])return a[1]>b[1];\n return a[0]<b[0];\n });\n vector<int>tem... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& a) {\n auto comp = [] (vector<int> f, vector<int> s) {\n if (f[0]==s[0]) {\n return f[1]>s[1];\n }\n return f[0]<s[0];\n };\n sort(a.begin(), a.end(), comp);\n in... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\nstatic bool cmp(vector<int>a,vector<int>b)\n{\nif(a[0]!=b[0])\n{\nreturn a[0]<b[0];\n}\nreturn a[1]>b[1];\n}\n int maxEnvelopes(vector<vector<int>>& e) {\n int n=e.size();\n vector<int>dp;\n sort(e.begin(),e.end(),cmp);\n dp.push_back(e[0][1]);\n ... |
354 | <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p>
<p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's... | 3 | {
"code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(envelopes.begin(),envelopes.end(),[](auto lhs,auto rhs){\n if(lhs[0]==rhs[0]){\n return lhs[1]>rhs[1];\n } \n return lhs[0]<rhs[0];\n });\n\n // retu... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 0 | {
"code": "int init = [] {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n std::ofstream out(\"user.out\");\n for (string str; getline(std::cin, str); out << \"\\n\") {\n if (str.size() <= 2) { // skip past empty lines\n out << 0;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 0 | {
"code": "int init = [] {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n std::ofstream out(\"user.out\");\n for (string str; getline(std::cin, str); out << \"\\n\") {\n if (str.size() <= 2) { // skip past empty lines\n out << 0;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 0 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int count[256] = {0};\n int l = 0;\n int r = 0;\n int ans = 0;\n\n while(r<s.length()){\n count[s[r]]++;\n\n while(count[s[r]]>1){\n count[s[l]]--;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 0 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.size()==0)return 0;\n // char c = \n vector<bool>present(2600,false);\n int i=0;\n int j=0;\n present[int(s[0])]=true;\n int ans=1;\n for(auto c:s){\n if(present... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string str) {\n if(str.size() == 0) return 0;\n unordered_map<char, int > ump;\n int longest = 0;\n int i = 0, j = 0;\n int best_i = 0, best_j = 0;\n\n while(i < str.size() && j < str.size() && i <= j){\n if(ump.find(str[j]) !... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n queue<char> q;\n unordered_set<char> st;\n int n = s.size(), max_length = 0;\n\n for (int i = 0;i < n;i++){\n if (st.find(s[i]) != st.end()){\n while(q.front() != s[i]){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\nprivate:\n int longestStartingFrom(const string& s, int start) {\n vector<bool> found(256, false);\n int l = 0;\n for (int i = start; i < s.length(); ++i) {\n if (found[s[i]]) {\n return l;\n }\n found[s[i]] = true;\n... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n=s.size();\n int i=0,j=0;\n string y=\"\";\n int ans=INT_MIN;\n unordered_map<char,int>mp;\n while(i<n and j<n){\n mp[s[j]]++;\n if(mp[s[j]]>1){\n st... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int ans = 0;\n int left = 0;\n for (int right = 0; right < s.length(); ++right) {\n while (left < right) {\n std::string subStr = s.substr(left, right - left);\n if (subSt... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool find(string s, int sz)\n {\n vector<int> check(256, 0);\n int cnt = 0;\n int i=0;\n for(; i<sz; i++)\n {\n if(check[s[i]-' ']==0)\n {\n cnt++;\n }\n check[s[i]-' ']++;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size();\n int l = 0,r = n+1;\n while(l < r-1)\n {\n int m = (l+r)/2;\n auto ok = [&](int m)->bool\n {\n map<char,int>mp;\n for(int i... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n string str1=\"\";\n for(int i=0;i<s.length();i++){\n string str=\"\";\n for(int j =i;j<s.length();j++){\n if (str.find(s[j]) == std::string::npos)\n str+=s[j];\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool check(string s, int l){\n map<char, int> mp;\n int n = s.length();\n for(int i =0; i<n; i++){\n if(i < l){\n mp[s[i]]++;\n }\n else{\n if(mp.size() == l)return true;\n mp[s... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\nint lengthOfLongestSubstring(std::string s) { //original inefficent solution to find the longest distinct substring in a string\n int i = 0;\n int j = 0;\n int max = 0;\n std::string substr;\n std::unordered_set<char> distinct;\n while (i != s.size()) {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.length()==0)\n {\n return 0;\n }\n unordered_map<int, int> mp;\n string temp=\"\";\n int maxi=0;\n for (int i=0; i<s.length(); i++)\n {\n if(mp.find(s... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int start=0,maxLen=0;\n string ans=\"\";\n string longestString;\n unordered_map<char,int> seen;\n\n for(int end=0;end<s.size();end++){\n char cur=s[end];\n ans+=cur;\n\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) \n {\n map <int, int> m;\n\n for(int i = 0; i < 256; i++)\n m[i] = -1;\n\n int l = 0, r = 0, maxlen = 0;\n\n while(r < s.size())\n {\n if(m[s[r]] != -1)\n {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n string newStr = \"\";\n bool inCurr = false;\n // >> looked up ** vectors vs arrays??\n vector<string> allStrs;\n int lastInst;\n for(int i = 0; i < s.size(); i++){\n inCurr = fals... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n // Sub Strings\n vector<string> ans;\n string sub = \"\";\n char prev = NULL;\n int counter = 0;\n\n // Itterate through string\n for (int i = 0; i<s.size() ; i++) {\n \n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int m=0,k=0;\n if(s.length()>1000){return k=95;}\n for(int i=0;i<s.length();i++){\n unordered_map<char,int>a;{\n for(int j=i;j<s.length();j++){\n if(a[s[j]]+1>1){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(const std::string& s) {\n std::vector<std::string> answers; // To store valid substrings\n std::string subString = \"\"; // Current substring being built\n \n for (char ch : s) {\n // Find if the current character is already in t... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n int hashArr[256] = {0};\n int maxlen = 0;\n\n for(int i=0;i<n;i++){\n vector<char> str;\n for(int j=i;j<n;j++){\n if(hashArr[s[j]] == 1) break;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if (s.empty()) return 0;\n vector<string> sol;\n sol.push_back({s[0]});\n \n for (int i = 1; i < s.size(); i++) {\n string current;\n int found = sol[i-1].find(string({s[i]}));... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if (s.empty()) return 0;\n vector<string> sol;\n sol.push_back({s[0]});\n \n for (int i = 1; i < s.size(); i++) {\n string current;\n int found = sol[i-1].find(string({s[i]}));... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int helper(string &s,int start,int end){\n for(int i = start;i<=end;i++){\n if(s[i] == s[end+1]){\n return i;\n }\n }\n return -1;\n }\n string solver(string &s, int start) {\n string ans = \"\";\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n struct sinfo {\n char ch{0};\n std::deque<int> seg = {};\n int last_i{0};\n void show() {\n std::string ss;\n for (auto i : seg) {\n ss += \" \" + std::to_string(i);\n }\n\n std::cout << \"... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n\n vector<vector<char>> v; // Changed int to char for storing characters\n\n for (int i = 0; i < s.size(); ++i) {\n vector<char> v1;\n\n for (int j = i; j < s.size(); ++j) {\n // Check if the ch... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n void printDeque(const deque<char>& s) {\n std::cout << \"Deque: \";\n for(auto c: s) {\n std::cout << c;\n }\n \n std::cout << std::endl;\n }\n \n bool isStringInside(const deque<char>& s, char nextChar) {\n for (a... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int ans = 0;\n int n = s.size();\n for(int i = 0; i < n; ++i)\n {\n vector<int> check(100);\n int j = i, cnt = 0;\n for(int x = 0; x < 100; ++x) check[x] = 0;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int l = 0;\n vector<int> cnt(10000, 0);\n int len = 0;\n for (int r = 0; r < s.size(); ++r) {\n cnt[s[r]]++;\n while (cnt[s[r]] > 1) {\n cnt[s[l++]]--;\n }\n... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "bool valid(vector<char> arr, char s){\n for(int i = 0 ; i < arr.size(); i++){\n if(arr[i] == s)\n return false;\n }\n return true;\n\n}\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n\n vector<char>* arr = new vector<char>;\n vector<int> sizes;\n\... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "bool valid(vector<char> arr, char s){\n for(int i = 0 ; i < arr.size(); i++){\n if(arr[i] == s)\n return false;\n }\n return true;\n\n}\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n //if(s == \"\"){return 0;}\n vector<char>* arr = new vector... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) \n {\n if(s.length() == 0)\n return 0;\n \n\n int finalMax = 0;\n\n vector<int> usedLetters;\n\n for(int i = 0; i < 127; i++)\n usedLe... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int ind, count =0, max=0;\n vector<int> ch(256, -1);\n if(s.length()==1) return 1;\n for(int i=0; i<s.length(); i++){\n //cout<<\"i= \"<<i<<endl;\n if(ch[s[i]]<0){\n //... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n\tstd::unordered_map<std::string, int> cache;\n int NumDuplicates(std::string s)\n {\n auto it = cache.find(s);\n if(it!=cache.end())\n return it->second;\n \n alignas(64)\n char lut[256];\n\n for(int i=0;i<256;i++)\... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n // size_t found = str.find(str1);\n // if (found != string::npos)\n int maxi=1;\n if(s.size()==0){return 0;}\n if(s.size()>=500){return 95;}\n for(int i=0; i<s.size(); i++){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "#include <queue>\n#include <string>\n#include <algorithm>\n\nclass Solution {\npublic:\n bool checkRepeat(const std::queue<char>& vec, char s) {\n std::queue<char> temp = vec;\n while (!temp.empty()) {\n if (temp.front() == s) return false;\n temp.pop();\n }\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool checkRepeat(const std::queue<char>& vec, char s) {\n std::queue<char> temp = vec;\n while (!temp.empty()) {\n if (temp.front() == s) return false;\n temp.pop();\n }\n return true;\n }\n\n int lengthOfLongestSubstrin... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\nprivate:\nbool find(queue<char>q,char x)\n{\n while(q.size())\n {\n if(q.front()!=x)\n q.pop();\n if(q.front()==x)\n return true;\n }\n return false;\n}\npublic:\n int lengthOfLongestSubstring(string s) {\n int len=0,curr=0;\n queue... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\nprivate:\nbool find(queue<char>q,char x)\n{\n while(q.size())\n {\n if(q.front()!=x)\n q.pop();\n if(q.front()==x)\n return true;\n }\n return false;\n}\npublic:\n int lengthOfLongestSubstring(string s) {\n int len=0,curr=0;\n queue... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) \n {\n if(s.size()==0)\n return 0;\n map<char,int>mp;\n map<char,int>::iterator it;\n int i,max=1;\n for(i=0;i<s.size();i++)\n {\n if(mp.find(s[i])==mp.end())\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) \n {\n if(s.size()==0)\n return 0;\n map<char,int>mp;\n map<char,int>::iterator it;\n int i,max=1;\n for(i=0;i<s.size();i++)\n {\n if(mp.find(s[i])==mp.end())\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n if (n == 0) return 0;\n for (int i = min(100, n); i >= 1; --i) {\n map<char, int> count;\n for (int k = 0; k < i; ++k) {\n count[s[k]] += 1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if (s.length() <= 1) {\n return s.length();\n }\n int res = 0;\n for (int i = 0; i < s.length(); i++) {\n for (int j = i; j < s.length(); j++) {\n // cout << res << end... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool hasRepeatingCharacters(string s)\n {\n unordered_map<char, int> count;\n\n for(auto c: s)\n {\n if(count.find(c) == count.end()) // if not found\n count[c] = 1;\n else\n return true;\n }\n... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool hasRepeatingCharacters(string s)\n {\n unordered_map<char, int> count;\n\n for(auto c: s)\n {\n if(count.find(c) == count.end()) // if not found\n count[c] = 1;\n else\n return true;\n }\n... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {int cnt=1;\n if(s==\"\")\n {return 0;}\n for(int i=0;i<s.length();i++)\n { unordered_map<char,int> m;\n string st=\"\";\n for(int j=i;j<s.length();j++)\n { if(s[i]<='z'&& s[i]>='a')... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {int cnt=1;\n if(s==\"\")\n {return 0;}\n for(int i=0;i<s.length();i++)\n { unordered_map<char,int> m;\n string st=\"\";\n for(int j=i;j<s.length();j++)\n { if(s[i]<='z'&& s[i]>='a')... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n=s.size();\n int m=0;\n for(int i=0;i<n;i++){\n vector<int>v(200,0);\n int c=0;\n for(int j=i;j<n;j++){\n if(v[s[j]]==0){\n v[s[j]]+=1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n=s.size();\n int m=0;\n for(int i=0;i<n;i++){\n vector<int>v(200,0);\n int c=0;\n for(int j=i;j<n;j++){\n if(v[s[j]]==0){\n v[s[j]]+=1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.length();\n if (n == 0) return 0;\n map<char, int> count;\n for (int i = min(n, 100); i >= 1; --i) {\n for (int j = 0; j < min(i, n); ++j) {\n count[s[j]] += 1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n if (s.length() <= 1){\n return s.length();\n } else if (s.length() > 1000){\n return 95;\n } else {\n int res = 1;\n\n for (int start_of_substring = 0 ; start... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size();\n vector pref(n + 1, vector<int>(200, 0));\n for(int i = 0; i < n; i++)\n {\n for(int j = 0; j < 200; j++)\n {\n pref[i + 1][j] = pref[i][j];\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n=s.length();\n if(n==0)return 0;\n vector<vector<int>>cnt(200,vector<int>(n+1,0));\n int ans=0;int largest=0;\n for(int i=1;i<=n;i++){\n int c=s[i-1];\n for(int j=0;j<200;... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n // if (s.size() > 95) s.resize(95);\n std::set<char> total_set(s.begin(), s.end());\n int max = 0;\n for (int i = 0; i < s.size(); i++) {\n if (s.size() - i < max) break;\n for (int j... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n vector<int> length(s.length());\n deque<char> subString(0);\n\n if (s.empty()) return 0;\n length[0] = 1;\n subString.push_back(s[0]);\n \n for (int i=1; i<s.length(); i++) {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\n bool isvalid(string s,int mid){\n for(int i=0;i<s.length()-mid+1;i++){\n map<char,int>m;\n // int r=\n for(int j=i;j<i+mid;j++){\n m[s[j]]++;\n }\n if(m.size()==mid){\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int count=0,maxi=0,index;\n for(int i =0;i<s.size();i++){\n vector<int> hash(257,0);\n for(int j =i;j<s.size();j++){\n index = s[j];\n \n if(hash[index]... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "\nconstexpr auto noneEqual(char symb)\n{\n return [=](char s)\n {\n return s == symb;\n };\n}\n\nclass Solution {\npublic:\n int lengthOfLongestSubstring(std::string s) {\n size_t counter{};\n for (size_t indx = 0; indx < s.size(); ++indx)\n {\n std::vecto... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.length() == 0)\n return 0;\n \n // Mega brute force method. \n // - Other ppl use sliding window, could be interesting to look into at further date (if I remember to LOL).\n int long... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n bool isRepeated(vector<int> in)\n {\n for(int i=0;i<in.size();i++)\n {\n if(in[i]>1)\n return true;\n }\n return false;\n }\n int lengthOfLongestSubstring(string s)\n {\n vector<int> chs(128,0);\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int maxLength = 0;\n for(int i=0; i<s.length(); i++){\n vector<int> hash(256);\n int length = 0;\n for(int j=i; j<s.length(); j++){\n int a = s[j];\n if... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string &s){\n int n = s.size();\n int ans = 0;\n for(int i=0;i<n;i++){\n vector<int> hash(256,0);\n for(int j=i;j<n;j++){\n if(hash[s[j]] == 1) break;\n ans = max(ans,j-i+1);... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int n = s.size(), max_len = INT_MIN;\n if (n == 0)\n return 0;\n \n for (int i = 0; i < n; i++) {\n vector<int> mp(256, 0);\n for (int j = i; j < n; j++) {\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int allSame(string s) {\n /*for (int i=0; i<s.size(); i++) {\n if (i<s.size()-1 && s[i] != s[i+1]) {\n return 0;\n }\n }*/\n set<char>x(s.begin(), s.end());\n if (x.size() == 1) {\n return 1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int allSame(string s) {\n /*for (int i=0; i<s.size(); i++) {\n if (i<s.size()-1 && s[i] != s[i+1]) {\n return 0;\n }\n }*/\n set<char>x(s.begin(), s.end());\n if (x.size() == 1) {\n return 1;\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\nprivate:\n int solve(string &s , int idx , vector<int> &dp){\n\n unordered_map<char,int> hash;\n if(dp[idx] != -1) return dp[idx]; \n\n int ct = 0;\n int ans = 0;\n\n for(int i=idx;i<s.size();i++){\n hash[s[i]]++;\n \n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int i=0;\n int maxi=1;\n int n=s.length();\n if(n==0)return 0;\n while(i!=n-1){\n int j=i+1;\n map<int,int>m;\n if(isalnum(s[i]))m[s[i]]++;\n else{\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int i=0;\n int maxi=1;\n int n=s.length();\n if(n==0)return 0;\n while(i!=n-1){\n int j=i+1;\n map<int,int>m;\n if(isalnum(s[i]))m[s[i]]++;\n else{\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int i=0;\n int maxi=1;\n int n=s.length();\n if(n==0)return 0;\n while(i!=n-1){\n int j=i+1;\n map<int,int>m;\n if(isalnum(s[i]))m[s[i]]++;\n else{\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n int result=0;\n for(int i=0;i<s.size();i++)\n {\n string temp=\"\";\n vector<int>ans(256,0);\n for(int j=i;j<s.size();j++)\n {\n if(ans[s[j]]==0)\n ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n int maxLen = 0;\n\n for (int i=0 ; i<s.size() ; i++) {\n vector<int> hash(256, 0);\n string subString = \"\";\n for (int j=i ; j<s.size() ; j++) {\n subString+=s... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "bool comp(string x1, string x2) { return x1.length() > x2.length(); }\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n vector<string> str_v;\n string cash = \"\";\n int i = 0, x = 0;\n while (i < s.length()) {\n if (cash.find(s[i]) >= cash.le... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "bool comp(string x1, string x2) { return x1.length() > x2.length(); }\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n vector<string> str_v;\n string cash = \"\";\n int i = 0, x = 0;\n while (i < s.length()) {\n if (cash.find(s[i]) >= cash.le... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n\n bool isValid(char ch,queue<char>q){\n while(!q.empty()){\n if(q.front() == ch){\n return false;\n }\n q.pop();\n }\n return true;\n \n }\n\n int lengthOfLongestSubstring(string s) {\n q... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "#include <iostream>\n#include <queue>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n queue<char> q; // Queue to store the current substring\n int max_length = 0;\n\n for (char c : s) {\n // Check if the ... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.length() == 0) {\n return 0;\n }\n vector<int> dp(s.length());\n dp[0] = 1;\n unordered_set<char> chars;\n chars.insert(s[0]);\n int max = 1;\n int newStart = 0;... |
3 | <p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "abcabcbb"
<strong>... | 3 | {
"code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n\n if(s.empty())\n {\n return 0;\n }\n unordered_map<int, int> map;\n priority_queue<int> pq;\n pq.push(0);\n int length = 0;\n\n for(int i = 0; i < s.size(); i++)\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.