In this tutorial, we will be discussing a program to find maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k.For this we will be provided with an array and an integer k. Our task is to find the maximum product from the array given that the frequency sum of all digits must be smaller than or equal to 2 * k.Example Live Demo#include using namespace std; #define ll long long int //returning maximum product value ll maxProd(int arr[], int n, int k) { ll product ... Read More
In this tutorial, we will be discussing a program to find maximum Product Cutting | DP-36.For this we will be provided with a rope of N meters. Our task is to cut the rope in different integer lengths such that the product of their lengths is the maximumExample Live Demo#include using namespace std; //finding maximum of two, three integers int max(int a, int b) { return (a > b)? a : b; } int max(int a, int b, int c) { return max(a, max(b, c)); } //returning maximum product int maxProd(int n) { if (n == 0 ... Read More
In this tutorial, we will be discussing a program to find maximum power of jump required to reach the end of string.For this we will be provided with a string of 0s and 1s. Our task is to find the maximum jump required to move from front to end of string given you can move to the same element as current one.Example Live Demo#include using namespace std; //finding maximum power jump int powerOfJump(string s) { int count = 1; int max_so_far = INT_MIN; char ch = s[s.length() - 1]; for (int i = 0; i < s.length(); ... Read More
In this tutorial, we will be discussing a program to find maximum possible time that can be formed from four digits.For this we will be provided with an array consisting 4 digits. Our task is to find the maximum time (24 hour format) that can formed using those four digits.Example Live Demo#include using namespace std; //returning updated frequency map map getFrequencyMap(int arr[], int n) { map hashMap; for (int i = 0; i < n; i++) { hashMap[arr[i]]++; } return hashMap; } //checking if the digit is present in frequency map bool hasDigit(map* ... Read More
In this tutorial, we will be discussing a program to find maximum possible sum of a window in an array such that elements of same window in other array are unique.For this we will be provided with two arrays with equal number of elements. Our task is to find the window in one element with maximum sum such that the same window in other array is unique.Example Live Demo#include using namespace std; //returning maximum sum window int returnMaxSum(int A[], int B[], int n) { //storing elements with their count unordered_set mp; int result = 0; int ... Read More
A list in python is a number of items placed with in [] which may or may not have same data types. It can also contain duplicates. In this article we will see how to extract only the unique values from a list.With append()In this approach we will first create a new empty list and then keep appending elements to this new list only if it is not already present in this new list. A for loop is used along with not in condition. It checks for the existence of the incoming element and it is appended only if it ... Read More
In this tutorial, we will be discussing a program to find maximum Possible Product in Array after performing given OperationsFor this we will be provided with an array of size N. Our task is to perform N-1 operations (changing a[j] → a[i]*a[j] and remove a[i] value or just remove the value of a[i] (only once)) such that the remaining values are the maximum ones only.Example Live Demo#include using namespace std; //printing operations void MaximumProduct(int a[], int n) { int cntneg = 0; int cntzero = 0; int used[n] = { 0 }; int pos = -1; ... Read More
A list in python can also contain lists inside it as elements. These nested lists are called sublists. In this article we will solve the challenge of retrieving only the last element of each sublist in a given list.Using for loopIt is a very simple approach in which we loop through the sublists fetching the item at index -1 in them. A for loop is used for this purpose as shown below.Example Live DemoAlist = [['Mon', 1], ['Tue', 'Wed', "Fri"], [12, 3, 7]] print("Given List:", Alist) print("Lastst Items from sublists:") for item in Alist: print((item[-1]))OutputRunning the above code gives us ... Read More
A list in python can also contain lists inside it as elements. These nested lists are called sublists. In this article we will solve the challenge of retrieving only the first element of each sublist in a given list.Using for loopIt is a very simple approach in which we loop through the sublists fetching the item at index 0 in them. A for loop is used for this purpose as shown below.Example Live DemoAlist = [['Mon', 1], ['Tue', 'Wed', "Fri"], [12, 3, 7]] print("Given List:", Alist) print("First Items from sublists:") for item in Alist: print((item[0]))OutputRunning the above code gives us ... Read More
In this tutorial, we will be discussing a program to find maximum possible middle element of the array after deleting exactly k elementsFor this we will be provided with an array of size N and an integer K. Our task is to reduce K elements from the array such that the middle element of the resulting array is maximum.Example Live Demo#include using namespace std; //calculating maximum value of middle element int maximum_middle_value(int n, int k, int arr[]) { int ans = -1; int low = (n + 1 - k) / 2; int high = (n + ... Read More