
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 7197 Articles for C++

754 Views
Problem statementGiven an Array of Positive and Negative Integers, find out the Maximum Subarray Sum in that ArrayExampleIf input array is − {-12, -5, 4, -1, -7, 1, 8, -3} then output is 9AlgorithmCalculate the prefix sum of the input array.Initialize− min_prefix_sum = 0, res = -infiniteMaintain a loop for i = 0 to n. (n is the size of the input array).cand = prefix_sum[i] – miniIf cand is greater than res (maximum subarray sum so far), then update res by cand.If prefix_sum[i] is less than min_prefix_sum (minimum prefix sum so far), then update min_prefix_sum by prefix_sum[i].Return resExample Live Demo#include ... Read More

196 Views
In this problem, we are given an array and a number k. Our task is to create a program that will find the maximum subarray sum in an array formed by repeating the given array k time in c++.Problem description − Here, we will find the maximum sum of the subarray formed from array formed by repeating the given array k times.Let’s take an example to understand the problem, Input − array = {3, 5, 1} k = 2Output − 18Explanation −array formed by repeating k times, array = {3, 5, 1, 3, 5, 1} Maximum subarray sum = 3+5+1+3+5+1 ... Read More

450 Views
In this problem, we are given an array and an integer k. Our task is to create a program that will find the maximum subarray sum by flipping signs of at most k array elements in C++.Code description − Here, we will have to find at most k elements to flip in the array which will make the sum of subarray created from this array maximum.Let’s take an example to understand the problem, Input − array = {1, -2, 7, 0} k = 2Output − 10Explanation − we will flip only one element which is -2, it makes the array ... Read More

288 Views
In this problem, we are given an array. Our task is to create a program that will find the maximum subarray sum after inverting at most two elements in C++.Problem description − Here, we can have to find the subarray that will produce the maximum sum on inverting the sign of any two numbers of the array.Let’s take an example to understand the problem, Input − array = {-5, 1, 3, 8, -2, 4, 7}Output − 30Explanation − we will consider elements from index 0 to 6 and invert values -5 and -2 to get the array with max sum.To ... Read More

156 Views
In this problem, we are given an integer X. Our task is to find the total number of steps that are taken to transform from 0 to X.Valid transformation − One step is counted when one transformation takes place from A to B. The condition for the transform to take place is A != B and A & B = A (& is bitwise AND). So, 1 step is transforming from A to B and we have to create a program that will count the maximum number of steps to transform 0 to X.Let’s take an example to understand the ... Read More

2K+ Views
Suppose we have two integers dividend and divisor. We have to divide two integers without using multiplication, division, and mod operator. Return the quotient after dividing the dividend by divisor. The integer division should truncate toward zero. Both of the inputs are integersSo if the given inputs are dividend = 7, divisor = -3, then output will be -2.To solve this, we will follow these steps −Taking two arguments x and y it indicates x divides yif x < -Infinity and y = 1, then return infinitya := |x|, b := |y| and ans := 0while a – b >= ... Read More

849 Views
Consider we have a linked list. We have to swap every two adjacent nodes and return its head. The constraint is that we cannot modify the value of the nodes, only the node itself can be changed. So if the list is like [1, 2, 3, 4], then the resultant list will be [2, 1, 4, 3]To solve this, we will follow these steps −if head is not present, then return headfirst := head, second := next of head, dummy is one new node with value -1next of dummy := first, and prev := dummywhile second is not nulltemp := ... Read More

610 Views
4SUM ProblemThe 4Sum is one of the problem variations in which we need to find the number of quadruplets present in the array such that their sum is equal to the given target. We are given an array of n integers called nums and a target value, and we have to find the number of index quadruplets (i, j, k, l) where i, j, k, and l are all indices in the range 0 to n - 1, such that they satisfy the condition: nums[i] + nums[j] + nums[k] + nums[l] = target Scenario 1 Inputs: arr= [-1, 0, 1, 2, ... Read More

89 Views
In C++ standard template libraray(STL), iswctype() function is used to check if the given wide character has property specified by desc.Iswctype() is an in built function whose header file is “ctype.h”.Syntax of Iswctype() is as followsint iswctype(wint_t c, wctype_t desc); iswctype () / Checks whether whether c has the property specified by desc. /Synopsisint iswctype(wint_t c, wctype_t desc);ParametersC − To check the wide characters which are casted to the integral type wint_tDesc − It is a value which is returned by the call to wctype, which is a scalar type which is used as return type for wctype(Wide character type).Return ... Read More

135 Views
In C++ standard template library(STL), iswlower() function is used to check if the given wide character is in lowercase or not, if not then the function will return a zero value. The characters with ASCII value from 97 to 122 i.e. a-z are the lowercase alphabetic letters. Iswlower() function is present in cctype header file in C/C++.Syntax of iswlower () is as followsint iswlower (wint_t c)Parameters − c is a wide character to be checked, casted to a wint_t, or WEOF where wint_t is an integral type.Return Value − islower() function return non-zero value when the string is in lowercase ... Read More