id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "const int N = 1e6;\nclass Solution {\npublic:\n\n int go[N][2];\n int cnt[N];\n int timer = 1;\n\n void add(int x) {\n int v = 0;\n for (int i = 19; i >= 0; i--) {\n bool bit = (x >> i) & 1;\n if (go[v][bit] == -1) {\n go[v][bit] = timer;\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "#define ll long long\n\nconst int M = 20;\nconst int W = 2e6 + 7;\n\nint trie[2][W];\nint cnt[W];\nint node_cnt = 1;\n\nvoid add(int k){\n int x = 0; // root\n for(int i=M ; i>=0 ; i--){\n int bit = 0;\n if(k & (1LL << i))bit = 1;\n if(trie[bit][x] == 0){\n // create n... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "#include<bits/stdc++.h>\n\nconst int MAX_BIT_SIZE = 32;\nconst int MAX_TRIE_NODES = 50005 * MAX_BIT_SIZE;\n\nint customTrie[MAX_TRIE_NODES][2];\nint nodeOccurrences[MAX_TRIE_NODES][2];\nint globalNodeCounter;\n\nclass Solution {\npublic:\n int maximumStrongPairXor(vector<int> &elements) {\n int s... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n const static int maxN = (1 << 20) + 10;\n int seg[maxN * 4];\n \n void upd(int ind, int l, int r, int i, int val){\n if(i < l || r < i) return;\n if(l == r){\n seg[ind] += val;\n return;\n }\n int mid = (l + r) >> 1;\... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n int maxXOR = 0;\n int mask = 0;\n \n // Sort the array\n sort(nums.begin(), nums.end());\n \n // Try to set each bit in the result from left to right\n for (int bit = 20; b... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int maxXor = 0;\n int mask = 0;\n \n // Iterate through each bit from left to right\n for (int bit = 30; bit >= 0; bit--) {\n // Try to inclu... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "// Time: O(nlogn + nlogr) = O(nlogr), r = max(nums)\n// Space: O(t)\n\n// bit manipulation, greedy, trie, sort, two pointers\nclass Solution {\nprivate:\n class Trie {\n public:\n Trie(int bit_length)\n : bit_length_(bit_length)\n , nodes_() {\n new_node();\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class TrieNode{\n private:\n TrieNode* children[2];\n\n public:\n TrieNode(){\n children[0] = children[1] = NULL;\n }\n\n bool containsKey(int val){\n return children[val]!=NULL;\n }\n\n void add(int val){\n children[val] = new TrieNode();\n }\n\n TrieNode... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "struct Trie {\n vector<int> v, lt, rt; // v stores the count of elements in the subtree rooted at the current node, lt stores the index of the left child, and rt stores the index of the right child.\n int id = 0; // id is used to assign a unique identifier to each node in the Trie.\n\n Trie() : v(... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class TrieNode{\n private:\n TrieNode* children[2];\n\n public:\n TrieNode(){\n children[0] = children[1] = NULL;\n }\n\n bool containsKey(int val){\n return children[val]!=NULL;\n }\n\n void add(int val){\n children[val] = new TrieNode();\n }\n\n TrieNode... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n struct xorTrie {\n static constexpr int max_b = 1 << 19;\n xorTrie *p[2] = {};\n void insert(int n) {\n xorTrie *r = this;\n for (int b = max_b; b > 0; b >>= 1) {\n int bit = (n & b) > 0;\n if (r->p[bit]... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n struct xorTrie {\n static constexpr int max_b = 1 << 19;\n xorTrie *p[2] = {};\n void insert(int n) {\n xorTrie *r = this;\n for (int b = max_b; b > 0; b >>= 1) {\n int bit = (n & b) > 0;\n if (r->p[bit] == nullptr)\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n struct xorTrie {\n static constexpr int max_b = 1 << 19;\n xorTrie *p[2] = {};\n void insert(int n) {\n xorTrie *r = this;\n for (int b = max_b; b > 0; b >>= 1) {\n int bit = (n & b) > 0;\n if (r->p[bit] == nullptr)\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "/* XOR trie allows finding the larger XOR in log(m), which is in 20 in our case.\n\nThe trick is to exclude elements larger n and smaller than n / 2 from our search:\n\nWe sort our array and insert elements as we go.\nWe implement the remove operation, and use a sliding window to remove smaller numbers fro... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "struct Trie{\n static const int wmax = 6e6+1;\n int trie[wmax][2];\n int cnt[wmax];\n int num;\n\n Trie(){\n memset(trie, 0, sizeof(trie));\n memset(cnt, 0, sizeof(cnt));\n num = 0;\n }\n \n void insert(int x){\n int cur = 0;\n cnt[cur]++;\n fo... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "struct xorTrie {\n static constexpr int max_b = 1 << 19;\n xorTrie *p[2] = {};\n void insert(int n) {\n xorTrie *r = this;\n for (int b = max_b; b > 0; b >>= 1) {\n int bit = (n & b) > 0;\n if (r->p[bit] == nullptr)\n r->p[bit] = new xorTrie();\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 0 | {
"code": "class Solution {\npublic:\n struct TrieNode\n {\n TrieNode* bits[2];\n TrieNode()\n {\n for (int i = 0; i < 2; i++) {\n bits[i] = NULL;\n }\n }\n };\n class Trie\n {\n private:\n TrieNode* root;\n public:\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "class Solution {\npublic:\n struct TrieNode\n {\n TrieNode* bits[2];\n TrieNode()\n {\n for (int i = 0; i < 2; i++) {\n bits[i] = NULL;\n }\n }\n };\n class Trie\n {\n private:\n TrieNode* root;\n public:\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "class Solution {\npublic:\n struct TrieNode\n {\n TrieNode* bits[2];\n TrieNode()\n {\n for (int i = 0; i < 2; i++) {\n bits[i] = NULL;\n }\n }\n };\n class Trie\n {\n private:\n TrieNode* root;\n public:\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "class TrieNode {\npublic:\n int nodeMax;\n TrieNode * node[2];\n TrieNode() {\n nodeMax = -1e9;\n node[0] = nullptr; node[1] = nullptr;\n }\n};\n\nclass Trie {\nprivate:\n TrieNode * root;\npublic:\n Trie() {\n root = new TrieNode();\n }\n\n void insert(int n) {... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "class TrieNode {\npublic:\n int nodeMin, nodeMax;\n TrieNode * node[2];\n TrieNode() {\n nodeMin = 1e9;\n nodeMax = -1e9;\n node[0] = nullptr; node[1] = nullptr;\n }\n};\n\nclass Trie {\nprivate:\n TrieNode * root;\npublic:\n Trie() {\n root = new TrieNode();\n... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "class TrieNode {\npublic:\n int nodeMax;\n TrieNode * node[2];\n TrieNode() {\n nodeMax = -1e9;\n node[0] = nullptr; node[1] = nullptr;\n }\n};\n\nclass Trie {\nprivate:\n TrieNode * root;\npublic:\n Trie() {\n root = new TrieNode();\n }\n\n void insert(int n) {... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "class Solution {\npublic:\n struct node{\n node*child[2]={NULL};\n int count=0;\n };\n node*root=new node();\n void insert(int num,int val)\n {\n node*curr=root;\n for(int i=20;i>=0;i--)\n {\n int bit=(num&(1<<i))>0?1:0;\n if(curr->chi... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "\n\nclass Solution {\npublic:\n class TrieNode\n{\npublic:\n TrieNode *children[2];\n\n int cnt = 0;\n TrieNode()\n {\n for (int i = 0; i < 2; i++)\n children[i] = NULL;\n }\n};\nclass Trie\n{\npublic:\n TrieNode *root;\n Trie()\n {\n root = new TrieNode()... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 1 | {
"code": "struct TrieNode {\n int count; \n TrieNode *c[2]; \n \n TrieNode(): count(0) {\n c[0] = c[1] = nullptr; \n }\n}; \n\nclass Trie {\n TrieNode *root; \n const int MAX_BIT = 20; \npublic: \n Trie() {\n root = new TrieNode(); \n }\n\n void insert(int val, int inc) {\... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "class Solution {\npublic:\n\n struct node{\n node *child[2];\n int cnt=0;\n node(){\n child[0]=NULL;\n child[1]=NULL;\n }\n };\n\n void insert(int n,node* root){\n node *curr=root;\n for(int i=22;i>=0;--i){\n ++curr->cnt;\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "class Solution {\npublic:\n\n struct node{\n node *child[2];\n int cnt=0;\n node(){\n child[0]=NULL;\n child[1]=NULL;\n }\n };\n\n void insert(int n,node* root){\n node *curr=root;\n for(int i=20;i>=0;--i){\n ++curr->cnt;\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "#include <vector>\n#include <algorithm>\n#include <iostream>\nusing namespace std;\n\nclass TrieNode {\npublic:\n TrieNode* children[2];\n int c;\n \n TrieNode() {\n children[0] = children[1] = nullptr;\n c = 0;\n }\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n \n T... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "class Solution {\npublic:\n struct Node {\n Node* child[2];\n int exist;\n int cnt;\n\n Node() : exist(0), cnt(0) {\n for (int i = 0; i < 2; ++i) {\n child[i] = nullptr;\n }\n }\n };\n\n Node* root;\n\n void insert(const in... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "class BTrie{\npublic:\n\tstruct Node{\n\t\tNode* child[2];\n\t\tint cnt , exist;\n\t\t\n\t\tNode() : cnt(0) , exist(0){\n\t\t\tfor(int c = 0 ; c<2;c++){\n\t\t\t\tchild[c] = nullptr;\n\t\t\t}\n\t\t}\n\t\t\n\t\t~Node(){\n\t\t\tfor(int c = 0; c<2;c++){\n\t\t\t\tdelete child[c];\n\t\t\t}\n\t\t}\t\n\t};\n\tNode... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "const int MAX = 1e7 + 5;\nstruct Node {\n int left;\n int right;\n int val;\n Node() : left(-1), right(-1), val(0) {}\n};\nNode nodes[MAX];\nclass Solution {\npublic:\n int idx = 0;\n int query(int node, int d, int val, int ans) {\n if (d == -1) {\n return ans;\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 2 | {
"code": "class Solution {\n public:\n inline int get_max(const vector<int>& nums) {\n return empty(nums) ? 0 : *ranges::max_element(nums);\n }\n inline int get_min(const vector<int>& nums) {\n return empty(nums) ? INT_MAX : *ranges::min_element(nums);\n }\n array<vector<int>, 2> split(const vector<int>& ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\n public:\n bool has_pair(vector<int>& g0, vector<int>& g1) {\n int mx = empty(g0) ? 0 : *ranges::max_element(g0);\n int mn = empty(g1) ? INT_MAX : *ranges::min_element(g1);\n return mn - mx <= mx;\n }\n array<vector<int>, 2> split(vector<int>& nums, int bit) {\n array<vecto... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "struct TrieNode\n{\n int cnt[2];\n TrieNode *c[2];\n TrieNode()\n {\n cnt[0]=cnt[1]=0;\n c[0]=c[1]=nullptr;\n }\n};\n\nstruct Trie\n{\n const int BIT=19;\n TrieNode *root;\n Trie()\n {\n root=new TrieNode;\n }\n void Insert(int a)\n {\n TrieNo... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Node{\n public:\n Node* chil[2];\n int val;\n Node(){\n chil[0]=NULL;\n chil[1]=NULL;\n val=-INT_MAX;\n\n }\n};\nclass Trie{\n public:\n Node* root;\n Trie(){\n root=new Node();\n }\n void insert(string &s,int a){\n int j=0;\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "\nstruct TNode {\n TNode() {\n Children[0] = nullptr;\n Children[1] = nullptr;\n }\n\n std::array<TNode*, 2> Children;\n int Count = 0;\n};\n\nclass TKeyValue {\npublic:\n TKeyValue() : Root_(new TNode()) { }\n\n void AddElement(int element) {\n const auto bits = GetB... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "\nstruct TNode {\n TNode() {\n Children[0] = nullptr;\n Children[1] = nullptr;\n }\n\n std::array<TNode*, 2> Children;\n int Count = 0;\n};\n\nclass TKeyValue {\npublic:\n TKeyValue() : Root_(new TNode()) { }\n\n void AddElement(int element) {\n const auto bits = GetB... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "\nstruct TNode {\n TNode() {\n Children[0] = nullptr;\n Children[1] = nullptr;\n }\n\n std::array<TNode*, 2> Children;\n int Count = 0;\n};\n\nclass TKeyValue {\npublic:\n TKeyValue() : Root_(new TNode()) { }\n\n void AddElement(int element) {\n const auto bits = GetB... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "\nstruct TNode {\n TNode() {\n Children[0] = nullptr;\n Children[1] = nullptr;\n }\n\n std::array<TNode*, 2> Children;\n int Count = 0;\n};\n\nclass TKeyValue {\npublic:\n TKeyValue() : Root_(new TNode()) { }\n\n void AddElement(int element) {\n const auto bits = GetB... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n\n class Trie{\n public:\n int cnt;\n vector<Trie*> child;\n Trie(){\n cnt=0;\n child=vector<Trie*>(2,nullptr);\n }\n };\n\n int maximumStrongPairXor(vector<int>& nums) {\n \n int n=nums.size();\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Trie{\npublic:\n vector<Trie*>v;\n int cnt=0;\n int bit=20;\n Trie(){\n v.resize(2,NULL);\n }\n void insert(int n){\n Trie* root=this;\n // cout<<n<<endl;\n for(int i=1;i<=bit;i++){\n bool b=(1<<(bit-i))&n;\n // cout<<b<<\" \";\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\n int findMaximumXOR(vector<int>& nums) {\n int maximumXOR = 0;\n int mask = 0;\n\n for(int bit=20; bit>=0; bit--){\n mask = mask | (1<<bit);\n unordered_map<int,pair<int,int>> hashmap;\n\n for(auto &num :nums){\n if(h... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\n int findMaximumXOR(vector<int>& nums) {\n int maximumXOR = 0;\n int mask = 0;\n\n for(int bit=20; bit>=0; bit--){\n mask = mask | (1<<bit);\n unordered_map<int,pair<int,int>> hashmap;\n\n for(auto &num :nums){\n // p... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "#define ll long long\n\nconst int M = 20;\nconst int W = 2e7 + 7;\n\nint trie[2][W];\nint cnt[W];\nint node_cnt = 1;\n\nvoid add(int k){\n int x = 0; // root\n for(int i=M ; i>=0 ; i--){\n int bit = 0;\n if(k & (1LL << i))bit = 1;\n if(trie[bit][x] == 0){\n // create n... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "#define ll long long\n\nconst int M = 31;\nconst int W = 2e7 + 7;\n\nint trie[2][W];\nint cnt[W];\nint node_cnt = 1;\n\nvoid add(int k){\n int x = 0; // root\n for(int i=M ; i>=0 ; i--){\n int bit = 0;\n if(k & (1LL << i))bit = 1;\n if(trie[bit][x] == 0){\n // create n... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "#define ll long long\n\nconst int M = 20;\nconst int W = 2e7 + 7;\n\nint trie[2][W];\nint cnt[W];\nint node_cnt = 1;\n\nvoid add(int k){\n int x = 0; // root\n for(int i=M ; i>=0 ; i--){\n int bit = 0;\n if(k & (1LL << i))bit = 1;\n if(trie[bit][x] == 0){\n // create n... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n\n map<int,int>m[32];\n\n void insert_num(int x,int op)\n {\n int temp=0;\n for(int i=22;i>=0;i--)\n {\n int num=1LL<<i;\n if(x&num)\n {\n temp+=num;\n m[i][temp]+=op;\n }\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "struct TrieNode {\n vector<shared_ptr<TrieNode>> children;\n TrieNode() : children(2) {}\n int mn = INT_MAX;\n int mx = INT_MIN;\n};\n\nclass BitTrie {\n public:\n BitTrie(int maxBit) : maxBit(maxBit) {}\n\n void insert(int num) {\n shared_ptr<TrieNode> node = root;\n for (int i = maxBit; i >= ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int ans=0,mask=0;\n\n for(int i=20;i>=0;i--)\n {\n int cur=ans|(1<<i);\n mask|=(1<<i);\n unordered_map<int... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& A) {\n int res = 0;\n for (int i = 20; i >= 0; --i) {\n res <<= 1;\n unordered_map<int, int> pref, pref2;\n for (int& a : A) {\n int p = a >> i;\n if (pref.find(... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& A) {\n int res = 0;\n for (int i = 20; i >= 0; --i) {\n res <<= 1;\n unordered_map<int, int> pref, pref2;\n for (int& a : A) {\n int p = a >> i;\n if (pref.fi... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Trie {\n private:\n static constexpr int ALPHABET_SIZE = 2;\n\n public:\n struct TrieNode {\n std::array<std::shared_ptr<TrieNode>, ALPHABET_SIZE> children;\n int count;\n bool word;\n\n TrieNode() {\n word = false;\n count = 0;\n for (int ch = 0; ch < ALPHABET_SIZE; ch... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int ans=0,mask=0;\n\n for(int i=30;i>=0;i--)\n {\n int cur=ans|(1<<i);\n mask|=(1<<i);\n unordered_map<int... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n int ans=0,mask=0;\n\n for(int i=30;i>=0;i--)\n {\n int cur=ans|(1<<i);\n mask|=(1<<i);\n unordered_map<int... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n struct trie{\n trie *next[2];\n int count;\n trie (){\n for(int i=0;i<2;i++){\n next[i]=NULL;\n count=0;\n }\n }\n };\n \nvoid insert(trie *root,int num){\n trie *curr=root;\n vector<int>arr(22,0);\n int idx=0;\n whil... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n struct trie{\n trie *next[2];\n int count;\n trie (){\n for(int i=0;i<2;i++){\n next[i]=NULL;\n count=0;\n }\n }\n };\n \nvoid insert(trie *root,int num){\n trie *curr=root;\n vector<int>arr(22,0);\n int idx=0;\n whil... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "struct Node{\n Node* link[2]={NULL,NULL};\n bool containsKey(int ind){\n return link[ind]!=NULL;\n }\n Node* get(int ind){\n return link[ind];\n }\n void put(int ind,Node* node){\n link[ind]=node;\n }\n};\n\nclass Solution {\nclass Trie{\n private: Node* root;\n... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n class BitTrie\n {\n struct TrieNode\n {\n TrieNode(void) = default;\n ~TrieNode(void)\n {\n delete children[0];\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n class BitTrie\n {\n struct TrieNode\n {\n TrieNode(void) = default;\n ~TrieNode(void)\n {\n delete children[0];\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "class Solution {\npublic:\n int maximumStrongPairXor(vector<int>& nums) {\n class BitTrie\n {\n struct TrieNode\n {\n TrieNode(void) = default;\n ~TrieNode(void)\n {\n delete children[0];\n ... |
3,197 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
<ul>
<li><code>|x - y| <= min(x, y)</code></li>
</ul>
<p>You need to select two integers from <code>nums</... | 3 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \nusing namespace std;\nusing namespace __gnu_pbds; \n\n\ntypedef unsigned long long ull;\ntypedef long long ll;\ntypedef long double ld;\n\nconst int inf = 1e9;\nconst int mod = 1e9 + 7;\n#define pb p... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 0 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int count =0;\n int i=0;\n while(i<s1.size()){\n if(s1[i]==s2[i]&&s1[i]==s3[i]){\n count++;\n }\n else break;\n\n i++;\n }\n ... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 0 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int i=0;\n while(i<s1.length() && i<s2.length() && i<s3.length() && s1[i]==s2[i] && s1[i]==s3[i]){\n i++;\n }\n if(i==0) return -1;\n int total=s1.length()+s2.length()... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 0 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n // find the longest prefix that exists\n bool is_pref = true;\n long min_len = std::min(std::min(s1.size(), s2.size()), s3.size());\n int longest_prefix = 0;\n\n\n\n for (int i =... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 0 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int nMinLength = min(s1.length(), min(s2.length(), s2.length()));\n int nPrefixSize = 0;\n for (int i = 0; i < nMinLength; i++) {\n if (s1[i] == s2[i] && s2[i] == s3[i]) nPrefixSize... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 0 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int count = 0 , ans = 0;\n int s = min(s1.size() , min(s2.size() , s3.size()));\n\n for(int i =0 ; i < s ; i++){\n if(s1[i] == s2[i] && s2[i] == s3[i]){\n ans++;\n ... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 1 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int mini=min(s1.size(),min(s2.size(),s3.size()));\n int cnt=0;\n for(int i=0;i<mini;i++){\n if(s1[i]==s2[i] && s2[i]==s3[i]) cnt++;\n else break;\n }\n if... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 1 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int s = s1.size() + s2.size() + s3.size();\n int n = min({s1.size(), s2.size(), s3.size()});\n \n for (int i = 0; i < n; i++) {\n if (s1[i] != s2[i] || s2[i] != s3[i]) {\n ... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int i=0;\n while(i<s1.length() && i<s2.length() && i<s3.length() && s1[i]==s2[i] && s1[i]==s3[i]){\n i++;\n }\n if(i==0) return -1;\n int total=s1.length()+s2.length()... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int n=s1.size();\n int m=s2.size();\n int k=s3.size();\n string ans=\"\";\n int i=0;\n int j=0;\n int l=0;\n while(i<n&&j<m&&l<k)\n {\n cou... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int n=s1.size();\n int m=s2.size();\n int k=s3.size();\n string ans=\"\";\n int i=0;\n int j=0;\n int l=0;\n while(i<n&&j<m&&l<k)\n {\n // ... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n unordered_map<char,int>mp;\n unordered_map<char,int>mp1;\n // unordered_map<int,int>mp2;\n\n int count=0;\n int max=0;\n int l1=s1.size();\n int l2=s2.size();\n int l3=s3.size(... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n int m = min({s1.size(), s2.size(), s3.size()});\n int n = max({s1.size(), s2.size(), s3.size()});\n int i = 0;\n while(i<m){\n if(s1[i] == s2[i] && s2[i] == s3[i])i++;\n ... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n string s4 = mostCommon(s1, s2);\n string s5 = mostCommon(s3, s4);\n if (s5.size() == 0) return -1;\n int ans = 0;\n ans = (s1.size() - s5.size()) + (s2.size() - s5.size()) + (s3... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n string s4 = mostCommon(s1, s2);\n string s5 = mostCommon(s3, s4);\n if (s5.size() == 0) return -1;\n int ans = 0;\n ans = (s1.size() - s5.size()) + (s2.size() - s5.size()) + (s3... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n string s4 = mostCommon(s1, s2);\n string s5 = mostCommon(s3, s4);\n if (s5.size() == 0) return -1;\n int ans = 0;\n ans = (s1.size() - s5.size()) + (s2.size() - s5.size()) + (s3... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n \n bool allSameSize = s1.size() == s2.size() && s2.size() == s3.size();\n \n vector<int> sizesStrings {};\n sizesStrings.push_back(s1.size());\n sizesStrings.push_back(s2.... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n \n bool allSameSize = s1.size() == s2.size() && s2.size() == s3.size();\n\n vector<int> sizesStrings {};\n sizesStrings.push_back(s1.size());\n sizesStrings.push_back(s2.size());... |
3,207 | <p>You are given three strings: <code>s1</code>, <code>s2</code>, and <code>s3</code>. In one operation you can choose one of these strings and delete its <strong>rightmost</strong> character. Note that you <strong>cannot</strong> completely empty a string.</p>
<p>Return the <em>minimum number of operations</em> requi... | 3 | {
"code": "class Solution {\npublic:\n int findMinimumOperations(string s1, string s2, string s3) {\n \n bool allSameSize = s1.size() == s2.size() && s2.size() == s3.size();\n\n vector<int> sizesStrings {};\n sizesStrings.push_back(s1.size());\n sizesStrings.push_back(s2.size());... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string &s) {\n\n long long ans=0;\n bool zero = false;\n int one_count=1;\n\n for(int i=s.length()-1 ; i>=0 ; i--){\n if(s[i]=='1' && zero==false){\n one_count++;\n continue;\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "/*\nAs we go left-to-right, we count ones using cnt.\n\nWhen we see a zero, we need cnt swaps to move it in front cnt ones.\n*/\n\n\nclass Solution42 {\npublic:\nlong long minimumSteps(const string &s) {\n long long res = 0;\n for (int i = 0, cnt = 0; i < s.size(); ++i) {\n if (s[i] == '1')\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string& str) {\n long ans = 0, co = 0;\n for(int i=str.size()-1;i>=0;--i)\n {\n if(str[i]=='0')\n {\n ++co;\n }\n else\n {\n ans+=co;\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string& s) {\n long long ans = 0;\n long long count = 0;\n for (int i = s.length() - 1; i >= 0; i--) {\n if (s[i] == '0') {\n count++;\n } else {\n ans += count;\n }\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string& s) {\n ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n long long ans = 0;\n long long count = 0;\n for (int i = s.length() - 1; i >= 0; i--) {\n if (s[i] == '0') {\n count++;\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n long long ones =0;\n long long ans=0;\n\n for(int i=0;i<s.length();i++){\n if(s[i]=='1'){\n ones++;\n }\n else{\n ans=ans+ones;\n }\n }\n... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int a=-1;\n for(int i=s.size()-1;i>=0;i--){\n if(s[i]=='1') {\n a=i;\n break;\n }\n }\n if(a==-1) return 0;\n int b=a;\n int numofa=0;\n l... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n long long tail = s.size() - 1;\n long long count = 0;\n for (int i = 0; i < s.size(); i++) {\n if (s[i] == '1') {\n count += (tail - i);\n tail--;\n }\n }\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n long long tail = s.size() - 1;\n long long count = 0;\n for (int i = 0; i < s.size(); i++) {\n if (s[i] == '1') {\n count += (tail - i);\n tail--;\n }\n }\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 0 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) \n {\n long long res = 0;\n long long one = 0;\n for(long long i = 0;i<s.size();i++)\n {\n if(s[i] == '1')\n {\n one++;\n }\n else\n {\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 2 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n long long maxi=0;\n long long cnt=0;\n for(int i=0;i<s.size();i++){\n \n if(s[i]=='1') cnt++;\n else{\n while(s[i]=='0'){\n maxi+=cnt;\n i++;... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 2 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int a=-1;\n for(int i=s.size()-1;i>=0;i--){\n if(s[i]=='1') {\n a=i;\n break;\n }\n }\n if(a==-1) return 0;\n int b=a;\n int numofa=0;\n l... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int pos=0;\n long long ans=0;\n for(int i=0;i<int(s.size());++i){\n if(s[i]=='0'){\n ans+=i-pos;\n ++pos;\n }\n }\n return ans;\n }\n};",
"memory":... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\nlong long minimumSteps(string s)\n{\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n\n int n = s.size(), i; \n for(i = n-1; i >= 0; i--)\n {\n if(s[i] == '0') break;\n }\n\n long res = 0;\n int prevIndex = i;\n for(int j = 0;... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n long long ans=0;\n int n=s.size();\n int suf[n];\n suf[n-1] = s[n-1] == '0' ? 1 : 0;\n for(int i=n-2;i>=0;i--) {\n suf[i] = suf[i+1];\n if(s[i]=='0') {\n suf[i]+=1;\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int cnt=0;\n int n=s.size();\n long long ans=0;\n unordered_map<int,int> mp;\n for(int i=0;i<n;i++)\n {\n mp[s[i]]++;\n }\n int res=mp['0'];\n for(int i=0;i<n;i++)\n... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int p1 = 0, p2 = 0;\n string rev = s;\n sort(rev.begin(), rev.end());\n\n \n while (p1 < s.size() && s[p1] != '1') {\n p1++;\n }\n\n \n while (p2 < rev.size() && rev[p2] !=... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n stack<char> st;\n long long int ans=0;\n for(auto i:s){\n if(i=='1'){\n st.push('1');\n }\n else if(i=='0' && !st.empty()){\n ans+=st.size();\n ... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int n = s.length();\n queue<int> pos;\n for(int i = n - 1; i >= 0; i--) {\n if(s[i] == '1') {\n pos.push(i);\n }\n }\n long long steps = 0;\n for(int i = n - 1;... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n int n = s.size(),index=0;\n long long ans=0;\n deque<int> store;\n for(int i=0;i<n;i++){\n if(s[i] == '0')store.push_back(i);\n }\n while(store.size() > 0){\n int i = store[0]... |
3,195 | <p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two ad... | 3 | {
"code": "class Solution {\npublic:\n long long minimumSteps(string s) {\n long long ans=0;\n priority_queue<int> q;\n int cnt=0;\n for(auto i:s)if(i=='1')cnt++;\n int n=s.size();\n for(int i=n-cnt;i<n;i++){\n if(s[i]=='0')q.push(-i);\n }\n for(in... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.