Found 33676 Articles for Programming

Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k in C++

Ayush Gupta
Updated on 09-Sep-2020 12:50:50

130 Views

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

Maximum Product Cutting | DP-36 in C++

Ayush Gupta
Updated on 09-Sep-2020 12:48:26

172 Views

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

Maximum power of jump required to reach the end of string in C++

Ayush Gupta
Updated on 09-Sep-2020 12:46:23

259 Views

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

Maximum possible time that can be formed from four digits in C++

Ayush Gupta
Updated on 09-Sep-2020 12:44:22

332 Views

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

Maximum possible sum of a window in an array such that elements of same window in other array are unique in c++

Ayush Gupta
Updated on 09-Sep-2020 12:41:24

109 Views

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

Get unique values from a list in Python

Pradeep Elance
Updated on 09-Sep-2020 12:36:28

3K+ Views

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

Maximum Possible Product in Array after performing given Operations in C++

Ayush Gupta
Updated on 09-Sep-2020 12:34:38

270 Views

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

Get last element of each sublist in Python

Pradeep Elance
Updated on 09-Sep-2020 12:33:34

2K+ Views

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

Get first element of each sublist in Python

Pradeep Elance
Updated on 09-Sep-2020 12:32:15

5K+ Views

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

Get first and last elements of a list in Python

Pradeep Elance
Updated on 09-Sep-2020 12:26:46

15K+ Views

There may be situation when you need to get the first and last element of the list. The tricky part here is you have to keep track of the length of the list while finding out these elements from the lists. Below are the approaches which we can use to achieve this. But of course all the approaches involve using the index of the elements in the list.Using only indexIn any list the first element is assigned index value 0 and the last element can be considered as a value -1. So we apply these index values to the list ... Read More

Advertisements