Saturday, 4 Dec 2021
Category: Arrays

Given an array vec[] of size N of non-negative integers. The task is to count the number of subsequences with the sum equal to S – 2 where S is the sum of all the elements of the array.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA […]

Given an array arr[] of size N and a value K, the task is to print the array rotated by K times to the right.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your […]

Given an array arr[] containing N integers, the task is to find the maximum sum obtained by adding the elements at the same index of the original array and of the reversed array.Example:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly […]

import java.util.*;  class GFG {          public static void main(String[] args)    {        int[][] interval            = { { 1, 3, 2 },                { 4, 5, 2 },                { 1, 5, 5 } };        int maxValue            = maxTwoNonOverLapping(interval);        System.out.println(maxValue);    }                  public static int maxTwoNonOverLapping(        int[][] interval)    {                        Arrays.sort(interval,                    (a, b) -> a – b);                                          PriorityQueue pq            = new PriorityQueue(                (a, b) -> a – b);                          int max = 0;        int ans = 0;                  for (int[] e : interval) {            while (!pq.isEmpty()) […]

Given an array arr[], the task is to print the indices that have the highest probability of holding the entire sum of the array after performing the given operations: Choose any two elements say arr[i] and arr[j], store their sum in a variable KAssign K at index of max(arr[i], arr[j]) and assign 0 at index of […]

#include using namespace std;int possibleCombinations(int arr1[], int arr2[], int N){        unordered_map mp;                    for (int i = 0; i < N; i++) {        mp[arr1[i]] = arr2[i];    }            int count = 1;            vector visited(N + 1, 0);    for (int i = 1; i

Given a binary array arr[] of N integers and an integer P, the task is to find the minimum cost to reach the end of the array from Pth index using jumps of length K. A jump to index i is valid if arr[i] = 1. The array can be modified using the following operations:Replace […]

Given an array arr[], the task is to calculate the minimum number of starting elements to choose from such that all other elements of the array can be visited. An element can be visited by another element only if the ratio of their values is not inversely proportional to the position of those elements in […]

Given a binary array arr1[] and an integer array arr2[], each of length N, the task is to rearrange the elements in the array arr2 such that the total cost generated is maximized. The total cost generated is calculated by summation of modified values in the arr2 array. The values are modified in such a […]

Given an array arr[] of size N, the task is to find the value of an integer K such that its repeated subtraction from array elements will make all array elements in minimum operations.Example:Input: arr[] = {5, 3, 3, 7}Output: 2Explanation: Minimum 2 operations must be performed:1st operation: subtract 2 from elements at indices {0, […]