LeetCode, GeeksForGeeks Problem of the day solution
Open in Telegram
Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards Channel link : https://t.me/leetcode_gfg_potd
Show more1 250
Subscribers
+224 hours
+147 days
+2930 days
Posts Archive
class Solution {
public:
int buyChoco(vector& prices, int money) {
int m1 = INT_MAX;
int m2 = INT_MAX;
int temp=-1;
for(int i=0;iprices[i]){
m1 = prices[i];
temp = i;
}
}
for(int i=0;i=0){
return money-m1-m2;
}
return money;
}
};
class Solution{
public:
int findWinner(int n, int A[]){
int result = accumulate(A, A+n, 0, bit_xor());
return result!=0 && n&1?2:1;
}
};
class Solution {
public:
int dr[8]={-1, -1, -1, 0, 0, 1, 1, 1};
int dc[8]={-1, 0, 1, -1, 1, -1, 0, 1};
int n, m;
int avg(int row, int col, vector>&img){
int cnt=1;
int sum=img[row][col];
for(int i=0; i<8; i++){
int nr=row+dr[i];
int nc=col+dc[i];
if(nr>=0 && nr=0 && nc> imageSmoother(vector>& img) {
n=img.size();
m=img[0].size();
vector>ans(n, vector(m, 0));
for(int i=0; i
class Solution
{
public:
//Function to find the first position with different bits.
int posOfRightMostDiffBit(int m, int n)
{
if(m==n) return -1;
int cnt=1;
while(n>0 && m>0)
{
if((n&1)!=(m&1)) return cnt;
cnt++;
n>>=1;
m>>=1;
}
return cnt;
}
};
class Solution {
public:
int maxProductDifference(vector& nums)
{
sort(nums.begin(),nums.end());
int n= nums.size()-1;
int result= nums[n] *nums[n-1]-nums[0]*nums[1];
return result;
}
};
class Solution {
public:
int gameOfXor(int n, int A[]) {
int ans = 0;
for(int i=0; i
class FoodRatings {
public:
struct comparator{
bool operator()(const pair& F1 , const pair& F2)const{
return F1.second > F2.second || (F1.second == F2.second && F1 < F2);
}
};
unordered_map,comparator>> CF;
unordered_map FC;
unordered_map FR;
FoodRatings(vector& foods, vector& cuisines, vector& ratings) {
for(int i = 0; ifirst;
}
};
class Solution{
public:
// calculate the maximum sum with out adjacent
int findMaxSum(int *arr, int n) {
int a0=0,a1=arr[0];
for(int i=1;i
class Solution {
public:
bool isAnagram(string s, string t) {
if (s.length() != t.length()) return false;
int n = s.length();
int counts[26] = {0};
for (int i = 0; i < n; i++) {
counts[s[i] - 'a']++;
}
for (int i = 0; i < n; i++) {
counts[t[i] - 'a']--;
}
for (int i = 0; i < 26; i++)
if (counts[i]) return false;
return true;
}
};
long long int countStr(long long int n){
return 1 + 2*n + n*(n-1)*(n+1)/2;
}
