Arnab Chakraborty has Published 4293 Articles

Find a permutation of 2N numbers such that the result of given expression is exactly 2K in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 06:45:42

102 Views

Suppose we have two integers N and K. We have to find first permutation of 2N number of natural numbers, such that the following equation is satisfied.$$\displaystyle\sum\limits_{i=1}^N\lvert A_{2i-1}-A_{2i}\rvert+\lvert \displaystyle\sum\limits_{i=1}^N A_{2i-1}-A_{2i} \rvert=2K$$The value of K should be less than or equal to N. For example, if N = 4 and K ... Read More

Find a local minima in an array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Dec-2019 06:43:41

481 Views

Suppose we have an array A with n elements. We have to find the local minima of the array. In array A, the element A[x] is said to be local minima if it is less than or equal to both of its neighbors. For corner elements only one neighbor will ... Read More

Comparing String objects using Relational Operators in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:31:15

465 Views

Here we will see how to compare two strings in C++. The C++ has string class. It also has the compare() function in the standard library to compare strings. But here we will use the conditional operators like ==, !=, , =. These operators check the strings character by characters. ... Read More

Code valid in both C and C++ but produce different output

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:26:14

122 Views

Here we will see some program that will return different results if they are compiled in C or C++ compilers. We can find many such programs, but here we are discussing about some of them.In C and C++, the character literals are treated as different manner. In C, they are ... Read More

Chrono in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:23:17

399 Views

In this section we will see what is the Chrono library in C++. This Chrono library is used for date and time. Timers and clocks are different in different systems. So if we want to improve time over precision we can use this library.In this library, it provides precision-neutral concept, ... Read More

How to use getline() in C++ when there are blank lines in input?

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:20:55

960 Views

In C++, we use the getline() function to read lines from stream. It takes input until the enter button is pressed, or user given delimiter is given. Here we will see how to take the new line character as input using the getline() function. Let us see the following implementation ... Read More

How to traverse a C++ set in reverse direction?

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:19:02

1K+ Views

Suppose we have a set, then we have to traverse the set in reverse direction. So if the set is like S = [10, 15, 26, 30, 35, 40, 48, 87, 98], then the output will be: 98 87 48 40 35 30 26 15 10.To traverse in reverse order, ... Read More

How to reverse an Array using STL in C++?

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:15:32

974 Views

Here we will see how to reverse an array using STL functions in C++. So if the array is like A = [10, 20, 30, 40, 50, 60], then the output will be B = [60, 50, 40, 30, 20, 10]. To reverse we have one function called reverse() present ... Read More

How to insert elements in C++ STL List?

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:13:46

531 Views

Suppose we have one STL list in C++. There are few elements. We have to insert a new element into the list. We can insert at the end, or beginning or at any position. Let us see one code to get better understanding. To insert at beginning we will use ... Read More

How to find the sum of elements of an Array using STL in C++?

Arnab Chakraborty

Arnab Chakraborty

Updated on 17-Dec-2019 13:11:17

384 Views

Here we will see how to find the sum of all element of an array. So if the array is like [12, 45, 74, 32, 66, 96, 21, 32, 27], then sum will be: 405. So here we have to use the accumulate() function to solve this problem. This function ... Read More

Advertisements