Find Maximum Number of Elements with Absolute Difference ≤ 1 in C++

Arnab Chakraborty
Updated on 18-Dec-2019 10:11:28

392 Views

Suppose we have an array of n elements. We have to find the maximum number of elements to select from the array, such that the absolute difference between any two of the chosen elements is less than or equal to 1. So if the array is like [2, 2, 3, 4, 5], then the element will be 3, so the sequence with maximum count is 2, 2, 3.The absolute difference of 0 and 1 means, that the number can be of type x and x + 1. So the idea is to store the frequencies of array elements. So if ... Read More

Sort in C++ Standard Template Library (STL)

Arnab Chakraborty
Updated on 18-Dec-2019 10:09:23

749 Views

Here we will see how to use the sort() function of C++ STL to sort an array So if the array is like A = [52, 14, 85, 63, 99, 54, 21], then the output will be [14 21 52 54 63 85 99]. To sort we will use the sort() function, that is present in the header file . The code is like below −Example Live Demo#include #include using namespace std; int main() {    int arr[] = {52, 14, 85, 63, 99, 54, 21};    int n = sizeof(arr) / sizeof(arr[0]);    cout

Perform Null Check Using HANA SQL Script

Smita Kapse
Updated on 18-Dec-2019 10:06:46

4K+ Views

You can go for using either NULLIF or COALESCE function to serve your requirement.NULLIF (expression, expression"): This function will return the same type whatever is specified as the first expression.Basically, NULLIF returnsThe first expression if the two expressions are not equal.NULL of type of first expressions if the expressions are equalThe other function available is COALESCE which basically checks if the first Value provided is NULL then it will return the second value.Examplec = COALESCE(b , a)If b is null then the function will return an otherwise b. So If you need to put a null check and use some ... Read More

Delete Duplicate Alphanumeric Entries from Column Data in SQL

Nitya Raut
Updated on 18-Dec-2019 10:05:14

217 Views

You can opt for using regular expressions to remove the duplicate numbers from column c or any other intended column.ExampleSELECT REPLACE_REGEXPR ('([A-Za-z0-9])\1+' in 'BB11222343CC'    WITH '\1'    OCCURRENCE ALL) FROM OutputB12343C

Issue Regarding JCo SAP Server Out of Network

Jennifer Nicholas
Updated on 18-Dec-2019 10:03:48

250 Views

You need to perform the below actions when you are stopping the JCO server instanceDelete all the references of your server from ServerDataEventListener instance. If you need to use the reference, then you can use registered ServerDataProvider object to fetch reference of ServerDataEventListener instance.Delete all the references of your destination from DestinationDataEventListener instance. If you need to use the reference, then you can use registered DestinationDataProvider object to fetch the DestinationDataEventListener instance.

Refer and Import SAP UI Core.js in SAPUI5 Project

Vrundesha Joshi
Updated on 18-Dec-2019 10:03:04

470 Views

The SAPUI5 library files are a part of Eclipse SAPUI5 plug-in.If you are running the app by using the Web App preview on the startup page ( Go to Run As -> select “Web APP Preview”), then eclipse starts a local HTTP server for development which serves at “/resources” the library.Till the preview window is open, you can go ahead and use the URL in any browser of your choice to debug the application.

Call Event Function from Another Method in Controller in SAP

Nancy Den
Updated on 18-Dec-2019 10:02:35

723 Views

It is advised not to call the event function from any other function but what you can do is refactor the event function implementation in a separate function and call that from any other function as shown below:ExampleBtnPress: function(oEvent) {    // Separate the implementation in the helper function    this.btnPressHelper(); } // Define the helper btnPressHelper: function() {    //logic here } // call the helper from whichever function you want to get the desired output PerformSomething: function() {    this.btnTapHelper(); }

Find Length of Longest Subsequence of One String Which is Substring of Another String in C++

Arnab Chakraborty
Updated on 18-Dec-2019 09:40:29

2K+ Views

Suppose, we have two strings X and Y, and we have to find the length of longest subsequence of string X, which is substring in sequence Y. So if X = “ABCD” and Y = “BACDBDCD”, then output will be 3. As “ACD” is the longest sub-sequence of X, which is substring of Y.Here we will use the dynamic programming approach to solve this problem. So if the length of X is n, and length of Y is m, then create DP array of order (m+1)x(n+1). Value of DP[i, j] is maximum length of subsequence of X[0…j], which is substring ... Read More

Find Largest Special Prime Less Than or Equal to a Given Number in C++

Arnab Chakraborty
Updated on 18-Dec-2019 09:36:11

513 Views

Suppose we have a number n. We have to find the largest special prime which is less than or equal to N. The special prime is a number, which can be created by placing digits one after another, so all the resultant numbers are prime.Here we will use Sieve Of Eratosthenes. We will create the sieve array up to the number n. Then start iteratively back from the number N, by checking if the number is prime. When this is prime, check whether this is special prime or not.Example Live Demo#include using namespace std; bool isSpecialPrime(bool sieve[], int num) {   ... Read More

Find Index of 0 to Replace with 1 for Longest Sequence of 1s in Binary Array

Arnab Chakraborty
Updated on 18-Dec-2019 09:27:13

276 Views

Suppose, we have an array of N elements. These elements are either 0 or 1. Find the position of 0 to be replaced with 1 to get longest contiguous sequence of 1s. Suppose the array is like arr = [1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1], the output index is 9. Replacing 0 with 1 at index 9 cause the maximum contiguous sequence of 1sWe have to keep track of three indexes. current index(curr), previous zero index(pz), and previous to previous zero index (ppz). Now traverse the array when array element is 0, then ... Read More

Advertisements