id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(head == NULL) return nullptr;\n\n ListNode* slow =...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n//首先设立两个指针, 快指针每次走 2步, 慢指针每次走 1步\n//如果有环, 快慢指针最终一定会相遇, 且一定不为空\n//这时快指针刚好比慢指针多绕了一圈\n//这时如果快指针退回起点, 然后两个指针都每次走 1步\n//再次相遇的时候刚好就是环的起点\n\nclass ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(!head || !head -> next)\n return NULL;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "class Solution {\n public:\n ListNode* detectCycle(ListNode* head) {\n ListNode* slow = head;\n ListNode* fast = head;\n while (fast && fast->next) {\n slow = slow->next;\n fast = fast->next->next;\n if (slow == fast) {\n slow = head;\n while (slow != fast) {\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode* slow=head;\n ListNode* fast=head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "class Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n\n ListNode* slow = head;\n ListNode* fast = head;\n\n while(fast && fast->next) {\n slow = slow->next;\n fast = fast->next->next;\n\n if(slow == fast) {\n slow = hea...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode* slow = head;\n ListNode* fast = head;\n\n //...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode* fast=meetNode(head);\n if(fast==NULL) retur...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
2
{ "code": "class Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n\n ListNode* slow = head;\n ListNode* fast = head;\n\n while(fast && fast->next) {\n slow = slow->next;\n fast = fast->next->next;\n\n if(slow == fast) {\n slow = hea...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
2
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode* slow = head;\n ListNode* fast = head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findTarget(ListNode* head,int pos)\n {\n ListNode* targetNode=head;\n int i=0;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool findTarget(ListNode* head,int pos)\n {\n ListNode* targetNode=head;\n int i=0;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if (head == nullptr) {\n return head;\n }\...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\nprivate:\n // bool goesToTargetNode(ListNode *f, ListNode *target) {\n // ListNode *currNode = f;\n // wh...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "class Solution {\npublic:\n ListNode* detectCycle(ListNode* head) {\n if (!head or !head->next) return nullptr;\n\n ListNode* s = head, * f = head;\n\n while (s and f and f->next) {\n f = f->next->next;\n s = s->next;\n if (s == f) break;\n }\...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n vector <ListNode*> arr;\n ListNode*temp=head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n \n vector<ListNode*> nodes;\n\n while(head!=NU...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n vector<ListNode* > storage;\n int x = 0;\n\n whil...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(head==NULL || head->next==NULL)\n return NULL;...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\nListNode *detectCycle(ListNode *head)\n{\n ListNode *slow = head;\n ListNode *fast = head;\n while (fast...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(!head || !head->next) return nullptr;\n vector<pai...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool hasCycle(ListNode *head) {\n if(head==NULL ){\n return 0;\n }\n \n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode *slow=head,*fast=head;\n set <ListNode*> s;\...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n bool isCycleExists(ListNode *head){\n ListNode* fast =head;\n ListNode* slow=head;\n whi...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n\n // TODO: Write your code here\n ListNode* slow = head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n\n // TODO: Write your code here\n ListNode* slow = head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n set<ListNode*> nodes;\n ListNode *ptr = head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n set<ListNode*> s;\n ListNode* temp = head;\n\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(head==nullptr){\n return head;\n }\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n set<ListNode*>mpp;\n while(head!=NULL){\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(head==nullptr){\n return head;\n }\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode *temp=head;\n set<ListNode *>s;\n whi...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(head==NULL || head->next==NULL)\n {\n r...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n unordered_set<ListNode*> s;\n ListNode *p,*q;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n\n bool checkCycle(ListNode* head){\n ListNode* slow = head;\n ListNode* fast = head;\n\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n unordered_set<ListNode*> st;\n while(head){\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if (head == nullptr || head->next == nullptr) return nullptr...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if (head == nullptr || head->next == nullptr) return nullptr...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if(!(head)) return 0;\n\n unordered_set<ListNode*> m;...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n unordered_set<ListNode*> prev_nodes;\n\n ListNode* cu...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n unordered_set<ListNode*> s;\n \n while(head!=N...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n if (head == nullptr || head->next == nullptr) return nullptr...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n map<ListNode*,int>mp;\n ListNode* temp=head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n unordered_map<ListNode*,int> mp;\n ListNode* tmp = he...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n map<ListNode*,int> list;\n ListNode* temp = head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n // ListNode *fast = head , *second = head, *temp = head;\n ...
142
<p>Given the <code>head</code> of a linked list, return <em>the node where the cycle begins. If there is no cycle, return </em><code>null</code>.</p> <p>There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the <code>next</code> pointer. Internally, <co...
3
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n ListNode *detectCycle(ListNode *head) {\n ListNode* temp = head;\n std:unordered_map<ListNode*,int>...
1,603
<p>Given an array <code>nums</code>. We define a running sum of an array as&nbsp;<code>runningSum[i] = sum(nums[0]&hellip;nums[i])</code>.</p> <p>Return the running sum of <code>nums</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4] <strong>Ou...
0
{ "code": "class Solution {\npublic:\n vector<int> runningSum(vector<int>& nums) {\n vector<int>arr(nums.size());\n arr[0]=nums[0];\n for(int i=1;i<nums.size();i++){\n arr[i]=arr[i-1]+nums[i];\n }\n return arr;\n\n }\n};", "memory": "10700" }
1,603
<p>Given an array <code>nums</code>. We define a running sum of an array as&nbsp;<code>runningSum[i] = sum(nums[0]&hellip;nums[i])</code>.</p> <p>Return the running sum of <code>nums</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4] <strong>Ou...
0
{ "code": "class Solution {\npublic:\n vector<int> runningSum(vector<int>& nums) {\n vector<int> runningSum;\n int sum = 0;\n for (int num : nums){\n sum += num;\n runningSum.push_back(sum);\n }\n return runningSum;\n }\n};", "memory": "10700" }
1,603
<p>Given an array <code>nums</code>. We define a running sum of an array as&nbsp;<code>runningSum[i] = sum(nums[0]&hellip;nums[i])</code>.</p> <p>Return the running sum of <code>nums</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4] <strong>Ou...
0
{ "code": "class Solution {\npublic:\n vector<int> runningSum(vector<int>& nums) {\n int n=nums.size();\n vector<int> pre(n);\n pre[0]=nums[0];\n for(int i=1;i<n;i++){\n pre[i]=pre[i-1]+nums[i];\n }\n\n return pre;\n } \n};", "memory": "10800" }
1,603
<p>Given an array <code>nums</code>. We define a running sum of an array as&nbsp;<code>runningSum[i] = sum(nums[0]&hellip;nums[i])</code>.</p> <p>Return the running sum of <code>nums</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4] <strong>Ou...
0
{ "code": "class Solution {\npublic:\n vector<int> runningSum(vector<int>& nums) {\n vector<int> result;\n result.reserve(nums.size());\n\n result.push_back(nums[0]);\n for (int i = 1; i < nums.size(); ++i) {\n result.push_back(result[i - 1] + nums[i]);\n }\n\n ...
1,603
<p>Given an array <code>nums</code>. We define a running sum of an array as&nbsp;<code>runningSum[i] = sum(nums[0]&hellip;nums[i])</code>.</p> <p>Return the running sum of <code>nums</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4] <strong>Ou...
2
{ "code": "class Solution {\npublic:\n vector<int> runningSum(vector<int>& nums) {\n int n = nums.size();\n for(int i=1;i<n;i++){\n nums[i] = nums[i]+nums[i-1];\n }\n return nums;\n }\n};", "memory": "10900" }
1,603
<p>Given an array <code>nums</code>. We define a running sum of an array as&nbsp;<code>runningSum[i] = sum(nums[0]&hellip;nums[i])</code>.</p> <p>Return the running sum of <code>nums</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [1,2,3,4] <strong>Ou...
2
{ "code": "class Solution {\npublic:\n vector<int> runningSum(vector<int>& nums) {\n // vector<int>arr(nums.size());\n // arr[0]=nums[0];\n // for(int i=1;i<nums.size();i++){\n // arr[i]=arr[i-1]+nums[i];\n // }\n // return arr;\n for(int i=1;i<nums.size();i++){...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n sort(arr.begin(), arr.end());\r\n map<int,int> mp;\r\n int prev=arr[0], cnt=0, n=arr.size(), distinct=0;\r\n for(int i=0;i<n;i++)\r\n {\r\n if(arr[i] == prev)\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "// class Solution {\r\n// public:\r\n// int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n// // sort(arr.begin(), arr.end());\r\n// vector<int> countArray(5000, 0);\r\n// unordered_map<int,int> countMap;\r\n// for(int i=0; i<arr.size(); i++) countMap[arr[i]]++;\...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n \r\n int fr[200005] = {0};\r\n sort(arr.begin(), arr.end());\r\n int nr = -1, prev = -1;\r\n for (auto x : arr) {\r\n if (prev != x) {\r\n nr++;\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n \r\n int fr[200005] = {0};\r\n sort(arr.begin(), arr.end());\r\n int nr = -1, prev = -1;\r\n for (auto x : arr) {\r\n if (prev != x) {\r\n nr++;\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n \r\n int fr[200005] = {0};\r\n sort(arr.begin(), arr.end());\r\n int nr = -1, prev = -1;\r\n for (auto x : arr) {\r\n if (prev != x) {\r\n nr++;\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n vector<int> freq;\r\n sort(arr.begin(),arr.end());\r\n freq.push_back(1);\r\n int x = 0;\r\n int n = arr.size();\r\n for(int i=0;i<n-1;i++){\r\n if(arr[i+1] ==...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n sort(arr.begin(), arr.end());\r\n priority_queue<int, vector<int>, greater<int>> pq;\r\n int count = 1;\r\n for(int i = 1 ; i < arr.size() ; i++){\r\n if(arr[i] == arr[i - 1...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n vector<int> freq;\r\n sort(arr.begin(),arr.end());\r\n freq.push_back(1);\r\n int x = 0;\r\n int n = arr.size();\r\n for(int i=0;i<n-1;i++){\r\n if(arr[i+1] ==...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n priority_queue<int, vector<int>, greater<int>> pq;\r\n sort(arr.begin(),arr.end());\r\n int count=1;\r\n for(int i=1;i<arr.size();i++)\r\n {\r\n if(arr[i-1]==arr[i])\...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n // Sort the array to group similar elements together\r\n sort(arr.begin(), arr.end());\r\n\r\n // Vector to store pairs of (element, frequency)\r\n vector<pair<int, int>> v;\r\n\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n sort(arr.begin(), arr.end());\r\n vector<pair<int, int>> v;\r\n for (int i = 0; i < arr.size();) {\r\n int count = 1;\r\n int currentElement = arr[i];\r\n i++...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n sort(arr.begin(),arr.end());\r\n vector <pair <int,int>> a;\r\n for (int i=0;i<arr.size();i++) {\r\n a.push_back(make_pair(1,arr[i]));\r\n if (i>0 && arr[i]==arr[i-1]) a...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\r\nclass Solution {\r\npublic:\r\n using int2=pair<int, int>;\r\n struct cmp{\r\n bool operator()(int2& x, int2& y){\r\n return x.second>y.second;\r\n }\r\n };\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n // lame sauce\r\n ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);\r\n\r\n // count unique int frequencies\r\n unordered_map<int, int> F;\r\n int maxF = 0;\r\n for (...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> numToOcc;\r\n map<int, int> occToUct;\r\n for (int num : arr) {\r\n numToOcc[num]++;\r\n }\r\n for (const auto [num, occ] : numToOcc) {\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n void print_vi(const vector<int> &vi) {\r\n cout << \"{ \";\r\n for (int i : vi) {\r\n cout << i << \", \";\r\n }\r\n cout << '}' << endl;\r\n }\r\n void print_umii(const unordered_map<int, int> &umii) {\r\n cout << \"{ \...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n std::unordered_map<int,int> num_to_count_map;\r\n for (const int num: arr) num_to_count_map[num] += 1;\r\n\r\n std::map<int, int> frequency_to_numbers_count_map;\r\n for (const auto...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n void print_vi(const vector<int> &vi) {\r\n cout << \"{ \";\r\n for (int i : vi) {\r\n cout << i << \", \";\r\n }\r\n cout << '}' << endl;\r\n }\r\n void print_umii(const unordered_map<int, int> &umii) {\r\n cout << \"{ \...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n void print_vi(const vector<int> &vi) {\r\n cout << \"{ \";\r\n for (int i : vi) {\r\n cout << i << \", \";\r\n }\r\n cout << '}' << endl;\r\n }\r\n void print_umii(const unordered_map<int, int> &umii) {\r\n cout << \"{ \...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n void print_vi(const vector<int> &vi) {\r\n cout << \"{ \";\r\n for (int i : vi) {\r\n cout << i << \", \";\r\n }\r\n cout << '}' << endl;\r\n }\r\n void print_umii(const unordered_map<int, int> &umii) {\r\n cout << \"{ \...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> um;\r\n map<int, int> m;\r\n \r\n for(int& a: arr) um[a]++;\r\n int uniq = um.size();\r\n\r\n for(auto& i: um) m[i.second]++;\r\n\r\n for(m...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);\r\n int n=arr.size();\r\n unordered_map<int,int>mp;\r\n for(auto it : arr){\r\n mp[it]++;\r\n }\r\n vect...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int,int> mp;\r\n int unique = 0;\r\n for(int i: arr){\r\n if(!mp.count(i)){\r\n unique++;\r\n mp[i]=1;\r\n }\r\n e...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n std::unordered_map<int, int> counter;\r\n\r\n for (auto const& num: arr){\r\n counter[num]++;\r\n }\r\n\r\n std::vector<int> scounter;\r\n scounter.reserve(counter.si...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n std::unordered_map<int, int> counter;\r\n\r\n for (auto const& num: arr){\r\n counter[num]++;\r\n }\r\n\r\n std::vector<int> scounter;\r\n scounter.reserve(counter.si...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n\r\n ios_base::sync_with_stdio(false);\r\n cin.tie(NULL);\r\n cout.tie(NULL);\r\n\r\n unordered_map<int, int> factor;\r\n int value;\r\n priority_queue<int> min_heap;\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);\r\n unordered_map<int,int> mp;\r\n for(int i=0;i<arr.size();i++)\r\n mp[arr[i]]++;\r\n vector<int> result;\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n \r\n unordered_map<int,int> mp;\r\n\r\n for(int x : arr) mp[x]++;\r\n\r\n vector<pair<int,int>> tmp(mp.begin(), mp.end());\r\n\r\n sort(tmp.begin(), tmp.end(), [&](pair<int,int>...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> mp;\r\n for(int num: arr) {\r\n mp[num]++;\r\n }\r\n priority_queue<int, vector<int>, greater<int>> pq;\r\n for(auto it: mp) {\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int,int> count;\r\n for (int i = 0; i < arr.size(); i++) {\r\n count[arr[i]]++;\r\n }\r\n\r\n priority_queue<int, vector<int>, greater<int>> pq;\r\n for...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
0
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n int n = arr.size();\r\n priority_queue<int, vector<int>, greater<int>> pq;\r\n unordered_map<int,int> m;\r\n for(auto x: arr){\r\n m[x]++;\r\n }\r\n\r\n for(au...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
1
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int,int> cnt;\r\n\r\n for(auto el:arr){\r\n cnt[el]++;\r\n }\r\n\r\n priority_queue<int,vector<int>,greater<int>> pq;\r\n\r\n for(auto el:cnt){\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
1
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> counts;\r\n\r\n for(int i = 0; i < arr.size(); i++)\r\n counts[arr[i]]++;\r\n\r\n priority_queue<int, vector<int>, greater<int>> repeats;\r\n for(aut...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
1
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int,int>mp;\r\n for(auto &num:arr)\r\n {\r\n mp[num]++;\r\n }\r\n vector<int>result;\r\n for(auto &a:mp)\r\n {\r\n result.push_ba...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
1
{ "code": "\nclass Solution {\npublic:\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\n int n = arr.size();\n\t\tunordered_map<int, int> frMap;\n\t\tfor (int &x: arr) {\n\t\t\tfrMap[x]++;\n\t\t}\n\t\tvector<int> fr;\n\t\tfor (auto &p: frMap) {\n\t\t\tfr.push_back(p.second);\n\t\t} \n\t\tsort(fr.b...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
1
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> counts;\r\n vector<int> heap;\r\n for (auto n : arr)\r\n ++counts[n];\r\n for (auto &p: counts)\r\n heap.push_back(p.second);\r\n make_heap(begin(heap), en...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
1
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> frequencyMap;\r\n\r\n int result = 0;\r\n\r\n vector<int> frequencyArray;\r\n for(int num : arr){\r\n frequencyMap[num]++;\r\n }\r\n\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n // Greedy approach, remove from increasing count order: 1, 2, 3\r\n unordered_map<int, int> countMap;\r\n for(int& num : arr)\r\n {\r\n countMap[num]++;\r\n }\r\n\r\n...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n std::unordered_map<int, int> num_map;\r\n for (int v: arr) {\r\n if (num_map.contains(v)) {\r\n num_map[v]++;\r\n } else {\r\n num_map.insert({v, ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int, int> counts;\r\n for (int x : arr) counts[x] += 1;\r\n priority_queue<int, vector<int>> pq;\r\n for (auto p : counts) {\r\n if (pq.size()<k) pq.push(p.sec...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n int n = arr.size();\r\n map<int,int> occur;\r\n for(int x: arr){\r\n occur[x]++;\r\n }\r\n\r\n vector<int> freqofoccur(n+1,0);\r\n for(auto it: occur){\r\n ...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n map<int,int>mp;\r\n for(auto &it:arr){\r\n mp[it]++;\r\n }\r\n int n=arr.size();\r\n int unique=mp.size();\r\n vector<int>freqcount(n+1,0);\r\n for(auto...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n map<int,int>mp;\r\n for(auto &it:arr){\r\n mp[it]++;\r\n }\r\n int n=arr.size();\r\n int unique=mp.size();\r\n vector<int>freqcount(n+1,0);\r\n for(auto...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);\r\n std::map<int,int> m;\r\n std::priority_queue<int> pq;\r\n for(auto& i:arr){\r\n m[i]++;\r\n }\r\n //...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int,int> freqMap;\r\n for(auto x: arr){\r\n freqMap[x]++;\r\n }\r\n vector<pair<int,int>> v(freqMap.begin(), freqMap.end());\r\n sort(v.begin(), v.end()...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arrr, int k) {\r\n map<int, int> mpp;\r\n for (auto it : arrr) {\r\n mpp[it]++;\r\n }\r\n\r\n // Extract the elements into a vector of pairs\r\n vector<pair<int, int>> arr(mpp.begin(),...
1,604
<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p> <ol> </ol> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <s...
2
{ "code": "class Solution {\r\npublic:\r\n int findLeastNumOfUniqueInts(vector<int>& arr, int k) {\r\n unordered_map<int,int> freq;\r\n for(int &x : arr) {\r\n freq[x]++;\r\n }\r\n vector<int> fast;\r\n for(auto x : freq) {\r\n fast.push_back(x.second);\r\n ...