Codeforces|Leetcode|Codechef free solutions
Ir al canal en Telegram
Free codeforces, Codechef, Leetcode solutions are available 😍😍😍😍😍😍 Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. 🥳🥳🥳🤩🤩🤩 Dm @Cpsoln if you want help in coding round.
Mostrar más4 317
Suscriptores
Sin datos24 horas
-137 días
-5230 días
Archivo de publicaciones
Amazon
Sum of Array done ✅✅✅
Last chocolate done ✅✅✅
After 5080 subscribers we will upload D.
Reaction krdo guys 😊
class Solution {
public:
long long solve(vector> &dp , vector &nums , int idx , int flag)
{
if(idx < 0) return 0;
if(idx == 0)
{
if(flag == 0) return nums[0];
else return INT_MIN;
}
if(dp[idx][flag] != -1) return dp[idx][flag];
long long ans = INT_MIN;
if(flag == 0)
{
ans = max(ans , nums[idx]+solve(dp , nums , idx-1 , 0));
ans = max(ans , nums[idx]+solve(dp , nums , idx-1 , 1));
}
else
ans = max(ans , -nums[idx] + solve(dp , nums , idx-1 , 0));
return dp[idx][flag] = ans;
}
long long maximumTotalCost(vector& nums)
{
int n = nums.size();
vector> dp(n , vector(2 , -1));
return max(solve(dp , nums , n-1 , 0) , solve(dp , nums , n-1 , 1));
}
};
class Solution {
public int minimumArea(int[][] grid) {
int minRow = Integer.MAX_VALUE;
int maxRow = Integer.MIN_VALUE;
int minCol = Integer.MAX_VALUE;
int maxCol = Integer.MIN_VALUE;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
if (grid[i][j] == 1) {
minRow = Math.min(minRow, i);
maxRow = Math.max(maxRow, i);
minCol = Math.min(minCol, j);
maxCol = Math.max(maxCol, j);
}
}
}
int height = maxRow - minRow + 1;
int width = maxCol - minCol + 1;
return height * width;
}
}
class Solution {
public double minimumAverage(int[] nums) {
Arrays.sort(nums);
List averages = new ArrayList<>();
int left = 0;
int right = nums.length - 1;
while (left < right) {
double average = (nums[left] + nums[right]) / 2.0;
averages.add(average);
left++;
right--;
}
double minAverage = Collections.min(averages);
return minAverage;
}
}
