id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n \n vector<long long >a(n+1,0);\n priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>>q;\n priority_queue<pair<long long,long long>,ve... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "#define ll long long\nstruct Meeting{\n int start;\n ll end;\n Meeting(int start,ll end){\n this->start=start;\n this->end=end;\n }\n};\nstruct Room{\n int roomId;\n ll end;\n Room(int roomId, ll end){\n this->roomId=roomId;\n this->e... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);cout.tie(NULL);\n }\n int mostBooked(int n, vector<vector<int>>& meetings) {\n set<int> availableRooms;\n for(int i = 0; i<n;i++)availableRooms.insert(i);\n vector<int> me... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "#define intt long long\nclass Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n sort(meetings.begin(),meetings.end());\n priority_queue<vector<intt>,vector<vector<intt>>,greater<vector<intt>>>pq1;\n priority_queue<intt,vector<intt>,greater<intt>>pq2;\n ... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& _meetings) {\n using pii = pair<long long, int>;\n priority_queue<pii, vector<pii>, greater<>> meetings;\n unordered_map<int, long long> start_count;\n for (auto & meeting : _meetings) {\n start... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n vector< int > ruc(n);\n sort( meetings.begin(), meetings.end() );\n multiset< int > availableRooms;\n set< pair<ll,int> > occupiedRooms;\n\n for( int i =0 ;i<n; ... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n sort(begin(meetings), end(meetings), [](auto &a, auto &b) {\n if(a[0] == b[0]) return a[1] < b[1];\n return a[0] < b[0];\n });\n auto comp = [](auto &a, auto &b) {\n ... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n // To store the next available time and booking count for each room\n vector<pair<long long, int>> rooms(n, {0, 0}); // {next available time, booking count}\n \n // Min-heap to sort meetings ... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n vector<vector<ll>>v;\n for(int i=0;i<meetings.size();i++){\n v.push_back({meetings[i][0],meetings[i][1],meetings[i][1]-meetings[i][0]});\n }\n sort(v.begin(),... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n sort(begin(meetings), end(meetings));\n vector<int> cnt(n, 0);\n using pii = pair<long long, int>;\n multiset<pii> q;\n set<int> free;\n for(int i = 0; i < n; ++i) free.insert(i... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& nums) {\n set<int> free_room;\n for(int i=0;i<n;i++){\n free_room.insert(i);\n }\n set<pair<long long int,int>> st;\n int i=0;\n long long int time=0;\n sort(nums.begin(),nu... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(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 }\n\n\n int mostBooked(int n, vector<vector<int>>& meetings) {\n sort(meetings.begin(),meetings.end());\n\n set... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n map<long long,long long> counts;\n set<pair<long long,long long>> times;\n set<long long> rooms;\n sort(meetings.begin(), meetings.end());\n \n for(int i=0;i<n;i++)rooms.insert(... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n vector<int> counter(n,0);\n \n sort(meetings.begin(), meetings.end());\n queue<vector<int>> meetingQ;\n for(auto x : meetings){\n meetingQ.push(x);\n }\n\n pri... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n vector<int> counter(n,0);\n \n sort(meetings.begin(), meetings.end());\n queue<vector<int>> meetingQ;\n for(auto x : meetings){\n meetingQ.push(x);\n }\n\n pri... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\n class Compare\n{\npublic:\n bool operator() (std::vector<long>& d, std::vector<long>& f)\n {\n if (d[1] > f[1]) {\n return true;\n }\n else if (d[1] == f[1]\n && d[2] > f[2]) {\n return true;\n }\n\n return... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) \n {\n // treat room as elements in pq\n // Step 1: sort meetings in terms of start time\n sort(meetings.begin(), meetings.end());\n int meeting_index = 0;\n\n // Step 2: establish n ro... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "#define ll long long\n\nclass ComparisonClass {\npublic:\n bool operator() (vector<ll> &v1, vector<ll> &v2){\n if(v1[0]==v2[0]){\n return v1[1]>=v2[1];\n }\n return v1[0]>=v2[0];\n }\n};\n\nclass Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meeti... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "#define ll long long\n#define vi vector<ll>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n priority_queue<ll, vi, greater<ll>>room_set;\n priority_queue<vi, vvi, greater<vi>>rejoin_set;\n for(int i=0;i<n;i++) room_set.... |
2,479 | <p>You are given an integer <code>n</code>. There are <code>n</code> rooms numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a 2D integer array <code>meetings</code> where <code>meetings[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means that a meeting will be held during the <strong>half-cl... | 3 | {
"code": "class Solution {\npublic:\n struct Compare {\n bool operator()(vector<long long>& a, vector<long long>& b) {\n if (a[0] == b[0]) {\n return a[1] > b[1];\n } else {\n return a[0] > b[0];\n }\n }\n };\n\n int mostBooked(int... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 0 | {
"code": "class Solution {\npublic:\n\tint partitionString(string& s) {\n\t\tint count = 0;\n\n\t\tbool used[26];\n\t\tfor (char c : s)\n\t\t{\n\t\t\tint index = c - 'a'; // Normalize to 0-26\n\t\t\tif (used[index])\n\t\t\t{\n\t\t\t\tmemset(used, 0, sizeof(used));\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\t\n\t\t\tused[index... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 0 | {
"code": "class Solution {\npublic:\n int partitionString(string& s) {\n int mask = 0;\n int count = 0;\n for (char c : s) {\n int bit = 1 << c - 'a';\n if (mask & bit) {\n count++;\n mask = 0;\n }\n mask |= bit;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 0 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<int> freq(26);\n int substrings = 1;\n for( int i = 0, j = 0; j < s.size(); j++ ){\n if ( freq[s[j] - 'a'] ){\n ++substrings;\n while( i < j) --freq[s[i++] - 'a'] ;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 0 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n // unordered_map <char, int> mp;\n // int count = 1;\n // int start = 0;\n // for(int i=0; i<s.length(); i++)\n // {\n // if(mp.find(s[i]) != mp.end())\n // {\n // if(mp[s[i]] >= start)... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_map<char, int> mp; // Create an unordered map to keep track of character counts\n int i = 0, j = 0, ans = 1, n = s.size(); // Initialize i and j as pointers, ans as the result, and n as the size of the string\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) \n {\n unordered_map<char, int> mp; \n int i = 0, j = 0, ans = 1, n = s.size(); \n while (j < n) \n {\n mp[s[j]]++; \n if (mp[s[j]] > 1) \n {\n while (i < j) mp[s[i++]... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<bool> a(26,0);\n auto b=a;\n int c=0;\n for(int i=0; i<s.size(); i++)\n {\n if(a[s[i]-'a'])\n {\n c++;\n a=b;\n }\n a[s[i]-'a'... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) \n {\n unordered_set<int> set(s.begin(), s.end());\n\n if(set.size() == 1) return s.length();\n if(set.size() == s.length()) return 1;\n\n cout << \"NOT RETURNED \\n\";\n\n int ps = 1;\n vector<int> h(... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "/*\nInput: s = \"abacaba\"\nOutput: 4\nExplanation:\nTwo possible partitions are (\"a\",\"ba\",\"cab\",\"a\") and (\"ab\",\"a\",\"ca\",\"ba\").\nIt can be shown that 4 is the minimum number of substrings needed.\n\ns = abacaba\nidx = 4\nletters = [26 * false] = {\"a\" : true, \"b\" : false, \"c\" : false}\... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<int> dp(s.size() + 1, 0);\n string curr = \"\";\n for (int i = 1; i <= s.size(); i++) {\n if (find(curr.begin(), curr.end(), s[i - 1]) != curr.end()) {\n curr = s[i - 1];\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n std::unordered_map<char,std::stack<int>> indices;\n for(int i=s.size()-1;i>=0;--i){\n indices[s[i]].push(i);\n }\n int m = 0;\n int count = 0;\n for(int i=0;i<s.size();++i){\n if(i==m){\n c... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int n = s.size();\n vector<int>vec(n,0);\n int head = -1;\n int tail =0 ;\n vector<int>cnt(26,0);\n\n while(tail < n){\n while(head+1 < n && cnt[s[head+1]-'a'] == 0){\n head++;... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(const string& s) {\n int out = 0;\n for(int i = 0; i < s.size();) {\n out++;\n vector<bool> a(24, 0);\n for(; i < s.size() && !a[s[i] - 'a']; i++) {\n a[s[i] - 'a'] = true;\n }\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n \n int partitionString(const string &s) {\n int ans = 0;\n int i = 0;\n while(i != s.size()){\n vector<bool> seen(26,false);\n for(; i < s.size(); ++i){\n int idx = s[i]-'a';\n if(seen[idx]){\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n \n int partitionString(const string &s) {\n int ans = 0;\n int i = 0;\n while(i != s.size()){\n vector<bool> seen(26,false);\n for(; i < s.size(); ++i){\n int idx = s[i]-'a';\n if(seen[idx]){\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int ind=0;\n int ans=0;\n while(ind<s.size())\n {\n vector<bool>visited(26,false);\n while(ind<s.size() && !visited[s[ind]-'a'])\n {\n visited[s[ind++]-'a']=true;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int subStringsCount = 0;\n for (int i = 0; i < size(s); ) {\n vector<bool> v(26,false);\n while(i < size(s) and v[s[i] - 'a'] == false) {\n v[s[i] - 'a'] = true;\n i++;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int res = 0;\n for(int i = 0, j; i < s.size(); ) {\n j = i;\n vector<bool> f(26, false);\n while(j < s.size()) {\n int ch = s[j] - 'a';\n if(f[ch]) break;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<bool> contained = vector<bool>(26, 0);\n int ss_count = 1;\n for (int i = 0; i < s.size(); i++) {\n if (contained[s[i]-'a']) {\n ss_count++;\n contained = vector<bool>(26, 0... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int ans = 0;\n int i =0;\n while(i < s.size())\n {\n vector<bool> track(26,false);\n while(i<s.size() && track[s[i]-'a'] != true)\n {\n track[s[i]-'a'] = true;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int ans = 0;\n int n = s.length();\n vector<bool> m(26,false);\n for(auto i = 0 ; i < n ; i ++){\n if(m[s[i] - 'a']){\n ans ++;\n vector<bool> v(26,false);\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int ans = 1;\n int n = s.length();\n vector<bool> m(26,false);\n for(auto i = 0 ; i < n ; i ++){\n if(m[s[i] - 'a']){\n ans ++;\n vector<bool> v(26,false);\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int out = 0;\n for(int i = 0; i < s.size();) {\n out++;\n vector<bool> a(256, 0);\n for(; i < s.size() && !a[s[i]]; i++) {\n a[s[i]] = true;\n }\n }\n retu... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base :: sync_with_stdio(false);\n }\n int partitionString(string s) {\n int index = 0;\n int n = s.size();\n int ans = 0;\n while(index < n){\n ans++;\n vector<bool>visited(256,0);\n w... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int n = s.size(), l = 0, r = 0, cntUnique = 0;\n vector<int> f(128);\n unordered_set<int> res;\n while (r < n) {\n f[s[r]]++;\n if (f[s[r]] == 1) {\n cntUnique++;\n }... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n std::list<std::string> l;\n std::string currentString;\n int pos = 0;\n for (auto i : s) {\n if (currentString.find(i) == std::string::npos) {\n currentString += i;\n } else {\n... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\nint partitionString(std::string s) {\n std::unordered_set<std::string> store;\n std::string temp;\n auto counter = 0;\n auto result = 0;\n while (counter < s.length()) {\n bool arr[26]={0};\n auto j=counter;\n fo... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n string temp=\"\";\n vector<string>ans;\n for(int i=0;i<s.size();i++){\n if(temp.find(s[i])!=string::npos){\n ans.push_back(temp);\n temp=\"\";\n }\n temp+=s[i... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n bool searchInCharSet(char &ch, string &str){\n int i=0;\n while(i < str.size()){\n if(str[i]==ch) return true;\n i++;\n } \n return false;\n }\n\n int partitionString(string s) {\n int n=s.size();\n // unor... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n bool present[26];\n for(int i = 0; i < 26; i++)\n present[i] = false;\n int k = 0;\n vector<string> words;\n string word = \"\";\n while(k < s.size()) {\n if(present[s[k] - 'a'])... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\nint partitionString(string s) {\n vector<string> ans;\n string a=\"\";\n unordered_map<char,int> mp;\n int i=0,j=0;\n while(i < s.length() && j < s.length())\n {\n mp[s[j]]++;\n if(mp[s[j]] > 1)\n {\n for (int k = i; k < j; k++)\n {\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n map<char, int> mp;\n vector<string> vs;\n string tmp = \"\";\n for (auto x : s) {\n mp[x]++;\n if (mp[x] > 1) {\n vs.push_back(tmp);\n for (auto y : tmp) mp[y] = ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<vector<char>> freq;\n vector<char> temp;\n for(int i = 0; i < s.length(); i++) {\n if(find(temp.begin(), temp.end(), s[i]) == temp.end()) {\n temp.push_back(s[i]);\n }\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<vector<char>> freq;\n vector<char> temp;\n for(int i = 0; i < s.length(); i++) {\n if(find(temp.begin(), temp.end(), s[i]) == temp.end()) {\n temp.push_back(s[i]);\n }\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n vector<vector<char>> freq;\n vector<char> temp;\n for(int i = 0; i < s.length(); i++) {\n if(find(temp.begin(), temp.end(), s[i]) == temp.end()) {\n temp.push_back(s[i]);\n }\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_map<char,int>m;\n int i=0,j=0;int n=s.size();\n int cnt=1;\n while(j<n){\n m[s[j]]++;\n if(m[s[j]]>1){\n while(i<j){\n m[s[i]]--;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int i=0,j=0,n=s.size(),ans=1;\n unordered_map<char,int> mpp;\n while(j<n){\n mpp[s[j]]++;\n if(mpp[s[j]]>1){\n ans++;\n while(i<j){\n mpp[s[i]]--;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> seen;\n int answer = 1;\n\n for ( char c : s ) {\n if ( seen.find(c) != seen.end() ) {\n seen = {c};\n answer += 1;\n }\n else {\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> seen_chars = {};\n int num_sub_str = 1;\n for (char c: s) {\n if (seen_chars.find(c) != seen_chars.end()) {\n num_sub_str += 1;\n seen_chars = {c};\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int saiz(const vector<string>& v){\n int n = v.size();\n int c=0;\n for(int i=0;i<n;++i){\n if(!v[i].empty()) c++;\n }\n return c;\n }\n bool IsIn(const string& s, char c){\n int n = s.size();\n for(int i = 0; ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(const string& s) {\n unordered_set<char> uniqueChars;\n int count = 1; // Initialize count to 1, since we'll always have at least one substring\n\n for (char c : s) {\n if (!uniqueChars.insert(c).second) {\n // Duplicate characte... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> set;\n int size = s.length();\n int partition = 0;\n for(int i = 0; i < size; i++) {\n int be_size = set.size();\n set.insert(s[i]);\n int af_size = set.size();\... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> setS;\n int count = 0;\n for (int i = 0; i < s.size(); i++)\n {\n if (setS.find(s[i]) != setS.end()){\n count++;\n setS.clear();\n }\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "#include <unordered_set>\n\nclass Solution {\npublic:\n int partitionString(string s) {\n int i = 0;\n\n unordered_set<char> charset;\n int str_count = 0;\n while(i<s.length()) {\n while(i<s.length() && !charset.contains(s[i])) {\n charset.insert(s[i... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> st;\n int cnt = 1;\n for(int i=0; i<s.size(); i++){\n if(st.find(s[i]) != st.end()){\n cnt++;\n st.clear();\n }\n st.insert(s[i]);\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 1 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> occurence;\n int result = 1;\n for(int i = 0;i<s.size();i++){\n if(occurence.count(s[i])>0){\n result++;\n occurence.clear();\n }\n occure... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int c=0;\n unordered_map<int ,int>map;\n for(int i=0;i< s.size();i++){\n map[s[i]]++;\n if(map[s[i]]==2){\n c++;\n i--;\n\n map.clear();\n }\n }return c+1;\n\n }\... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int n = s.size(), ans = 1;\n unordered_set<char> st = {s[0]};\n for (int i = 1; i < n; i++) {\n if (st.find(s[i]) != st.end()) {\n ans++;\n st.clear();\n }\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "#pragma GCC optimize (\"O3,unroll-loops\")\n#pragma GCC target (\"avx2,bmi,bmi2,lzcnt,popcnt\")\nclass Solution {\npublic:\n int partitionString(string s) {\n std::ios_base::sync_with_stdio(false);\n cin.tie(0);\n int count=0;\n unordered_set<char>st;\n for(int i=0;i<s... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<char, bool> check; // Do check.clear()\n string st;\n int n,ans=1;\n // void finder(int index){\n // if(index>=n) return;\n // if(check[st[index]] == true){\n // ans++;\n // check.clear();\n // check[st[ind... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int subStrings(string s){\n int n = s.size();\n int cnt = 1;\n unordered_map<char, int> ump;\n\n int i=0;\n while(i < n){\n if(ump.find(s[i]) != ump.end()){\n cnt++;\n ump.clear();\n um... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<char, bool> check; // Do check.clear()\n string st;\n int n,ans=1;\n void finder(int index){\n if(index>=n) return;\n if(check[st[index]] == true){\n cout<<index<<\" \";\n ans++;\n check.clear();\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<char, bool> check; // Do check.clear()\n string st;\n int n,ans=1;\n void finder(int index){\n if(index>=n) return;\n if(check[st[index]] == true){\n cout<<index<<\" \";\n ans++;\n check.clear();\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> visit;\n int count = 0;\n string curr = \"\";\n for(const auto& i: s){\n if(visit.count(i) == 1){\n visit.clear();\n visit.insert(i);\n co... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> visit;\n int count = 0;\n string curr = \"\";\n for(const auto& i: s){\n if(visit.count(i) == 1){\n visit.clear();\n visit.insert(i);\n co... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n\n unordered_set<char> seen;\n int count = 0;\n string cur_sub;\n\n for (char c : s) { \n if (seen.find(c) != seen.end()) {\n ++count;\n seen.clear();\n }\n\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int j = 0, mincuts = 0;\n unordered_map<char,int> mp;\n\n while(j < s.size())\n {\n mp[s[j]]++;\n while(mp[s[j]] > 1)\n {\n mp.clear();\n mincuts++;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int isValid(string s)\n {\n unordered_map<char, int> mp;\n for(auto ch : s)\n {\n mp[ch]++;\n if(mp[ch] > 1)\n {\n return false;\n }\n }\n return true;\n }\n\n int solve(int... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int ans=1;\n vector<int> cnt(26,0);\n \n for(auto x:s){\n cnt[x-'a']++;\n if(cnt[x-'a']>1){\n cnt=vector<int> (26,0);\n cnt[x-'a']=1;\n ans++;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int cnt = 0;\n int n = s.length();\n for(int i=0;i<n;i++)\n {\n vector<int> freq(26,0);\n while(i < n && freq[s[i]-'a'] == 0)\n {\n freq[s[i]-'a']++;\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int n=s.length();\n int i=0;\n int count=0;\n unordered_map<char,int> mp(n);\n while(i<n){\n if(mp.find(s[i])==mp.end()){\n mp[s[i]]++;\n \n }\n else if(mp.... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int helper(int i, string &s){\n vector<int> fre(26, 0);\n int n = s.length();\n int ans = 0;\n while((i < n) && (fre[s[i]-'a']==0)){\n fre[s[i]-'a']++;\n i++;\n ans++;\n }\n return ans;\n }\n int... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int counter = 0;\n int index = 0;\n\n while (index < s.size())\n {\n remove_prefix(s, index);\n counter++;\n }\n\n return counter;\n }\n\n // removes the longest prefix w/o... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 2 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_set<char> unique;\n int parts = 1;\n for (const auto& c : s) {\n if (!unique.emplace(c).second) {\n ++parts;\n unique.clear();\n unique.insert(c);\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n set<char> cur_pool;\n int n = 1;\n\n for (char ch : s) {\n if (cur_pool.count(ch) > 0) {\n n += 1;\n cur_pool = {ch};\n } else {\n cur_pool.insert(ch);\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_map<string ,int> mp;\n unordered_set<char> st;\n int len=s.length();\n int i=0;\n while(i<len){\n if(st.count(s[i])==0){\n string temp=\"\";\n while(i<len &... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n unordered_map<string ,int> mp;\n unordered_set<char> st;\n int len=s.length();\n int i=0;\n int count=0;\n while(i<len){\n if(st.count(s[i])==0){\n string temp=\"\";\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n string partiton = \"\";\n vector<string> ans;\n unordered_set<char> t;\n for(int i = 0; i < s.length(); i++)\n {\n if(t.find(s[i]) != t.end())\n {\n ans.push_back(partito... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n \n std::vector<std::string> partitions;\n std::string substring;\n std::unordered_set<char> distinct_set;\n\n // Iterate through string\n for(std::string::size_type i = 0; i<s.size(); i++) {\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int inCharacters(char x, vector<char> Characters) {\n for (int i = 0; i < Characters.size(); i++) {\n if (x == Characters[i]) return 1;\n }\n return 0;\n }\n int partitionString(string s) {\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n set<char> st;\n int count=0;\n for(auto c: s){\n if(st.find(c)!=st.end()){\n st.clear();\n count++;\n st.insert(c);\n }\n else st.insert(c);\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) \n {\n set<char>st;\n int ans=1;\n for(auto a:s){\n if(st.find(a)!=st.end()){\n ans++;\n st.clear();\n }\n st.insert(a);\n }\n return ans;\n }\n};",
"memory": "62373... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "\nclass Solution {\npublic:\n int partitionString(string s) {\n set<char>st;\n int g=1;\n for(int i=0;i<s.size();i++){\n if(st.find(s[i])!=st.end()){\n g++;\n st.clear();\n }\n st.insert(s[i]);\n }\n return... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n\n int partitionString(string s) {\n int n=s.size();\n int count=0;\n set<char> st;\n\n for(int i=0;i<n;i++){\n if(st.find(s[i]) != st.end()){\n count++;\n st.clear();\n }\n st.insert(s[... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int n=s.size();\n set<int>container;\n int count=0;\n for(int i=0;i<n;i++)\n {\n if(i==n-1)\n {\n count++;\n }\n if(container.find(s[i])!=container.... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n if(s.size()==1) return 1;\n int ans = 0;\n set<char> st;\n st.insert(s[0]);\n for(int i=1;i<s.size();i++){\n if(st.find(s[i])==st.end()) st.insert(s[i]);\n else{\n ans++;... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n int ans=1;\n set<char> st;\n for(auto it: s){\n if(st.find(it)!=st.end()){\n ans++;\n st.clear();\n }\n... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n set<char>st;\n int setSize=0;\n int total=0;\n for(int i=0;i< s.size();i++)\n {\n st.insert(s[i]);\n if(st.size()> setSize)\n {\n setSize= st.size();\n ... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int count=1;\n int l=0;\n set<char> myset;\n while(l<s.size()){\n int x=myset.size();\n myset.insert(s[l]);\n int y=myset.size();\n if(x==y){\n count++;\n myset=... |
2,487 | <p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <strong>once</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of substrin... | 3 | {
"code": "class Solution {\npublic:\n int partitionString(string s) {\n int count=1;\n int l=0;\n set<char> myset;\n while(l<s.size()){\n int x=myset.size();\n myset.insert(s[l]);\n int y=myset.size();\n if(x==y){\n count++;\n myset=... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.