fa
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

رفتن به کانال در Telegram

Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards Channel link : https://t.me/leetcode_gfg_potd

نمایش بیشتر
1 250
مشترکین
+224 ساعت
+147 روز
+2930 روز
آرشیو پست ها
GFG | Problem of the day :]

class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode *fast = head, *slow = head; while(n--) fast = fast -> next; if(!fast) return head -> next; while(fast -> next) fast = fast -> next, slow = slow -> next; slow -> next = slow -> next -> next; return head; } };

LeetCode | Daily challenge :

class Solution{ public: // The main function that returns the arrangement with the largest value as // string. // The function accepts a vector of strings static bool cmp(string a,string b){ return a+b>b+a; } string printLargest(int n, vector &arr) { // code here sort(arr.begin(),arr.end(),cmp); string ans = ""; for(int i = 0;i

GFG | Problem of the day :

GFG | Problem of the day :

class Solution { public: vector sortedSquares(vector& nums) { for(auto &x : nums){ x = x*x; } sort(nums.begin(),nums.end()); return nums; } };

LeetCode | Daily challenge :

class Solution{ public: int firstElementKTime(int n, int k, int a[]) { std::unordered_map map; for(int i=0; i

GFG | Problem of the day :

class Solution { public: string maximumOddBinaryNumber(string s) { int i=s.length()-1; while(s[i]!='1') { i--; } swap(s[i],s[s.length()-1]); int l=0,r=i-1; while(l=0) { while(l<=r && r>=0 && s[r]=='1') { swap(s[l],s[r]); l++; } r--; } return s; } };

LeetCode | Daily challenge :

class Solution { public: int peakElement(int arr[], int n) { int ans=0; for(int i=0;iarr[i+1]){ ans=i; break; } else if(arr[i]>arr[i-1]){ ans=i; } } return ans; } };

GFG | Problem of the day :

class Solution { public: bool isEvenOddTree(TreeNode* root) { if(!root) return false; queueq; q.push(root); int lev=0; while(!q.empty()){ int n=q.size(); TreeNode* prev=NULL; while(n--) { TreeNode* cur=q.front(); q.pop(); if(lev%2==0){ if(cur->val % 2 == 0) return false; if(prev && prev->val>=cur->val) return false; }else{ if(cur->val % 2 == 1) return false; if(prev && prev->val<=cur->val) return false; } prev=cur; if(cur->left) q.push(cur->left); if(cur->right) q.push(cur->right); } lev++; } return true; } };

LeetCode | Daily challenge :

class Solution{ public: long long sumBitDifferences(int arr[], int n) { long long ans = 0; for(int k=0;k<32;k++){ int ct1 = 0; int ct0 = 0; for(int i=0;i>k)&1); if(t==1){ ct1++; } else{ ct0++; } } ans+=(ct1*(1ll)*ct0); } return ans*2; } };

GFG | Problem of the day :

class Solution { public: int findBottomLeftValue(TreeNode* root) { queue q; q.push(root); int ans = 0; while(!q.empty()){ int sz = q.size(); for(int i =0; i val; if(node->right) q.push(node -> right); if(node->left) q.push(node -> left); } } return ans; } };

LeetCode | Daily challenge :