id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n int L = beginWord.size();\n unordered_map<string, vector<string>> allComboDict;\n\n for(string word: wordList) {\n for(int i=0; i<L; i++){\n string ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n int len = beginWord.length();\n unordered_map<string, vector<string>> wordMp;\n for (string& word: wordList) {\n for (int i = 0; i < len; i++) {\n s... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n bool hasEndWord = false;\n int len = beginWord.length();\n unordered_map<string, vector<string>> map;\n for (auto word : wordList) {\n if (!hasEndWord && wo... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_set<string> wordlist_set;\n for(auto it : wordList){\n wordlist_set.insert(it);\n }\n if(wordlist_set.find(endWord) == wordlist_set.end()) return ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n wordList.push_back(beginWord);\n int n=wordList.size();\n unordered_map<string,vector<string>> adj;\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, vector<int>> mp;\n int ladderLength(string beginWord, string endWord,\n vector<string>& wordList) {\n int m = beginWord.size();\n int n = 0;\n for (auto word : wordList) {\n for (int i = 0; i < m; i+... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\nprivate:\n string delimit = \"\";\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map<string, vector<string>> adj;\n \n // Build adjacency list\n\n int endExists = -1;\n for(int i=wordList.size(... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\nbool only1diff(string &u,string &v){\n if(u.size()!=v.size() || u==v) return false;\n if(u==v) return false;\n int cnt=0;\n for(int i=0;i<u.size();i++){\n if(u[i]!=v[i]) cnt++;\n if(cnt>=2) return false;\n }\n return true;\n}\n int ladderLength(... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "int getDistance(string s1, string s2) {\n if (s1.size() != s2.size()) {\n return -1;\n }\n int res = 0;\n for (int i = 0; i < s1.size(); i++) {\n res += !!(s1[i] != s2[i]);\n }\n return res;\n}\n\nclass Solution {\npublic:\n int ladderLength(string beginWord, string endWo... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\n private:\n int fun(unordered_map<string,vector<string>>mp,string src, string target){\n priority_queue<pair<int,string>,vector<pair<int,string>>,greater<pair<int,string>>>pq;\n pq.push({1,src});\n unordered_set<string>s;\n s.insert(src);\n while(!... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "#include <queue>\n#include <string>\n#include <unordered_map>\n#include <vector>\n#include <limits>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int re(const unordered_map<string, vector<string>>& adjList, const string& start, const string& end) {\n if (start == end) return 0;\n\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "\n\nclass Solution {\npublic:\n int re(const unordered_map<string, vector<string>>& adjList, const string& start, const string& end) {\n if (start == end) return 0;\n\n unordered_map<string, int> distances;\n for (const auto& pair : adjList) {\n distances[pair.first] = IN... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n queue<pair<int, int>> q;\n bool checkadj(string a, string b) {\n int c=0;\n for(int i=0; i<a.size(); i++) {\n if(a[i]!=b[i]) {\n c++;\n if(c>1) return false;\n }\n }\n return true;\n }\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "typedef pair<int, string> pis;\n\nclass Solution {\npublic:\n int word_diff(const string& word_1, const string& word_2) {\n int n = word_1.size();\n int diff = 0;\n for (int i = 0; i < n; i++) {\n if (word_1[i] != word_2[i]) diff++;\n }\n return diff;\n }... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\n typedef std::pair<string,int> PAIR;\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n const int wSIZE = beginWord.size();\n unordered_map<string, vector<string>> keyToWord;\n\n for(string& word : wordList){\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\n typedef std::pair<string,int> PAIR;\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n const int wSIZE = beginWord.size();\n unordered_map<string, vector<string>> keyToWord;\n\n for(string& word : wordList){\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n int n = wordList.size();\n unordered_map<string, vector<string>> graph;\n \n // Step 1: Build the graph with the correct adjacency logic\n for (int i = 0; i < n... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n if(find(wordList.begin(),wordList.end(),endWord)==wordList.end()){return 0;}\n unordered_map<string,vector<string>> dist1;\n wordList.push_back(beginWord);\n for(int i... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n \n void fill_with_neighbour(string &x, unordered_map<string, vector<string> > &mp){\n string s = x; \n int n = x.size();\n mp[x] = {};\n for(int j = 0; j < n; j ++){\n for ( int i = 0 ; i < 26 ; i ++){\n s[j] = char('a'... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "struct node{\n string s;\n vector<node*> nbr;\n node(string k) : s(k) {} \n};\nclass Solution {\npublic:\n bool valid(string a, string b){\n int cnt = 0;\n for(int i = 0 ; i<a.size() ; i++){\n if(a[i] != b[i]) cnt++;\n }\n return cnt == 1;\n }\n \n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map < string , int > hash ; \n for( auto i : wordList ){\n hash[i] = 0 ; \n }\n queue< pair < pair < string , string > , int >> q ; \n q.p... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n \n bool canBeNextNode (string a, string b) {\n int count = 0;\n for (int i = 0; i < a.size() && count <= 1; i++)\n if (a[i] != b[i])\n count++;\n \n return count == 1;\n }\n\n unordered_map<string, vector<string>>... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\nbool differByOne(const std::string& word1, const std::string& word2) {\n int differences = 0;\n for (size_t i = 0; i < word1.length(); ++i) {\n if (word1[i] != word2[i]) {\n ++differences;\n if (differences > 1) {\n return false;\... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n map<string,vector<string>> patterns;\n string getPatterns(string pattern, int i){\n string temp = pattern;\n temp[i] = '*';\n return temp;\n }\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n bool isEndWor... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "/*\nEvery adjacent pair of words differs by a single letter.\nevery si is in wordList\nNote that beginWord does not need to be in wordList.\n\nmy apporch \n start with the beginWord \n hot = *ot h*t ho*\n*/\n\nclass Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<st... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n /*\n Non-directional graph.\n BFS\n // Method 1\n unordered_set<string> remaining nodes\n time: N*(N-1)*...*3*2*1 = N!\n space: O(N)\n\n // Method 2\n build a graph:\n std::ordered_map<string, std::unordered_set<s... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map<string, vector<string>> mp;\n for(auto str:wordList){\n for(int i=0;i<str.size();i++){\n string p=str.substr(0,i)+\"*\"+str.substr(i+1,str.si... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map<string,vector<string>> umap;\n int bs=beginWord.size();\n for(int i=0;i<wordList.size();i++ ){\n string str =wordList[i];\n for(int j=0;j<... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n unordered_set<string> visited;\n unordered_map<string,vector<string>> wordMap;\n unordered_set<string> wordSet;\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n unordered_set<string> visited;\n unordered_map<string,vector<string>> wordMap;\n unordered_set<string> wordSet;\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n // build transformation graph (including beginWord)\n if (find(wordList.begin(), wordList.end(), beginWord) == wordList.end()) {\n wordList.push_back(beginWord);\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n // build transformation graph (including beginWord)\n if (find(wordList.begin(), wordList.end(), beginWord) == wordList.end()) {\n wordList.push_back(beginWord);\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n void find(string ref,vector<string>&word,map<string,vector<string>>&adj,int size){\n int x=word.size();\n for(int i=0;i<x;i++){\n int cnt=0,j=0;\n string chk=word[i];\n while(j<size){\n if(ref[j]!=chk[j])cnt++;\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n map<string,vector<string>>mp;\n \n for(int i=0;i<wordList.size();i++){\n int c=0;\n for(int j=0;j<wordList[i].size();j++){\n if(beginWord... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\nprivate:\n std::unordered_set<std::string> setified_wordlist {};\n\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n // Shortest path - BFS (shortest transformation)\n // Let n = wordList.size()\n // (1) V(G) = all words... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord,\n vector<string>& wordList) {\n unordered_map<string, vector<string>> mp;\n int n = beginWord.size();\n for (int i = 0; i < wordList.size(); i++) {\n int count=0;\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\nprivate:\n bool valid_jump(string s , string t){\n int cnt = 0;\n for(int i = 0 ; i<s.size() ; i++){\n if(s[i]!=t[i]) cnt++; \n }\n return cnt == 1;\n }\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,vector<string>> mp;\n unordered_map<string,bool> visited;\n bool diff(string s1 , string s2){\n int i = 0;\n int res = 0;\n while(i < s1.size()){\n if(s1[i] != s2[i]){\n res++;\n }\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\n bool isOneLetterDiff(const string& from, const string& to) {\n if(from.size() < to.size() - 1 || from.size() > to.size() + 1) {\n return false;\n }\n int changes = 0;\n int shortest = min(from.size(), to.size());\n for(int i=0;i < shortest... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\n\n/**\n- do a graph which s1->s2 iff s1 differs on at most one char from s2\n- if beginword cannot be transformed to any string return 0, if endword not in wordlist return 0\n- if so, get shortest path from beginWord to endword using bfs and each vertex has min distance, since \n its bfs,... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int getDiff(string s1, string s2) {\n int ret = 0;\n for (int i = 0; i < s1.size(); i++) {\n ret += (s1[i] != s2[i]);\n }\n return ret;\n }\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n u... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "#include <queue>\n#include <string>\n#include <unordered_map>\n#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int re(unordered_map<string, vector<string>>& adjList, const string& start, const string& end) {\n if (start == end) return 0;\n \n unordered_map<string, int> ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n AddWordToWildCards(beginWord);\n AddWordToWildCards(endWord);\n bool endWordInWordList = false;\n for (auto& w : wordList) {\n if (w == endWord) {\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n AddWordToWildCards(beginWord);\n AddWordToWildCards(endWord);\n bool endWordInWordList = false;\n for (auto& w : wordList) {\n if (w == endWord) {\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map<string, vector<string>> adj;\n int L = beginWord.length();\n\n for (string& word : wordList) {\n for (int i = 0; i < L; ++i) {\n strin... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\nunordered_map<string, vector<string>> list;\n// vector<int> v;\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n\n\n list.clear();\n unordered_set<string> s;\n s.insert(beginWord);\n for(string& word : wordList){\n ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "struct Trie {\n // TODO: Maybe I only need one word per node, not a vector.\n // the kattis code has the same TODO comment.\n void insert(const string& word, const int id) {\n shared_ptr<TrieNode> curr = root;\n for (const char c : word) {\n auto& node = curr->childr... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "struct Trie {\n // TODO: Maybe I only need one word per node, not a vector.\n // the kattis code has the same TODO comment.\n void insert(const string& word, const int id) {\n shared_ptr<TrieNode> curr = root;\n for (const char c : word) {\n auto& node = curr->childr... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n\n unordered_set<string> uset;\n uset.insert(beginWord);\n for(string word: wordList)\n uset.insert(word);\n \n unordered_map<string,vector<string>> u... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map<string, vector<string>> adjList; \n unordered_map<string, bool> visited; \n\n bool transPos = false;\n int L = beginWord.length();\n for (auto& ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n unordered_map<string, vector<string>> adjList; \n unordered_map<string, bool> visited; \n\n bool transPos = false;\n int L = beginWord.length();\n for (auto& ... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n map<string, vector<string>> transforms;\n wordList.push_back(beginWord);\n for(auto word:wordList)\n {\n for(int i=0; i<word.length(); i++)\n {\n... |
127 | <p>A <strong>transformation sequence</strong> from word <code>beginWord</code> to word <code>endWord</code> using a dictionary <code>wordList</code> is a sequence of words <code>beginWord -> s<sub>1</sub> -> s<sub>2</sub> -> ... -> s<sub>k</sub></code> such that:</p>
<ul>
<li>Every adjacent pair of words ... | 3 | {
"code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector<string>& wordList) {\n map<string, vector<string>> transforms;\n wordList.push_back(beginWord);\n for(auto word:wordList)\n {\n for(int i=0; i<word.length(); i++)\n {\n... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "int a[100000];\nint result[100000];\n\nconst int INT_BIT_SIZE = sizeof(int)<<3, RADIX = 0x100, MASK = RADIX-1, MASK_BIT_LENGTH = 8;\nint *buckets = new int[RADIX](), *startIndex = new int[RADIX](), *temp = nullptr;\n\n// Fast radix sort by Kenneth Chiguichon and cpp'ified by cpu007:\n// https://github.com/... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "\nint a[100000];\nint result[100000];\n\nconst int INT_BIT_SIZE = sizeof(int)<<3, RADIX = 0x100, MASK = RADIX-1, MASK_BIT_LENGTH = 8;\nint *buckets = new int[RADIX](), *startIndex = new int[RADIX](), *temp = nullptr;\n\n// Fast radix sort by Kenneth Chiguichon and cpp'ified by cpu007:\n// https://github.co... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "int a[100000];\n\nint init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n ofstream out(\"user.out\");\n for (string s; getline(cin, s); out << '\\n') {\n if (s.length() == 2) {\n out << 0;\n continue;\n }\n int n = 0;\n for (in... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "int a[100000];\n\nint init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n ofstream out(\"user.out\");\n for (string s; getline(cin, s); out << '\\n') {\n if (s.length() == 2) {\n out << 0;\n continue;\n }\n int n = 0;\n for (in... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "\nauto fastIOSetup = []()noexcept{\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 0;\n}();\n\nclass Solution {\n std::unordered_set<int> data;\npublic:\n int longestConsecutive(vector<int>& nums) {\n std::ranges::sort(nums);\n int result = 0;... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if (nums.size() == 0) return 0;\n ranges::sort(nums);\n int n = nums.size();\n int ans = 1, curr = 1;\n for (int i = 1; i < n; i++){\n if (nums[i] == nums[i-1] + 1) {curr++; ans = max(... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\n std::unordered_set<int> data;\npublic:\n int longestConsecutive(vector<int>& nums) {\n std::ranges::sort(nums);\n int result = 0;\n int count = 0;\n auto last = std::numeric_limits<int>::max();\n for (auto x : nums) {\n if (x == last) c... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "const int MAXN = 2e9 + 1;\nconst int MINV = -1e9;\nclass Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n for (const auto &n : nums) {\n b.write(n);\n }\n int ans = 0;\n for (const auto &n : nums) {\n if (b.read(n)) {\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "const int MAXN = 2e9 + 1;\nconst int MINV = -1e9;\nclass Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n for (const auto &n : nums) {\n b.write(n);\n }\n int ans = 0;\n for (const auto &n : nums) {\n if (b.read(n)) {\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(const std::vector<int>& nums) {\n if (nums.empty())\n return 0;\n\n auto [minIt, maxIt] = std::minmax_element(nums.begin(), nums.end());\n const int minV = *minIt;\n const int maxV = *maxIt;\n\n constexpr si... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(const std::vector<int>& nums) {\n if (nums.empty())\n return 0;\n\n auto [minIt, maxIt] = std::minmax_element(nums.begin(), nums.end());\n const int minV = *minIt;\n const int maxV = *maxIt;\n\n constexpr si... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(const std::vector<int>& nums) {\n if (nums.empty())\n return 0;\n\n auto [minIt, maxIt] = std::minmax_element(nums.begin(), nums.end());\n const int minV = *minIt;\n const int maxV = *maxIt;\n\n constexpr si... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(const std::vector<int>& nums) {\n if (nums.empty())\n return 0;\n\n auto [minIt, maxIt] = std::minmax_element(nums.begin(), nums.end());\n const int minV = *minIt;\n const int maxV = *maxIt;\n\n constexpr si... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(const std::vector<int>& nums) {\n if (nums.empty())\n return 0;\n\n auto [minIt, maxIt] = std::minmax_element(nums.begin(), nums.end());\n const int minV = *minIt;\n const int maxV = *maxIt;\n\n constexpr si... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(std::vector<int>& nums) {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr); std::cout.tie(nullptr);\n\n //std::unordered_map<int, int> map; \n\n //// push all elements onto the map\n //for (auto va... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\nstd::cin.tie(NULL);\n if(nums.size()<=1){\n return nums.size();\n }\n sort(nums.begin(),nums.end());\n int maxlen=0;\n int cnt=0;\n for... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& n) {\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n if(n.size()==0) return 0;\n sort(n.begin(),n.end());\n int maxi=0,temp=1;\n for(int i=1;i<n.size();i++)\n {\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n sort(nums.begin(), nums.end());\n if (nums.size() == 0) {\n return 0;\n }\n int maxcount = 1;\n int count =... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n int ans = 0;\n int count = 1;\n for(int i=0;i<n-1;i++){\n if(i>0 && nums[i] == nums[i+1]){\n continue;\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n int n = nums.size();\n if(n == 0) return 0;\n int longSeq = 1;\n int curCnt = 0;\n int lastSmallest = INT_MIN;\n\n sort(nums.begin(), nums.end());\n\n for(int i=0; i<n; i++){\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int maxi=0;\n int cnt=0;\n int last=INT_MIN;\n for(int i=0;i<n;i++)\n {\n if((nums[i]-1)==last)\n {\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n int n = nums.size();\n int last = INT_MIN;\n int count =0 ;\n int lastlonger = 0;\n sort(nums.begin(),nums.end());\n\n for(int i = 0; i< n; i++){\n if(nums[i] - 1 == last){\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n if (nums.size() == 0) {\n return 0;\n }\n int maxcount = 1;\n int count = 1;\n for (int i = 1; i < nums.size(); i++) {\n if (nums[i]... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if(nums.size() == 0){\n return 0;\n }\n sort(nums.begin(),nums.end());\n int maxCount = 1;\n int curCount = 1;\n int curNum = nums[0];\n for(auto it: nums){\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n int c=1,m=1,n=nums.size();\n if (n==0)\n return 0;\n sort(nums.begin(),nums.end());\n unique(nums.begin(),nums.end());\n for(int i=0;i<n-1;i++){\n if(nums[i]-nums[i+1]==-1)\n... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int maxlen=0;\n int len=1;\n if(nums.size()==0) return 0;\n if(nums.size()==1) return 1;\n if(nums.size()==2 && nums[0]==nums[1]) return 1;\n for(i... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if(nums.empty())\n return 0;\n sort(nums.begin(),nums.end());\n int ans =1;\n int sum =1;\n int n = nums.size();\n int temp = nums[0]; \n for(int i=1;i<n;i++)\n {\n if(nums[i]==temp)\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if(nums.size() == 1 ){\n return 1;\n }\n if(nums.size() == 0 ){\n return 0;\n }\n sort(nums.begin(),nums.end());\n for(int i=0;i<(nums.size() -1);i++){\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n if(n==0) return 0;\n\n vector<int> longest_consecutive;\n int count = 0;\n for(int i=1; i<n ; i++){\n if(nums[i] - nums[... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if(nums.size()==0){\n return 0;\n }\n else if(nums.size()==1){\n return 1;\n }\n int arr[nums.size()];\n for(int i=0;i<nums.size();i++){\n arr[i]=nums[i];\... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "// class Solution {\n// public:\n// int longestConsecutive(vector<int>& nums) {\n// sort(nums.begin(), nums.end());\n// stack<int> s;\n// // int j=1;\n// int max =0;\n\n// for(int i=0; i<nums.size(); i++){\n// if(nums[i]+1==nums[i+1]){\n// max... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 0 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n auto uniqueEnd = unique(nums.begin(), nums.end());\n vector<int> numss(nums.begin(), uniqueEnd);\n if(numss.size()==1)\n {\n return 1;\n }\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) \n { \n if(nums.size() <= 1)\n {\n return nums.size();\n }\n // max heap\n priority_queue<int> pq(nums.begin(), nums.end());\n\n int prev = pq.top();\n pq.pop();\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n vector<int> nums;\n int solve1(){\n sort(nums.begin(), nums.end());\n int n=nums.size();\n if(!n) return 0;\n\n int ans=0, cnt=0, exp=nums[0];\n for(auto it: nums){\n if(it == exp){\n exp++;\n cnt... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& arr) {\n int n=arr.size();\n if(n<=1)\n return n;\n sort(arr.begin(),arr.end());\n int i=0;int j=0,maxc=1,c=1;\n vector<int> v=arr;\n arr.clear();\n for(int i=0;i<n-1;i++)\n {\n if(v[i]!=v[i... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) \n { \n if(nums.size() <= 1)\n {\n return nums.size();\n }\n // max heap\n priority_queue<int> pq(nums.begin(), nums.end());\n\n int prev = pq.top();\n pq.pop();\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n \n if(nums.size() == 0)\n {\n return 0;\n }\n\n priority_queue<int,vector<int>,greater<int>> q(nums.begin(),nums.end());\n\n int ans = INT_MIN;\n int a = q.top();\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n vector<int> v;\n int mx = 0;\n sort(nums.begin(), nums.end());\n for (size_t i = 0;i<nums.size();i++) {\n if (v.size() > 0 && nums[i] == v.back()) continue;\n if (i && nums[i] != v... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n vector<int> ans;\n int t=nums.size();\n if(t<2) return t;\n sort(nums.begin(),nums.end());\n int start=nums[0];\n int maxi=-1;\n ans.push_back(start);\n for(int i=1;i<t;i++){... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if(nums.size()==0)return 0;\n if(nums.size()==1)return 1;\n int cnt=1;\n vector<int>v;\n sort(nums.begin(),nums.end());\n v.push_back(nums[0]);\n int maxi= INT_MIN;\n \n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n // int n = nums.size();\n // if(n==1)return 1;\n // sort(nums.begin(),nums.end());\n // int count=0;\n // int maxi = 0;\n // for(int i=0;i<n-1;i++)\n // {\n // if(nums[i+... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if (nums.size() == 0) return 0;\n sort(nums.begin(), nums.end());\n print(nums);\n vector<int> counts;\n int curr = 1;\n for (int i = 1; i < nums.size() ; i ++){\n if (nums[i] =... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& N) {\n const int S = N.size();\n\n if (!S)\n return 0;\n\n if (S == 1)\n return 1;\n\n vector<pair<int, int>> Buckets;\n\n priority_queue<int, deque<int>, greater<int>> Q;\n \n... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& N) {\n const int S = N.size();\n\n if (!S)\n return 0;\n\n if (S == 1)\n return 1;\n\n vector<pair<int, int>> Buckets;\n\n priority_queue<int, deque<int>, greater<int>> Q;\n \n... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n vector<int> temp = nums;\n int n = nums.size();\n if(n==0 || n==1){\n return n;\n }\n sort(temp.begin(), temp.end());\n vector<int>count(n,1);\n for(int i=1;i<n;i++){\n ... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n if(nums.size()==0) return 0;\n sort(nums.begin(),nums.end());\n int size=1,count=1;\n vector<int> a;\n a.push_back(nums[0]);\n for(int i=1;i<nums.size();i++)\n {\n if(num... |
128 | <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence.</em></p>
<p>You must write an algorithm that runs in <code>O(n)</code> time.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums ... | 1 | {
"code": "class Solution {\npublic:\n int longestConsecutive(vector<int>& nums) {\n int n=nums.size();\n\n if (n==0){\n return 0;\n }\n\n if (n==1){\n return 1;\n }\n\n std::sort(nums.begin(), nums.end());\n vector<int> Nums;\n Nums.push_back(nums[0]);\n for (int i = 1; i ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.