id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct Trie{\n struct Node{\n unordered_map<char, int> to;\n int cnt = 0;\n Node(): cnt(0){}\n };\n vector<Node> d;\n Trie(): d(1){}\n void add(int i, const string& s){\n int v = 0;\n fo...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode {\n bool isWordEnd = false;\n int indx;\n TrieNode* children[26];\n\n};\n\nclass Trie {\n TrieNode* root = new TrieNode();\n\npublic:\n Trie() {}\n \n void insert(const string& word, int indx) {\n auto node = root;\n for(auto c: word)\n {\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode{\npublic:\n map<char, TrieNode*> children;\n bool isWord = false;\n int refs = 0;\n \n void addWord(string &word){\n\n TrieNode* cur = this;\n cur->refs++;\n\n for(char &c : word){\n if(cur->children.count(c) == 0)\n cur->children...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n vector<string> findWords(vector<vector<char>>& board, vector<string>& words) {\n end.resize(30001, \"\");\n buildTrie(words);\n vector<string> res;\n int n = board.size(), m = board[0].size();\n for (int i = 0; i < n; i++){\n for ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n vector<string> findWords(vector<vector<char>>& board, vector<string>& wordList) {\n int n = board.size(), m = board[0].size();\n set<string> words;\n words.insert(wordList.begin(), wordList.end());\n vector<string> res;\n string curr = \"\";...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode {\npublic:\n map<char, TrieNode*> children;\n bool isWord = false;\n int refs = 0;\n\n void addWord(string word) {\n TrieNode* cur = this;\n cur->refs++;\n for (char c : word) {\n if (cur->children.count(c) == 0) {\n cur->children[c]...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode {\npublic:\n map<char, TrieNode*> children;\n bool isWord = false;\n int refs = 0;\n\n void addWord(string word) {\n TrieNode* cur = this;\n cur->refs++;\n for (char c : word) {\n if (cur->children.count(c) == 0) {\n cur->children[c]...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode {\npublic:\n map<char, TrieNode*> children;\n bool isWord = false;\n int refs = 0;\n\n void addWord(string word) {\n TrieNode* cur = this;\n cur->refs++;\n for (char c : word) {\n if (cur->children.count(c) == 0) {\n cur->children[c]...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode {\n public:\n unordered_map<char, TrieNode*> children;\n string word;\n\n TrieNode() : word(\"\") {}\n};\n\nclass Solution {\npublic:\n\n vector<string> ans;\n\n void addToTrie(string word, TrieNode *node) {\n for (int i = 0; i < word.length(); i++) {\n if...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct Node {\n unordered_map<char, Node*> children;\n string word;\n};\n\nclass Solution {\nprivate:\n vector<vector<char>> brd;\n vector<string> res;\npublic:\n void Search(int row, int col, Node* parent) {\n char letter = brd[row][col];\n // we can always get a valid node because the Search()...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode {\n unordered_map<char, TrieNode*> children;\n bool eofWord=false;\n string word=\"\";\n};\nclass Solution {\n void dfs(vector<vector<char>>& board, vector<string>& res, TrieNode* root, int x, int y){\n if(x<0 || y<0 || x>=board.size() || y>=board[0].size()){\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode {\n unordered_map<char, TrieNode*> children;\n bool eofWord=false;\n string word=\"\";\n};\nclass Solution {\n void dfs(vector<vector<char>>& board, vector<string>& res, TrieNode* root, int x, int y){\n if(x<0 || y<0 || x>=board.size() || y>=board[0].size()){\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n\n struct Trie {\n Trie* children[26];\n bool isEnd;\n int num;\n Trie() {\n isEnd = false;\n num = 0;\n for(int i = 0; i < 26; ++i)\n children[i] = nullptr;\n }\n };\n\n Trie* root;\n\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution\n{\npublic:\n\tvoid deepDFS\n\t\t(const vector<vector<char>>& B, \n\t\t\tunordered_map<int, unordered_map<int, unordered_set<string>>>& F,\n\t\t\t\tunordered_map<string, unordered_set<int>>& G,\n\t\t\t\t\tvector<vector<int>>& V, int maxDepth, int depth, \n\t\t\t\t\t\tstring& s, int x, int y,...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <unordered_set>\n#include <iostream>\n#include <chrono>\n\nnamespace std {\ntemplate <> struct hash<std::pair<int, int>> {\n inline size_t operator()(const std::pair<int, int> &v) const {\n std::hash<int> int_hasher;\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <unordered_set>\n#include <iostream>\n#include <chrono>\n\nnamespace std {\ntemplate <> struct hash<std::pair<int, int>> {\n inline size_t operator()(const std::pair<int, int> &v) const {\n std::hash<int> int_hasher;\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n\n\nclass TrieNode\n{\n\tpublic:\n\t\tunordered_map<char, TrieNode*> Childs;\n\t\tbool IsWord = false;\n\t\tstring word;\n\t\tbool isRemoved = false;\n\n\t\tvoid insert(string word) {\n\t\t\tauto cur = this;\n\t\t\tfor (int i = 0; i < word.size(); i++)\n\t\t\t{\n\t\t\t\tif (cur->...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n\n\nclass TrieNode\n{\n\tpublic:\n\t\tunordered_map<char, TrieNode*> Childs;\n\t\tbool IsWord = false;\n\t\tstring word;\n\t\tbool isRemoved = false;\n\n\t\tvoid insert(string word) {\n\t\t\tauto cur = this;\n\t\t\tfor (int i = 0; i < word.size(); i++)\n\t\t\t{\n\t\t\t\tif (cur->...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n using SeenMap = unordered_map<int, unordered_set<int>>;\n struct TrieNode {\n TrieNode* next[26] = {nullptr};\n TrieNode* parent = nullptr;\n bool isEnd = false;\n int validChild = 0;\n TrieNode() {\n for (int i = 0; i < 26; i+...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n using SeenMap = unordered_map<int, unordered_set<int>>;\n struct TrieNode {\n TrieNode* next[26] = {nullptr};\n TrieNode* parent = nullptr;\n bool isEnd = false;\n int validChild = 0;\n TrieNode() {\n for (int i = 0; i < 26; i+...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n using SeenMap = unordered_map<int, unordered_set<int>>;\n struct TrieNode {\n TrieNode* next[26] = {nullptr};\n bool isEnd = false;\n int validChild = 0;\n TrieNode() {\n for (int i = 0; i < 26; i++) next[i] = nullptr;\n }\n\n ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n vector<string> findWords(vector<vector<char>>& board, vector<string>& words) {\n using u6 = uint64_t;\n const u6 K = 27;\n \n unordered_set<u6> hs;\n\n int m = board.size();\n int n = board[0].size();\n\n vector<char> visited(m...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode\n{\n TrieNode* children[26];\n bool isLeaf;\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n isLeaf = false;\n }\n};\n\nclass Solution\n{\npublic:\n TrieNode *root;\n vector<int> dirX{0, 1, 0, -1};\n vector<i...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode\n{\n TrieNode* children[26];\n bool isLeaf;\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n isLeaf = false;\n }\n};\n\nclass Solution\n{\npublic:\n TrieNode *root;\n vector<int> dirX{0, 1, 0, -1};\n vector<i...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n struct Node\n {\n char val;\n unordered_map<char,vector<Node*>> adj;\n };\n struct wordNode\n {\n char val;\n unordered_map<char,wordNode*> adj;\n };\n unordered_map<char,vector<Node*>> um;\n unordered_set<string> ans;\n uno...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode{\n unordered_map<char, TrieNode*> children;\n string word = \"\";\n};\n\nclass Trie{\n TrieNode* root;\n\n public:\n Trie(){\n root = new TrieNode();\n }\n\n TrieNode* getRootNode(){\n return root;\n }\n\n void insert(string word){\n TrieNode*...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "struct TrieNode{\n unordered_map<char, TrieNode*> children;\n // Optimization: Keeping track of word within trie would speed up the recursion\n // since we wont need to pass the cur string as a parameter.\n string word = \"\";\n};\n\nclass Trie{\n TrieNode* root;\n\n public:\n Trie(){\...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n vector<string> res;\n vector<vector<int>> dir = {{1,0},{-1,0},{0,1},{0,-1}};\n struct trie\n {\n vector<trie*> child;\n int cnt = 0;\n bool isEnd = false;\n trie()\n {\n child.resize(26,NULL);\n }\n };\n trie...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n struct Node {\n string word;\n vector<Node*> next;\n Node() : word(\"\"), next(26, nullptr) {}\n };\npublic:\n Node* root = new Node();\n vector<string> ans;\n\n void insert(const string& word) {\n Node* p = this->root;\n for(char c : wor...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n struct Node {\n string word;\n vector<Node*> next;\n Node() : word(\"\"), next(26, nullptr) {}\n };\npublic:\n Node* root = new Node();\n vector<string> ans;\n\n void insert(const string& word) {\n Node* p = this->root;\n for(char c : wor...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\n public:\n char val;\n bool wordEnd = false;\n bool hasNext = false;\n Node* children[26] = {};\n Node() {\n val = '\\0';\n }\n Node(char _val) {\n val = _val;\n }\n };\n\n\nclass Solution {\npublic:\n\n No...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\n public:\n char val;\n bool wordEnd = false;\n bool hasNext = false;\n Node* children[26] = {};\n Node() {\n val = '\\0';\n }\n Node(char _val) {\n val = _val;\n }\n };\n\n\nclass Trie {\npublic:\n Node* ro...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\n public:\n char val;\n bool wordEnd = false;\n bool hasNext = false;\n bool found = false;\n Node* children[26] = {};\n Node() {\n val = '\\0';\n }\n Node(char _val) {\n val = _val;\n }\n };\n\n\nclass ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\n public:\n char val;\n bool wordEnd = false;\n bool hasNext = false;\n bool found = false;\n Node* children[26] = {};\n Node() {\n val = '\\0';\n }\n Node(char _val) {\n val = _val;\n }\n };\n\n\nclass ...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Node {\n public:\n char val;\n bool wordEnd = false;\n bool hasNext = false;\n Node* children[26] = {};\n Node() {\n val = '\\0';\n }\n Node(char _val) {\n val = _val;\n }\n };\n\n\nclass Solution {\npublic:\n\n No...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode{\npublic:\n vector<TrieNode*> children;\n bool is_word;\n string str;\n TrieNode() {\n for(int i = 0; i < 26; i++) {\n children.push_back(NULL);\n is_word = false;\n str = \"\";\n }\n }\n};\n\nclass Solution {\nprivate:\n TrieN...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class TrieNode{\npublic:\n vector<TrieNode*> children;\n string word;\n bool is_word;\n TrieNode(): word(\"\"), is_word(false) {\n for(int i = 0; i < 26; i++) {\n children.push_back(NULL);\n }\n }\n};\nclass Solution {\nprivate:\n TrieNode* root = new TrieNode();\...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n const int MAX_WORD_LENGTH = 10;\n\n class TrieNode{\n private:\n TrieNode* children[26];\n\n public:\n TrieNode(){\n for(int i = 0; i < 26; i++){\n children[i] = NULL;\n }\n }\n\n void buildTrie(vector<vector<char>> board, TrieNode** ptr,\n...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n const int MAX_WORD_LENGTH = 10;\n\n class TrieNode{\n private:\n TrieNode* children[26];\n\n public:\n TrieNode(){\n for(int i = 0; i < 26; i++){\n children[i] = NULL;\n }\n }\n\n void buildTrie(vector<vector<char>> board, TrieNode** ptr,\n...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\n const int MAX_WORD_LENGTH = 10;\n\n class TrieNode{\n private:\n TrieNode* children[26];\n\n public:\n TrieNode(){\n for(int i = 0; i < 26; i++){\n children[i] = NULL;\n }\n }\n\n void buildTrie(vector<vector<char>> board, TrieNode** ptr,\n...
212
<p>Given an <code>m x n</code> <code>board</code>&nbsp;of characters and a list of strings <code>words</code>, return <em>all words on the board</em>.</p> <p>Each word must be constructed from letters of sequentially adjacent cells, where <strong>adjacent cells</strong> are horizontally or vertically neighboring. The ...
3
{ "code": "class Solution {\npublic:\n void help(vector<vector<char>>&board,unordered_map<string,int>&mp,string &t,int i,int j,unordered_map<string,int>&store,int len){\n if(i>=board.size() || j>=board[0].size() || i<0 || j<0 || board[i][j]=='0'){return;}\n //if(store[t]==0){return;}\n if(t.si...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
0
{ "code": "class Solution {\npublic:\n int t[101];\n int solve(vector<int>& nums, int i, int n){\n if(i > n)\n return 0;\n \n if(t[i] != -1)\n return t[i];\n \n int take = nums[i] + solve(nums, i+2, n);\n int skip = solve(nums, i+1, n);\n \n...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
1
{ "code": "class Solution {\npublic:\n int robHelper(vector<int>& nums , int n){\n int prev = 0;\n int prev2 = 0;\n for(int i = n-1 ; i >= 0 ; i--){\n\n int op1 = prev2 + nums[i];\n int op2 = prev;\n\n int curi = max(op1 , op2);\n prev2 = prev;\n ...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
1
{ "code": "class Solution {\npublic:\n int robHelper(vector<int>& nums , int n){\n int prev = 0;\n int prev2 = 0;\n for(int i = n-1 ; i >= 0 ; i--){\n\n int op1 = prev2 + nums[i];\n int op2 = prev;\n\n int curi = max(op1 , op2);\n prev2 = prev;\n ...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
2
{ "code": "class Solution {\npublic:\n int rob(vector<int>& nums) {\n int n = nums.size();\n if (n == 1) return nums[0]; \n\n vector<int> dp(n, 0);\n vector<int> dp1(n, 0);\n\n dp[0] = nums[0];\n dp[1] = max(nums[0], nums[1]);\n\n dp1[0] = 0;\n dp1[1] = nums[...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
2
{ "code": "class Solution {\npublic:\n int rob(vector<int>& nums) {\n int N = nums.size();\n if(N == 1){\n return nums[0];\n }\n if(N == 2){\n return max(nums[0] , nums[1]);\n }\n vector<int> a(N - 1);\n for(int i = 0; i < N - 1; i++){\n ...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
3
{ "code": "class Solution {\n private:\n int ans(int n,vector<long long int> &nums,vector<int>&dp){\n \n \n dp[0] = nums[0];\n \n \n for(int i=1;i<n;i++){\n int pick=nums[i];\n if(i>1){\n pick=nums[i]+dp[i-2];\n }\n ...
213
<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and&nbsp;...
3
{ "code": "class Solution {\n private:\n int ans(int n,vector<long long int> &nums,vector<int>&dp){\n \n \n int prev1 = nums[0];\n \n int prev2=0;\n for(int i=1;i<n;i++){\n int pick=nums[i];\n if(i>1){\n pick=nums[i]+prev2;\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstd::vector<int> parse_input_data_string(const std::string& s) {\n std::vector<int> data_1D;\n const int N = s.size();\n int accumulat...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstd::vector<int> parse_input_data_string(const std::string& s) {\n std::vector<int> data_1D;\n const int N = s.size();\n int accumulator...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "// class MaxHeap\n// {\n// private:\n// vector<int> T;\n// int sz;\n\n// int MaxIndex(int a, int b, int c)\n// {\n// if (T[a]>=T[b] && T[a]>=T[c]) { return a ;}\n// else if (T[b]>=T[a] && T[b]>=T[c]) { return b ;}\n// return c;\n// }\n\n// void swap(int i...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "// class MaxHeap\n// {\n// private:\n// vector<int> T;\n// int sz;\n\n// int MaxIndex(int a, int b, int c)\n// {\n// if (T[a]>=T[b] && T[a]>=T[c]) { return a ;}\n// else if (T[b]>=T[a] && T[b]>=T[c]) { return b ;}\n// return c;\n// }\n\n// void swap(int i...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstd::vector<int> parse_input_data_string(const std::string& s) {\n std::vector<int> data_1D;\n const int N = s.size();\n int accumulator...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "int findKthLargestA(vector<int>& nums, int k) {\n priority_queue<int> max_heap(nums.begin(), nums.end());\n\n while (--k != 0) max_heap.pop();\n\n return max_heap.top();\n}\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.t...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "int findKthLargestA(vector<int>& nums, int k) {\n priority_queue<int> max_heap(nums.begin(), nums.end());\n\n while (--k != 0) max_heap.pop();\n\n return max_heap.top();\n}\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.t...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstd::vector<int> parse_input_data_string(const std::string& s) {\n std::vector<int> data_1D;\n const int N = s.size();\n int accumulator...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n\n int partition(int l, int r, vector<int>& nums) {\n int pivot = nums[l];\n int pivotIndex = l;\n while (l <= r) {\n if (nums[l] > pivot && nums[r] < pivot) {\n int temp = nums[l];\n nums[l] = nums[r];\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n void heapify(int i , vector<int>&arr,int& N){\n if (2*i+1 >=N) return ;\n int larger=i;\n if (arr[2*i+1]>arr[i]) larger=2*i+1;\n if (2*i+2<N && arr[2*i+2]>arr[larger]) larger = 2*i+2;\n if(larger==i) return ;\n else {\n swa...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int partition(int l, int r, vector<int> &nums) {\n int pick = nums[l];\n int i= r;\n int j = l+1;\n while( j <= i) {\n if( nums[j] < pick && nums[i] > pick ) {\n swap(nums[j] , nums[i]);\n j++;\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution\n{\npublic:\n int quickSort(vector<int> &nums, int start, int end, int k)\n {\n if (start > end)\n return -1;\n if (start == end)\n return nums[k];\n\n int pivot = nums[end];\n int l = start;\n for (int i = start; i < end; i++)\n...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "/*\n * @lc app=leetcode id=215 lang=cpp\n *\n * [215] Kth Largest Element in an Array\n */\n\n// @lc code=start\nclass Solution {\n public:\n int findKthLargest(vector<int>& A, int k) {\n int n = A.size();\n k = n - k;\n return quick_select(A, 0, n - 1, k);\n }\n\n int quick_select(vector<int>&...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\n static bool comp(int x, int y){\n return x>y;\n }\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end(), comp);\n return nums[k-1];\n }\n};", "memory": "57900" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(std::vector<int>& nums, int k) {\n int left = 0, right = nums.size() - 1;\n while (true) {\n int pivot_index = rand() % (right - left + 1) + left;\n int new_pivot_index = partition(nums, left, right, pivot_index);\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\n bool check(int val, vector<int>& nums, int smallest_rank){\n int cnt = 0;\n for(auto num:nums){\n if (num <= val)cnt++;\n }\n\n return cnt >= smallest_rank;\n }\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int n = nums...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "\nclass Solution {\npublic:\n int fsize;\n int findKthLargest(vector<int>& nums, int k) {\n fsize = nums.size();\n build_heap(nums);\n int tmp;\n while (k > 0) {\n tmp = deleteMax(nums);\n k--;\n }\n return tmp;\n }\n void build_he...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int mn = *min_element(nums.begin(), nums.end());\n int mx = *max_element(nums.begin(), nums.end());\n\n vector<int> counts(mx-mn+1, 0);\n for (int num : nums) {\n ++counts[num-mn];\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int minValue = INT_MAX;\n int maxValue = INT_MIN;\n \n for (int num: nums) {\n minValue = min(minValue, num);\n maxValue = max(maxValue, num);\n }\n \n vect...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n return nums[n-k];\n }\n};", "memory": "58800" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n return nums[nums.size()-k];\n }\n};", "memory": "58900" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n return nums[n-k];\n }\n};", "memory": "58900" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.begin(),nums.end());\n return nums[n-k];\n }\n};", "memory": "59000" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n return nums[nums.size() - k];\n }\n};", "memory": "59000" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(std::vector<int>& nums, int k) {\n std::sort(nums.begin(), nums.end(), std::greater<int>());\n return nums[k-1];\n }\n};", "memory": "59100" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end(), std::greater<int>());\n return nums[k-1];\n }\n};", "memory": "59100" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n return nums[nums.size()-k];\n \n }\n};", "memory": "59200" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
0
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n \n sort(nums.begin(),nums.end());\n\n return nums[nums.size()-k];\n \n }\n};", "memory": "59200" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "#pragma GCC optimize(\"O2\")\nclass Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n ios::sync_with_stdio(0);\n\n sort(begin(nums),end(nums),greater<int>());\n return nums[k-1];\n }\n};", "memory": "59300" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int left = 0, right = nums.size() - 1;\n default_random_engine gen((random_device())());\n while (left <= right) {\n\n uniform_int_distribution<int> dis(left, right);\n int pivot_idx =...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int arr[nums.size()];\n int i;\n for(i=0;i<nums.size();i++){\n arr[i]=nums[i];\n }\n sort(arr,arr+nums.size());\n return arr[nums.size()-k];\n }\n};", "memory": "59500" }
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n std::random_device rnd;\n mt.seed(rnd());\n int left = 0;\n int right = nums.size() - 1;\n k = nums.size() - k;\n while(true){\n int pivot_index = quickSelect(left, right, nu...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class MinHeap{\n public:\n int heap[INT_MAX];\n int size;\n\n MinHeap(){\n heap[0] = -1;\n size = 0;\n }\n\n int top(){\n return heap[1];\n }\n\n void insert(int val){\n heap[++size] = val;\n int ind ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int partition(vector<int>& nums, int low, int high) {\n int pivot = nums[high];\n int idx = low - 1;\n\n for (size_t k = low; k < high; ++k) {\n if (nums[k] > pivot) {\n ++idx;\n std::swap(nums[idx], nums[k]);\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int partition(vector<int>& nums, int low, int high) {\n int pivot = nums[high];\n int idx = low - 1;\n\n for (size_t k = low; k < high; ++k) {\n if (nums[k] > pivot) {\n ++idx;\n std::swap(nums[idx], nums[k]);\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int partition(vector<int>& nums, int low, int high) {\n int pivot = nums[high];\n int idx = low - 1;\n\n for (size_t k = low; k < high; ++k) {\n if (nums[k] > pivot) {\n ++idx;\n std::swap(nums[idx], nums[k]);\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) \n {\n // std::sort(nums.begin(),nums.end(),greater<int>());\n // return nums[k-1];\n priority_queue<int,vector<int>,greater<int>> minHeap(nums.begin(),nums.begin()+k);\n for(int i=k; i<nums.size(); i...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(std::vector<int>& nums, int k) {\n std::priority_queue<int, std::vector<int>, std::greater<int>> min_heap(nums.begin(), nums.begin() + k);\n \n for (int i = k; i < nums.size(); i++) {\n if (nums[i] > min_heap.top()) {\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(std::vector<int>& nums, int k) {\n std::priority_queue<int, std::vector<int>, std::greater<int>> min_heap(nums.begin(), nums.begin() + k);\n \n for (int i = k; i < nums.size(); i++) {\n if (nums[i] > min_heap.top()) {\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n \n priority_queue<int,vector<int>,greater<int>> pq(nums.begin(),nums.begin()+k);\n\n for(int i=k;i<nums.size();i++){\n\n if(nums[i]>pq.top()){\n\n pq.pop();\n pq.pus...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, greater<int>> min_heap(nums.begin(), nums.begin() + k);\n for (int i = k; i < nums.size(); i++) {\n if (nums[i] > min_heap.top()) {\n min_heap.pop();\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, greater<int>>pq(nums.begin(), nums.begin()+k);\n int n = nums.size();\n for(int i=k; i<n; i++){\n int top = pq.top();\n if(top <= nums[i]){\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(std::vector<int>& nums, int k) {\n std::priority_queue<int, std::vector<int>, std::greater<int>> min_heap(nums.begin(), nums.begin() + k);\n \n for (int i = k; i < nums.size(); i++) {\n if (nums[i] > min_heap.top()) {\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class MaxHeap\n{\n private:\n vector<int> T;\n int sz;\n\n int MaxIndex(int a, int b, int c)\n {\n if (T[a]>=T[b] && T[a]>=T[c]) { return a ;}\n else if (T[b]>=T[a] && T[b]>=T[c]) { return b ;}\n return c;\n }\n\n void swap(int i, int j)\n {\n int temp = ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int n = nums.size();\n std::vector<int> tmp(n);\n mergeSelect(nums, tmp, 0, n - 1, k);\n return nums[k - 1];\n }\n\n void mergeSelect(vector<int>& nums, vector<int>& tmp, int L, int R, int k) {...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int max=INT_MIN;\n for(int i=0;i<nums.size();i++){\n nums[i]+=10000;\n if(nums[i]>max){\n max=nums[i];\n }\n }\n std::vector<int> arr(max + 1, 0);\n for...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n if (nums.size() < k) return -1; // can't have nums have less than k numbers\n\n // If k is small, use a min-heap to find the k-th largest element.\n if (k <= nums.size() / 2) {\n priority_queue<i...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n int n = nums.size();\n if (k < n - k + 1)\n {\n // Min Heap of size k:\n int cap = k;\n priority_queue<int, vector<int>, greater<int>> pq;\n for (int num : nums)\...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n priority_queue<int,vector<int>,greater<>> pq(nums.begin(), nums.begin()+k);\n for (int i = k, n = nums.size(); i < n; ++i) {\n if (nums[i] > pq.top()) {\n pq.push(nums[i]);\n ...
215
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p> <p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p> <p>Can...
1
{ "code": "class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, greater<int>> pq;\n for(auto it: nums){\n pq.push(it);\n if(pq.size()>k) pq.pop();\n }\n return pq.top();\n }\n};", "memory": "61100" }