
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

869 Views
Suppose we have a binary tree we have to make a string consists of parenthesis and integers from a binary tree with the preorder traversing way. A null node will be represented by empty parenthesis pair "()". And we need to omit all the empty parenthesis pairs that don't affect the one-to-one mapping relationship between the string and the original binary tree.So, if the input is likethen the output will be 5(6()(8))(7)To solve this, we will follow these steps −ans := blank stringDefine a function pot(). This will take node, sif is null, thenreturn blank stringif if left or right ... Read More

198 Views
In this tutorial, we will be discussing a program to find maximum size rectangle binary sub-matrix with all 1s.For this we will be provided with 2D matrix containing zeroes and ones. Our task is to find the largest 2D matrix subset containing only ones.Example Live Demo#include using namespace std; #define R 4 #define C 4 //finding the maximum area int maxHist(int row[]) { stack result; int top_val; int max_area = 0; int area = 0; int i = 0; while (i < C) { if (result.empty() || row[result.top()]

190 Views
In this tutorial, we will be discussing a program to find maximum size of sub-array that satisfies the given condition.For this we will be provided with an array of integers. Our task is to find the maximum length subset of that array satisfying either of arr[k] > arr[k + 1] when k is odd and arr[k] < arr[k + 1] when k is even, arr[k] > arr[k + 1] when k is even and arr[k] < arr[k + 1] when k is odd.Example Live Demo#include using namespace std; //comparing values of a and b int cmp(int a, int b) { ... Read More

191 Views
In this problem, we are given an array arr[] of integers. Our task is to create a program to calculate the Maximum set bit sum in array without considering adjacent elements in C++.Problem description − Here, we have an array arr[]. We have to find the number of set bits for each number. Then, we will find the maximum set bit sum in adjacent elements of the array. i.e. maximum sum for a[i] + a[i+2] ….Let’s take an example to understand the problem, Inputarr[] = {1, 4, 6, 7}Output4ExplanationArray with the element’s in binary formarr[] = {01, 100, 101, 111} ... Read More

323 Views
In this problem, we are given a 2-D array arr[] consisting of boolean values (i.e 0’s and 1’s) and an integer K. Our task is to create a program to find the Maximum score after flipping a Binary Matrix atmost K times in C++.Problem Description − Here, for the 2-D array, and the k moves, we need to find the number that is created by the elements of the array. In each move, we will take a row or column and flip all the elements of the row or column. The choice will be done to keep in mind that ... Read More

273 Views
In this problem, we are given a 2-D array that contains rational numbers (one in each row). Our task is to create a program to calculate the maximum rational number (or fraction) from an array in C++.Problem Description − The 2-D array is of the form [n][2]. Each row has two integer values that denote the value of a and b in the equation of rational number, a/b. We need to find the greatest number out of all these rational numbers.Let’s take an example to understand the problem, Inputrat[][] = { {3, 2}, {5, 7}, {1, 9}, ... Read More

844 Views
In this problem, we are given an array stkprice[] that denotes the price of a certain stock on i-th day. Our task is to create a program to calculate Maximum profit after buying and selling the stocks in C++.Problem Description − Here, we need to check when can be bought and sell the stock to gain profit. To gain profit, we need to buy the stock at a low price and sell it when the price goes up. And repeat the same when the drop is encountered again.Let’s take an example to understand the problem, Inputstkprice[] = {120, 310, 405, ... Read More

205 Views
In this tutorial, we will be discussing a program to find maximum product subset of an array.For this we will be provided with an array containing positive and negative values. Our task is to find the maximum product for a subset of the array.Example Live Demo#include using namespace std; int maxProductSubset(int a[], int n) { if (n == 1) return a[0]; int max_neg = INT_MIN; int count_neg = 0, count_zero = 0; int prod = 1; for (int i = 0; i < n; i++) { ... Read More

199 Views
In this problem, we are given an array of integers(positive as well as negative). Our task is to create a program to calculate the Maximum Product Subarray in C++.Problem Solution − Here, we have an array that contains positive, negative, and zero numbers. We need to find the product of subarrays created by elements of the array. And maximize the product of the subarray.Let’s take an example to understand the problem, Inputarr[] = {-1, 2, -7, -5, 12, 6}Output5040ExplanationThe subarray with the maximum product is {2, -7, -5, 12, 6}Product = 5040Solution ApproachTo solve this problem, we are given an ... Read More

206 Views
In this problem, we are given an array arr[] of integers. Our task is to create a program to find the Maximum Product Subarray - Using Two Traversals in C++.Problem description − Here in the array, we will find the maximum product subarray using two traversals one from index 0 and another index (n-1).Let’s take an example to understand the problem, Inputarr[] = {4, -2, 5, -6, 0, 8}Output240ExampleSubarray = {4, -2, 5, -6} Maximum product = 4 * (-2) * 5 * (-6) = 240Solution ApproachTo solve this problem using two traversals. Here, we will find the maximum product ... Read More