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
C++ Articles - Page 342 of 719
639 Views
Suppose we have an array of non-negative integers called nums, the degree of this array is actually the maximum frequency of any one of its elements. We have to find the smallest possible length of a contiguous subarray of nums, that has the same degree as nums.So, if the input is like [1, 2, 2, 3, 1], then the output will be 2, this is because the input array has a degree of 2 because both elements 1 and 2 appear twice. The subarrays that have the same degree − [1, 2, 2, 3, 1], [1, 2, 2, 3], [2, ... Read More
809 Views
Suppose we have a string s, we have to find the count of contiguous substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. If substrings occur multiple times are counted the number of times they occur.So, if the input is like "11001100", then the output will be 6, as the substrings are "1100", "10", "0011", "01", "1100", "10".To solve this, we will follow these steps −Define an array cnt of size 2 and fill this with 0res := 0for initialize i := 0, when i ... Read More
468 Views
Suppose we have a positive integer, we have to check whether it has alternating bits − so, two adjacent bits will always have different values.So, if the input is like 10, then the output will be True, as binary representation of 10 is 1010.To solve this, we will follow these steps −p := n AND 1if n < 2, then −return truen := n/2while n is non-zero, do −c := n AND 1if c XOR p is same as 0, then −return falsep := cn := n/2return trueLet us see the following implementation to get better understanding −Example Live Demo#include ... Read More
858 Views
Suppose we have an array of integers; we have to find the length of longest continuous increasing subarray.So, if the input is like [2,4,6,5,8], then the output will be 3. As the longest continuous increasing subsequence is [2,4,6], and its length is 3.To solve this, we will follow these steps −if size of nums
610 Views
Suppose there is a non-empty special binary tree with some non-negative value, here each node in this tree has exactly two or zero children. If the node has two children, then this node's value is the smaller value among its two children. In other words, we can say that [root.val = minimum of root.left.val, root.right.val]. If we have such binary tree, we have to find the second minimum value in the set made of all the nodes' value in the whole tree. If there is no such element, then return -1 instead.So, if the input is likethen the output will ... Read More
211 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()]
196 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
203 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
328 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
284 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