id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n int dp[51];\n int fun(int x,string &s,map<string,int>&m) {\n if(x>=s.length()) {\n return 0;\n }\n if(dp[x]!=-1) {\n return dp[x];\n }\n int ans=1+fun(x+1,s,m);\n string h=\"\";\n for(int i=x;i<s.length...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n int minExtraChar(string s, vector<string>& dictionary) {\n map<string,bool>vis;\n for(int i=0;i<dictionary.size();i++){\n vis[dictionary[i]]=1;\n }\n vector<pair<int,int>>vect;\n map<pair<int,int>,int>dp;\n for(int i=0;i<s.length();i++...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n int solve(string& s, int i, int n, map<string, bool>& mp, vector<int>& dp) {\n if (i >= n)\n return 0;\n\n if (dp[i] != -1)\n return dp[i];\n\n int skip = 1 + solve(s, i + 1, n, mp, dp);\n int take = n - i;\n string st ...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n map<string,int> m;\n int fun(int i,string s,vector<int>&dp){\n if(i>=s.size())return 0;\n if(dp[i]!=-1)return dp[i];\n int ans=1+fun(i+1,s,dp);\n string k=\"\";\n for(int j=i;j<s.size();j++){\n k+=s[j];\n if(m[k])ans...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n int minExtraChar(string s, vector<string>& dictionary) {\n int n=s.size();\n int dp[n];\n int m=dictionary.size();\n\n unordered_map<string, bool> mp;\n for(int i=0; i<dictionary.size(); i++){\n mp[dictionary[i]]=true;\n }\...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "int _ = [](){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n int minExtraChar(string s, vector<string>& dictionary) {\n int n=s.size();\n int dp[n];\n int m=dictionary.size();\n\n unordered_map<string, bool> mp;\n ...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class TrieNode {\npublic:\n bool iscompleteword;\n int count;\n TrieNode* children[26];\n TrieNode() {\n iscompleteword = false;\n count = 0;\n memset(children, 0, sizeof(children));\n }\n};\nclass Trie {\npublic:\n TrieNode* root;\n Trie() { root = new TrieNode();...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class TrieNode {\npublic:\n bool iscompleteword;\n int count;\n TrieNode* children[26];\n TrieNode() {\n iscompleteword = false;\n count = 0;\n memset(children, 0, sizeof(children));\n }\n};\nclass Trie {\npublic:\n TrieNode* root;\n Trie() { root = new TrieNode();...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "typedef long long ll; \nclass Solution {\npublic:\n int minExtraChar(string s, vector<string>& dictionary) {\n ll n = s.length();\n unordered_map <string,bool> m;\n for(auto x : dictionary)\n {\n m[x] = true;\n }\n vector <ll> dp(n+1,100000);\n ...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n string substring(int i, int j,string &s){\n string ans=\"\";\n for(int k=i;k<=j;k++){\n ans+=s[k];\n }\n return ans;\n }\n vector<int> dp;\n int solve(int i,string &s,map<string,int> &mp){\n if(i>=s.size()) return 0;\n ...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n\n int solve(int index , string & str , map<string , int>&mp , vector<int>&dp){\n if(index >= str.length()){\n return 0 ;\n }\n if(dp[index] != -1){\n return dp[index] ;\n }\n string temp = \"\" ;\n int a...
2,755
<p>You are given a <strong>0-indexed</strong> string <code>s</code> and a dictionary of words <code>dictionary</code>. You have to break <code>s</code> into one or more <strong>non-overlapping</strong> substrings such that each substring is present in <code>dictionary</code>. There may be some <strong>extra characters<...
3
{ "code": "class Solution {\npublic:\n int minExtraChar(string s, vector<string>& dictionary) {\n map<string, bool> isPresent;\n for(int i=0;i<dictionary.size();++i){\n isPresent[dictionary[i]] = 1;\n }\n\n int n = s.length();\n\n int extraChars[n][n];\n for(int...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "int speedUp = []\n{std::ios::sync_with_stdio(0); std::cin.tie(0); return 0; }();\nbool has[100002];\n\nint digit(char c)\n{\n return c & 15;\n}\nbool isDigit(char c)\n{\n return '0' <= c && c <= '9';\n}\nint init = [] {\n std::ofstream out(\"user.out\");\n std::cout.rdbuf(out.rdbuf());\n for...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "int speedUp = []\n{std::ios::sync_with_stdio(0); std::cin.tie(0); return 0; }();\nbool has[100002];\n\nint digit(char c)\n{\n return c & 15;\n}\nbool isDigit(char c)\n{\n return '0' <= c && c <= '9';\n}\nint init = [] {\n std::ofstream out(\"user.out\");\n std::cout.rdbuf(out.rdbuf());\n for...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "#pragma GCC target(\"tune=native\")\n#pragma GCC optimize(\"Ofast\")\n//#pragma GCC optimize(\"Os\")\n// Code here is optimized for size\n\nstatic const auto fastIO = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n   return 0;\n}();\nclass Solution ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "auto init =[](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n\n for(int i=0;i<n;i++){\n while(nums[i] >0 &&nums[i] <=n && nums[n...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "auto init =[](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n\n for(int i=0;i<n;i++){\n while(nums[i] >0 &&nums[i] <=n && nums[n...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "#include <bits/stdc++.h>\r\n\r\nusing namespace std;\r\n\r\nclass Solution {\r\npublic:\r\n int firstMissingPositive(vector<int>& nums) {\r\n if (nums.size() == 0) {\r\n return 1;\r\n }\r\n\r\n int i = 0;\r\n while (i < nums.size()) {\r\n /* nums[i] shou...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n bool y = false ;\n for(int i = 0 ; i < n ; i++){\n if(nums[i]==1){\n y = true ;\n }\n }\n if(y == false){\n return 1;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "#include <bits/stdc++.h>\r\n\r\nusing namespace std;\r\n\r\nclass Solution {\r\npublic:\r\n int firstMissingPositive(vector<int>& nums) {\r\n if (nums.size() == 0) {\r\n return 1;\r\n }\r\n\r\n int i = 0;\r\n while (i < nums.size()) {\r\n /* nums[i] shou...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = size(nums);\n for (int j = 0; j < 5; j++)\n for (int i = 0; i < n; i++) {\n int x = nums[i];\n if (x >= 1 && x <= n) {\n swap(nums[x - 1], nums[i]...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]<=0){\n nums[i] = n + 2;\n }\n }\n for(int i=0;i<n;i++){\n if(abs(nums[i]) > n) continue;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n for (int i = 0; i < nums.size(); i++)\n if (nums[i] < 0)\n nums[i] = 0;\n\n for (int i = 0; i < nums.size(); i++) {\n if (abs(nums[i]) > 0) {\n int idx = abs(nums...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]<=0 || nums[i]>n){\n nums[i]=n+1;\n }\n }\n for(int i=0;i<n;i++){\n if(abs(nums[i])<=n){nums[abs(...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
0
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int N = nums.size();\n vector<bool> visited(N+1, false);\n for(int i =0 ;i<N;i++){\n if(nums[i] > 0 && nums[i] <= N){\n visited[nums[i]] = true;\n }\n }\n\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] < 0)\n nums[i] = 0;\n }\n\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] != 0 && abs(nums[i]) <= nums.siz...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] < 0)\n nums[i] = 0;\n }\n\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] != 0 && abs(nums[i]) <= nums.siz...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n vector<bool> seen(n + 1, false); // Array for lookup\n\n // Mark the elements from nums in the lookup array\n for (int num : nums) {\n if (num > 0 && num <= n) {\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n vector<bool> present(1+n, false);\n for(int i = 0; i < n; i++) {\n if(nums[i] > 0 && nums[i] <= n) {\n present[nums[i]] = true;\n }\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\n\npublic:\n\n int firstMissingPositive(vector<int>& nums) {\n\n int n = nums.size();\n\n vector<bool> seen(n + 1, false); // Array for lookup\n\n // Mark the elements from nums in the lookup array\n\n for (int num : nums) {\n\n if (num > 0 && num...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n vector<bool>vec(n+1,false);\n for(int i=0;i<n;i++){\n if(nums[i]>0 && nums[i]<=n)\n vec[nums[i]]=true;\n }\n\n for(int i=1;i<=n;i++){\n if(...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n\n int firstMissingPositive(vector<int>& nums) {\n int arr[100005] = {0};\n\n for(int i=0; i< nums.size();i++){\n if(nums[i]>0 && nums[i]<nums.size()+1){\n arr[nums[i]] = 1;\n }\n }\n\n for(int i=1; i< nums.size(...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size() , max = INT_MAX ,N= 1e5+2 ;\n int arr[N];\n for(int i = 1 ; i <= n+1 ; i++){\n arr[i] = -1 ;\n }\n for(int j = 0 ; j < n ; j++){\n if(nums[j] >= 0 && n...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n bool* mapping = new bool[nums.size() + 1] {false};\n\n for (int i = 0; i < nums.size(); i++) {\n\n if (nums[i] > 0 && nums[i]<=nums.size()) {\n mapping[nums[i]] = true;\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n }\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int res=1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>res) retur...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int r=1;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "// class Solution {\n// public:\n// int firstMissingPositive(vector<int>& nums) {\n// bool contains_one = false;\n// for(int x: nums){\n// if(x==1){\n// contains_one = true;\n// break;\n// }\n// }\n// if(!contains_o...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n nums.erase(remove_if(nums.begin(), nums.end(), [](int n) { return n <= 0; }), nums.end());\n\n sort(nums.begin(), nums.end());\n\n int target = 1;\n for (int n : nums) {\n if (n == target) ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int number = 1;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n if(number == nums[i]){\n number++;\n }\n }\n return number;\n \n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int target = 1;\n for(int i = 0; i < nums.size(); ++i){\n if(nums[i]<1) continue;\n if(nums[i]>target) return target;\n target = nums[i]+1;\...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int missingno=1;\n sort(nums.begin(),nums.end());\n for(int num:nums)\n {\n if(num == missingno)\n {\n missingno++;\n }\n else if(num >missingno)\n {\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int last = -5000;\n int smallest = 1;\n for(int i = 0; i < nums.size(); i++){\n \n if(nums[i] <= 0) {\n continue;\n }\n if(smallest...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int last = -5000;\n int smallest = 1;\n for(int i = 0; i < nums.size(); i++){\n \n if(nums[i] <= 0) {\n continue;\n }\n if(smallest...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
2
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int target=1;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>0 && nums[i]==target) target++;\n else if(nums[i]>target) return target;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n int index = 1;\n\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] < 1 || index > nums[i]) continue;\n if (index == nums[i]) ++index;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int r=1;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]>0){\n if(r==nums[i]){\n r++;\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n }\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n vector<int> res(n+1);\n for (int i :nums){\n if (i>0 && i<=n) res[i-1]++;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n vector<int> temp(n+1);\n\n for(int i=0; i<n; i++){\n if(nums[i]>0 && nums[i]<=n){\n temp[nums[i]] = 1;\n }\n }\n\n for(int j=1; j<tem...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& arr) {\n int n=arr.size();\n \n vector<int> v(n+1,0);\n for(int i=0;i<n;i++){\n if(arr[i]>0 && arr[i]<=n) v[arr[i]]=1; \n }\n \n for(int i=1;i<n+1;i++){\n if(v[i]==0){...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n\n int numsSize = nums.size();\n vector<int> cnt(numsSize+2, -1);\n\n for(int i = 0; i < numsSize; i++) {\n if(nums[i] > 0 && nums[i] <= numsSize+1) {\n cnt[nums[i]] = 1;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<int> temp(nums.size() + 2, 0);\n int ans;\n\n for(int i = 0; i < nums.size(); i++) {\n if(nums[i] > 0 && nums[i] <= nums.size()) {\n temp[nums[i]] = 1;\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n vector<int> v(n + 1, 0);\n for (int i = 0; i < n; i++) {\n if (nums[i] > 0 && nums[i] <= n) {\n v[nums[i]] = 1;\n }\n }\n for (int i ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n const int N = 1e5+2;\n vector<bool> exist(N);\n for(int x: nums) {\n if(x > 0 && x < N) {\n exist[x] = 1;\n }\n }\n for(int i = 1; i < N; i++) {\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<bool> map(100001, 0);\n for(const int &val: nums){\n if(val > 0 && val < 100001) map[val] = 1;\n }\n for(int i = 1; i < map.size(); ++i){\n if(!map[i]) return i;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n\n vector<bool> found(100005, false);\n for(int i=0; i<n; i++) {\n if (nums[i]>=1 && nums[i] <= 100005) found[nums[i]] = true;\n }\n for(int i=1; i<100005; i++)...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(std::vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n if (nums.size() <= 1) { if (nums[0] == 1) { return 2; } else { return 1; } }\n\n\n int index = get_first_positive_element(nums);\n std::cout << index << std...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int getPos(vector<int> arr, int val) {\n for(int i =0; i < arr.size(); i++)\n if(arr[i]==val)\n return i;\n return -1;\n }\n int firstMissingPositive(vector<int>& arr) {\n sort(arr.begin(), arr.end());\n int n = arr....
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int binarySearch(vector<int> a, int n) {\n int l = 0, r = n - 1, res = -1;\n while(l <= r){\n int mid = l + (r - l) / 2;\n if(a[mid] > 0){\n res = mid;\n r = mid - 1;\n }\n else{\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n nums.resize(n * 2);\n for (int i = 0; i < n; i ++) if (nums[i] >= 1 && nums[i] <= n) nums[n - 1 + nums[i]] = 1;\n for (int i = n; i < nums.size(); i ++) if (!nums[i]) return i -...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int> a) {\n \n int i,n=a.size();\n for(i=0;i<n;i++)\n if(a[i]<=0 || a[i]>n)\n a[i] = INT_MAX;\n\n a.push_back(INT_MAX);\n for(i=0;i<n;i++)\n {\n if(abs(a[i])==INT_MAX) continue;\n \n if(a...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int findSmallestPositive(vector<int>nums){\n nums.push_back(0);\n int n = nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]<=0 || nums[i]>=n){\n nums[i] = 0;\n }\n }\n for(int i=0;i<n;i++){\n n...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n vector<int> v;\n for (int i = 1; i <= n; i++){\n v.push_back(i);\n }\n\n for (int i = 0; i < n; i++){\n if (nums[i] >= 1 && nums[i] <= n){\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "\nclass Solution {\npublic:\n int segregateArr(vector<int>& arr) {\n int j = 0;\n int n = arr.size();\n for (int i = 0; i < n; i++) {\n if (arr[i] <= 0) {\n swap(arr[i], arr[j]);\n j++;\n }\n }\n return j;\n }\n\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& arr) {\n int n=arr.size();\n sort(arr.begin(),arr.end());\n vector<int>pos;\n int prev=0;\n for(int i=0;i<n;i++){\n if(arr[i]>0 && prev!=arr[i]){\n prev=arr[i];\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int>temp;\n temp.push_back(nums[0]);\n for(int i=1;i<nums.size();i++){\n if(nums[i]!=temp.back()) temp.push_back(nums[i]);\n }\n int n = temp.si...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n vector<int>arr;\n int temp;\n sort(nums.begin(),nums.end());\n if((n==1&&n...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<int> temp;\n for (int num : nums)\n {\n if (num > 0)\n {\n temp.push_back(num);\n }\n }\n nums = temp;\n\n sort(nums.begin(), nums.end());\n\n auto newEnd = uni...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<int>nums2;\n sort(nums.begin(),nums.end());\n for(int i=0,j=0;i<nums.size();i++)\n {\n if(nums[i]>=1)\n {\n nums2.push_back(nums[i]) ;\n j++;\n }\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n vector<int>arr;\n int temp;\n sort(nums.begin(),nums.end());\n if((n==1&&nums[0]>1)||(nums[0]<0&&n==1)){\n return 1;\n }else if(n==1){\n return...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n vector<int>arr;\n int temp;\n sort(nums.begin(),nums.end());\n if((n==1&&nums[0]>1)||(nums[0]<0&&n==1)){\n return 1;\n }else if(n==1){\n return...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n=nums.size();\n vector<int>arr;\n int temp;\n sort(nums.begin(),nums.end());\n if((n==1&&nums[0]>1)||(nums[0]<0&&n==1)){\n return 1;\n }else if(n==1){\n return...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n priority_queue<int, vector<int>, greater<int>> pq;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0)\n pq.push(nums[i]);\n }\n int ct=1;\n while(!pq.empty()){\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n\n // Remove all non positive numbers\n nums = removeNeg(nums);\n\n // Now we have array of size n so for each number in the range n, Mark the number in its index as -1, So when iterating if the index val is ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<long long>v;\n sort(nums.begin(), nums.end());\n\n for(int i = 0; i < nums.size(); i++){\n\n if(v.size() > 0 && v.back() == nums[i]){\n cout<<\"hello \"<<i<<endl;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\nint find(int target,vector<int> nums){\n int index=-1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==target){\n index=i;\n }\n }\n return index;\n}\nvector<int> solve(vector<int> nums){\n vector<int> ans;\n ans.push_back(nums[0]);\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n long long int arr[1000000]={0};\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>0&&nums[i]<1000000)\n arr[nums[i]]++;\n }\n for(int i=1;i<=1000000;i++)\n {\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n long long int arr[1000000]={0};\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]>0&&nums[i]<1000000)\n arr[nums[i]]++;\n }\n for(int i=1;i<=1000000;i++)\n {\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n int n = nums.size();\n vector<int> arr;\n\n for(int each : nums)\n if(each > 0)\n arr.push_back(each);\n \n if(arr.size() == 0)\n return 1;\n \n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class SPV {\nprivate:\n vector<int> mVec;\n void removeNegatives() {\n vector<int> positiveVec{};\n for (auto& v : mVec) {\n if (v>0) {\n positiveVec.push_back(v);\n }\n }\n mVec = positiveVec;\n }\n void sortVec() {\n sort...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<long long>nums2;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n nums2.push_back(nums[i]);\n }\n // else{\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<long long>nums2;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n nums2.push_back(nums[i]);\n }\n // else{\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n vector<int> num;\n int l=nums.size(), j=0;\n //cout << \"size: \" << l << \"\\n\";\n cout << \"length of nums: \" << l << \"\\n\";\n for (int i=0; i<l; i++) { if (nums[i] > 0) { num.insert ( nu...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n if(nums.size()==0){\n return 1;\n }\n for(int i=0 ; i<nums.size() ; i++){\n if(nums[i]<=0){\n nums.erase(nums.begin()+i);\n i--;\n }\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_map<int, int> mp(nums.size());\n\n for (int num : nums) {\n if (num > 0) mp[num] = 1;\n }\n for (int i = 1; i <= nums.size() + 1; ++i) {\n if (mp.find(i) == mp.end()) {...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_map<int, int> mp(nums.size());\n\n for (int num : nums) {\n if (num > 0) mp[num] = 1;\n }\n for (int i = 1; i <= nums.size() + 1; ++i) {\n if (mp.find(i) == mp.end()) {...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_set<int> visited;\n visited.reserve(nums.size());\n\n vector<int> pos;\n pos.reserve(nums.size());\n\n for (int x: nums) {\n if (x > 0 && visited.find(x) == visited.end()) ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_set<int> pos;\n pos.reserve(nums.size());\n\n for (int x: nums) {\n if (x > 0) {\n pos.emplace(x);\n }\n }\n for (int i = 1; i <= INT_MAX; i++) {\...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n unordered_set<int>sett;\n int cnt=1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0 && sett.find(nums[i])==sett.end()){\n if(nums[i]!=cnt)r...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n \n unordered_map<int, bool> map;;\n int lg = INT_MIN;\n for(const auto& i : nums) {\n if(i < 1) continue; \n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n int sm = INT_MAX;\n unordered_map<int, bool> map;\n int lg = INT_MIN;\n for(const int& i : nums) {\n if(i < 1) continue...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n \n unordered_map<int, bool> map;;\n int lg = INT_MIN;\n for(const int& i : nums) {\n if(i < 1) continue; \n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n \n unordered_map<int, bool> map;\n int lg = INT_MIN;\n for(const int& i : nums) {\n if(i < 1) continue; \n i...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\nSolution() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n }\n int firstMissingPositive(vector<int>& nums) {\n \n unordered_map<int, bool> map;;\n int lg = INT_MIN;\n for(const auto& i : nums) {\n if(i < 1) co...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_set<int> numSet;\n for (int num : nums) {\n if (num > 0) {\n numSet.insert(num);\n }\n }\n\n // Step 2: Iterate through the range [1, len(nums) + 1]\n for (int i = 1; i <= ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_set<int> mpp(nums.begin(),nums.end());\n int i=1;\n while(true)\n {\n if(mpp.find(i)==mpp.end())\n {\n return i;\n }\n i++;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_map<int,int>mp1;\n int k=1;\n for(int i=0;i<nums.size();i++)\n mp1[nums[i]]++;\n for(int i=0;i<nums.size();i++){\n if(mp1[k]){\n k++;\n }\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_map<int,int> mp;\n\n for(int num:nums){\n mp[num]++;\n }\n int i=1;\n while(true){\n if(mp.find(i)!=mp.end())i++;\n else return i;\n }\n }\n...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_map<int,bool> temp;\n\n for(auto i : nums)\n temp[i] = true;\n\n int small = 1;\n while(true){\n if(temp.find(small) == temp.end())\n return small;\n ...
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_set<int> mem;\n int ans = 1;\n for(auto i : nums){\n mem.insert(i);\n while(mem.contains(ans)){ ++ans; }\n }\n return ans;\n }\n};", "memory": "69608" }
41
<p>Given an unsorted integer array <code>nums</code>. Return the <em>smallest positive integer</em> that is <em>not present</em> in <code>nums</code>.</p> <p>You must implement an algorithm that runs in <code>O(n)</code> time and uses <code>O(1)</code> auxiliary space.</p> <p>&nbsp;</p> <p><strong class="example">Exa...
3
{ "code": "class Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n unordered_map<int,int>mp;\n\n for(auto& it : nums){\n mp[it] = 1;\n }\n int maxi = *max_element(nums.begin(),nums.end());\n for(int i = 1 ; i <= maxi; i++){\n if(mp.find(i...