es
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

Ir al canal en Telegram

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

Mostrar más
1 250
Suscriptores
+224 horas
+147 días
+2930 días
Archivo de publicaciones
class Solution { public: long long getCount(int n) { // Your code goes here vector> a(10); a[0] = {8}; a[1] = {2,4}; a[2] = {1,3,5}; a[3] = {2,6}; a[4] = {1,5,7}; a[5] = {2,4,6,8}; a[6] = {3,5,9}; a[7] = {8,4}; a[8] = {7,9,5,0}; a[9] = {6,8}; vector pre(10, 1); vector curr(10, 1); while(--n){ for(int i=0; i<10; i++){ curr[i] = pre[i]; for(auto j : a[i]){ curr[i] += pre[j]; } } pre = curr; } long long sum = 0; for(int i=0; i<10; i++){ sum += curr[i]; } return sum; } };

GFG | Problem of the day :

class Solution { public: int minIncrementForUnique(vector& nums) { sort(nums.begin(), nums.end()); int n = nums.size(); int ans=0; for(int i=1;i

LeetCode | Daily challenge :

class Solution { public: string armstrongNumber(int n) { int check = n; int sum = 0; while(n != 0){ sum += pow(n%10,3); n = (n-n%10)/10; } return (sum==check)?"true":"false"; } };

GFG | Problem of the day :

class Solution { public: int minMovesToSeat(vector& seats, vector& students) { sort(seats.begin(), seats.end()); sort(students.begin(), students.end()); int n=seats.size(); int ans=0; for(int i=0;i

LeetCode | Daily challenge :

class Solution { public: int padovanSequence(int n) { //code here int mod=1e9+7; int arr[n]; if(n==0 or n==1 or n==2) return 1; arr[0]=1; arr[1]=1; arr[2]=1; for(int i=3;i<=n;i++) { arr[i]=arr[i-2]+arr[i-3]; arr[i]=arr[i]%mod; } return arr[n]; } };

GFG | Problem of the day :

class Solution { public: void sortColors(vector& nums) { int n=nums.size(); int low=0, mid=0, high=n-1; while(mid<=high){ if(nums[mid]==0){ swap(nums[low], nums[mid]); low++; mid++; } else if(nums[mid]==1){ mid++; } else{ swap(nums[mid], nums[high]); high--; } } } };

LeetCode | Daily challenge :

class Solution { public: int countNumberswith4(int n) { int count = 0; for (int i = 0; i <= n; i++) { string str = to_string(i); size_t found = str.find('4'); if (found != string::npos) count++; } return count; } };

GFG | Problem of the day :

class Solution { public: vector relativeSortArray(vector& arr1, vector& arr2) { unordered_map mp; unordered_set s; vector v; for(int i : arr1){ mp[i]++; } for(int i : arr2){ s.insert(i); } for(int i : arr2){ for(int j = 0; j < mp[i]; j++){ v.push_back(i); } } vector b; for(auto i : mp){ if(!s.count(i.first)){ for(int j = 0; j < i.second; j++){ b.push_back(i.first); } } } sort(b.begin(), b.end()); for(int i : b){ v.push_back(i); } return v; } };

LeetCode | Daily challenge :

class Solution { public: long long maxTip(int n, int x, int y, vector &a, vector &b) { vector> diff; for (int i = 0; i < n; i++) { diff.push_back({abs(a[i] - b[i]), i}); } sort(diff.rbegin(), diff.rend()); long long ans = 0; for (auto it : diff) { int i = it.second; if (x == 0) { ans += b[i]; y--; } else if (y == 0) { ans += a[i]; x--; } else { if (a[i] > b[i]) { ans += a[i]; x--; } else { ans += b[i]; y--; } } //cout << "ans: " << ans << endl; } return ans; } };

GFG | Problem of the day :

class Solution { public: int heightChecker(vector& heights) { int mismatch = 0; vector count(101, 0); for(int i = 0; i < heights.size(); i++) count[heights[i]]++; int i = 1, j = 0; while(i < 101){ if(count[i] == 0){ i++; } else{ if(i != heights[j]) mismatch++; j++; count[i]--; } } return mismatch; } };

LeetCode | Daily challenge :