Given an array arr[] consisting of N positive integers and a positive integer K such that there are N countries, each country has arr[i] players, the task is to find the maximum number of teams that can be formed by forming teams of size K such that each player in the team is from a […]

Continue Reading#include using namespace std; void Rearrange(int arr[], int K, int N){ int ans[N + 1]; int f = -1; for (int i = 0; i < N; i++) { ans[i] = -1; } K = find(arr, arr + N, K) – arr; vector smaller, greater; for (int i = 0; i < N; i++) { if (arr[i] < arr[K]) smaller.push_back(arr[i]); else if (arr[i] > arr[K]) greater.push_back(arr[i]); } int low = […]

Continue ReadingGiven an array arr[] and brr[] both consisting of N integers and a positive integer K, the task is to find the minimum value of X such that the sum of the maximum of (arr[i] – X, 0) raised to the power of brr[i] for all array elements (arr[i], brr[i]) is at most K.Examples:Input: arr[] […]

Continue Readingimport java.io.*;class GFG{ static void findMinDays(int arr[], int R[], int N, int X, int K){ int low = 0, high = X; int minDays = -1; while (low = K) { sum += temp; } } if (sum >= X) { minDays = mid; high = mid – 1; } else { low = mid + 1; } } System.out.println(minDays);}public static void main(String[] args){ int X = 100, K = 45; int arr[] = { 2, 5, […]

Continue Reading#include using namespace std; bool check(int K, int n, int m, vector arr, int good_share){ int candies = n, taken = 0; while (candies > 0) { taken += min(K, candies); candies -= min(K, candies); for (int j = 0; j < m; j++) { int consume = (arr[j] * candies) / 100; candies -= consume; } } return (taken >= good_share);} void minimumK(vector &arr, int N, int M){ int good_share […]

Continue Readingimport java.util.*; class GFG { static double probability(int[] arr1, int[] arr2) { int N = arr1.length; int M = arr2.length; double res = 0; Arrays.sort(arr2); for (int i = 0; i < N; i++) { int y = countGreater( arr2, arr1[i]); res += y; } res = (double)res / (double)(N * M); return res; } static int countGreater(int[] arr, int k) { int n = arr.length; int l = 0; int r = n - 1; int leftGreater […]

Continue Reading#include using namespace std; int minAbsoluteSumDiff(vector A, vector B, int N){ int sum = 0; int diff[N]; for (int i = 0; i < N; i++) { diff[i] = abs(A[i] - B[i]); sum += diff[i]; } sort(A.begin(), A.end()); int bestDiff[N]; for (int i = 0; i < N; i++) { int j = lower_bound(A.begin(), A.end(), B[i]) - A.begin(); if (j != 0 && j != N) bestDiff[i] = min(abs(A[j] - […]

Continue ReadingSize of smallest square that contains N non-overlapping rectangles of given dimensions Given two positive integers W and H and N rectangles of dimension W*H, the task is to find the smallest size of the square required such that all the N rectangles can be packed without overlapping. Examples:Input: N = 10, W = 2, H […]

Continue Reading