From 004daad9af171a4cdcd5efa8d9cb8ccae320f419 Mon Sep 17 00:00:00 2001 From: Amulya Saxena <56781866+Amulya310@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:11:15 +0530 Subject: [PATCH 1/9] Added Node Deletion from BST#107 Solution for #issue107 Hey, I've added the code for node deletion from BST in CPP. This is a small contribution under GSSOC'21. I've also included a brief description ,multiline comments and 3 test cases( inputs and outputs ) in my code. --- Tree/node_deletion_BST.cpp | 177 +++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 Tree/node_deletion_BST.cpp diff --git a/Tree/node_deletion_BST.cpp b/Tree/node_deletion_BST.cpp new file mode 100644 index 000000000..57f1e0af5 --- /dev/null +++ b/Tree/node_deletion_BST.cpp @@ -0,0 +1,177 @@ +// C++ program to delete a node in binary search tree!!! +//brief description of the concept of deletion- +/*When we delete a node, three possibilities arise. +1) Node to be deleted is leaf: Simply remove from the tree. + + 5 5 + / \ delete(2) / \ + 3 7 ---------> 3 7 + / \ / \ \ / \ + 2 4 6 8 4 6 8 +2) Node to be deleted has only one child: Copy the child to the node and delete the child + + 5 5 + / \ delete(3) / \ + 3 7 ---------> 4 7 + \ / \ / \ + 4 6 8 6 8 +3) Node to be deleted has two children: Find inorder successor of the node. Copy contents of the inorder +successor to the node and delete the inorder successor. Note that inorder predecessor can also be used. + + + 5 6 + / \ delete(5) / \ + 4 7 ---------> 4 7 + / \ \ + 6 8 8 +The important thing to note is, inorder successor is needed only when right child is not empty. +In this particular case, inorder successor can be obtained by finding the minimum value in right child +of the node.*/ + +//code +#include +using namespace std; + +struct node { + int key; + struct node *l,*r; +}; + +//Function to create a new BST node + +struct node* new_node(int value) +{ + struct node* temp + = (struct node*)malloc(sizeof(struct node)); + temp->key = value; + temp->l = temp->r = NULL; + return temp; +} + +//Inorder traversal of BST +void inorder(struct node* root) +{ + if (root != NULL) { + inorder(root->l); + cout << root->key; + inorder(root->r); + } +} + +//Function to insert a new node with given key in BST// + +struct node* insert(struct node* node, int key) +{ + //If the tree is empty, return a new node // + if (node == NULL) + return new_node(key); + + // Otherwise, recur down the tree // + if (key < node->key) + node->l = insert(node->l, key); + else + node->r = insert(node->r, key); + + //return the (unchanged) node pointer // + return node; +} +//function to search for the minimum value in the BST +struct node* minValueNode(struct node* node) +{ + struct node* present = node; + + /* loop down to find the leftmost leaf */ + while (present && present->l!= NULL) + present = present->l; + + return present; +} + +/* Given a binary search tree and a key, this function +deletes the key and returns the new root */ +struct node* deleteNode(struct node* root, int key) +{ + // base case + if (root == NULL) + return root; + + // If the key to be deleted is + // smaller than the root's + // key, then it lies in left subtree + if (key < root->key) + root->l = deleteNode(root->l, key); + + // If the key to be deleted is + // greater than the root's + // key, then it lies in right subtree + else if (key > root->key) + root->r = deleteNode(root->r, key); + + // if key is same as root's key, then this is the node to be deleted + else { + // node with only one child or no child + if (root->l == NULL) { + struct node* temp = root->r; + free(root); + return temp; + } + else if (root->r == NULL) { + struct node* temp = root->l; + free(root); + return temp; + } + + // node with two children: Get the inorder successor + // (smallest in the right subtree) + struct node* temp = minValueNode(root->r); + + // Copy the inorder successor's content to this node + root->key = temp->key; + + // Delete the inorder successor + root->r = deleteNode(root->r, temp->key); + } + return root; +} + +// Driver Code +int main() +{ + struct node* root = NULL; + root = insert(root, 1); + root = insert(root, 5); + root = insert(root, 2); + root = insert(root, 7); + root = insert(root, 14); + root = insert(root, 9); + + cout << "Inorder traversal of the given tree \n"; + inorder(root); + + cout << "\nDelete 2\n"; + root = deleteNode(root,2); + cout << "Inorder traversal of the modified tree \n"; + inorder(root); + + cout << "\nDelete 5\n"; + root = deleteNode(root, 5); + cout << "Inorder traversal of the modified tree \n"; + inorder(root); + + cout << "\nDelete 14\n"; + root = deleteNode(root, 14); + cout << "Inorder traversal of the modified tree \n"; + inorder(root); + + return 0; +} + +/*test cases- +1.input-2 + output-157914 + +2.input-5 + output-17914 + +3.input-14 + output-179 */ From da6b664c69aff012f032a8febdfcedb7ae2b35b2 Mon Sep 17 00:00:00 2001 From: Amulya Saxena <56781866+Amulya310@users.noreply.github.com> Date: Wed, 17 Mar 2021 10:50:46 +0530 Subject: [PATCH 2/9] Added Check Palindrome -C++ #1096 Solution for #issue1096 Hey, I've added the code for palindrome check separately for numbers and strings in CPP. This is a small contribution under GSSOC'21. I've also included a brief description ,multiline comments and 3 test cases( inputs and outputs ) in my code. --- C++palindrome_1.cpp | 41 ++++++++++++++++++++ C++palindrome_2.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 C++palindrome_1.cpp create mode 100644 C++palindrome_2.cpp diff --git a/C++palindrome_1.cpp b/C++palindrome_1.cpp new file mode 100644 index 000000000..5b7d391fc --- /dev/null +++ b/C++palindrome_1.cpp @@ -0,0 +1,41 @@ + +#include +using namespace std; + +//palindrome check for a number!!! +/*This program reverses an integer (entered by the user) using while loop. Then, if statement is +used to check whether the reversed number is equal to the original number or not.*/ + +//driver code +int main() +{ + int n, num, digit, rev = 0; + + cout << "Enter a positive number of your choice: "; //taking input from the user + cin >> num; + + n = num; + + do //do while loop to reverse the digits of the number + { + digit = num % 10; + rev = (rev * 10) + digit; + num = num / 10; + } while (num != 0); + + cout << " The reverse of the number is: " << rev << endl; + + if (n== rev) //checking if the reversed number is same as the original input number + cout << " The number is a palindrome!!!"; + else + cout << " The number is not a palindrome!!!"; + + return 0; +} +/*test cases- + 1.input-121 + output-The number is a palindrome!!! + 2.input-34567 + output-The number is not a palindrome!!! + 3.input-123454321 + output-The number is a palindrome!!! */ diff --git a/C++palindrome_2.cpp b/C++palindrome_2.cpp new file mode 100644 index 000000000..2cc7c00d0 --- /dev/null +++ b/C++palindrome_2.cpp @@ -0,0 +1,93 @@ +//c++ program to check whether a string is a palindrome or not + +/*Find the length of the string say l. Now, find the mid as mid = l / 2. +Push all the elements till mid into the stack i.e. str[0…mid-1]. +If the length of the string is odd then neglect the middle character. +Till the end of the string, keep popping elements from the stack and compare +it with the current character i.e. string[i]. +If there is mismatch then the string is not a palindrome. +If all the elements match then the string is a palindrome.*/ + +#include +#include +#include +#include +#include + +using namespace std; + +char* stack; +int top = -1; + +// push function +void push(char el) +{ + stack[++top] = el; +} + +// pop function +char pop() +{ + return stack[top--]; +} + +// Function that returns 1 +// if str is a palindrome +int isPalindrome(char str[]) +{ + int length = strlen(str); + + // Allocating the memory for the stack + stack = (char*)malloc(length * sizeof(char)); + + // Finding the mid + int i, mid = length / 2; + + for (i = 0; i < mid; i++) { + push(str[i]); + } + + // Checking if the length of the string + // is odd, if odd then neglect the + // middle character + if (length % 2 != 0) { + i++; + } + + // While not the end of the string + while (str[i] != '\0') { + char el = pop(); + + // If the characters differ then the + // given string is not a palindrome + if (el!= str[i]) + return 0; + i++; + } + + return 1; +} + +// Driver code +int main() +{ + char str[100]; + cout<<"Enter a string of your choice: "<>str; + if (isPalindrome(str)) { + cout<<"Yes"< Date: Wed, 17 Mar 2021 11:03:25 +0530 Subject: [PATCH 3/9] Delete C++palindrome_1.cpp --- C++palindrome_1.cpp | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 C++palindrome_1.cpp diff --git a/C++palindrome_1.cpp b/C++palindrome_1.cpp deleted file mode 100644 index 5b7d391fc..000000000 --- a/C++palindrome_1.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include -using namespace std; - -//palindrome check for a number!!! -/*This program reverses an integer (entered by the user) using while loop. Then, if statement is -used to check whether the reversed number is equal to the original number or not.*/ - -//driver code -int main() -{ - int n, num, digit, rev = 0; - - cout << "Enter a positive number of your choice: "; //taking input from the user - cin >> num; - - n = num; - - do //do while loop to reverse the digits of the number - { - digit = num % 10; - rev = (rev * 10) + digit; - num = num / 10; - } while (num != 0); - - cout << " The reverse of the number is: " << rev << endl; - - if (n== rev) //checking if the reversed number is same as the original input number - cout << " The number is a palindrome!!!"; - else - cout << " The number is not a palindrome!!!"; - - return 0; -} -/*test cases- - 1.input-121 - output-The number is a palindrome!!! - 2.input-34567 - output-The number is not a palindrome!!! - 3.input-123454321 - output-The number is a palindrome!!! */ From aa8dcd484e0021587f5874a1357470b61e6b47d0 Mon Sep 17 00:00:00 2001 From: Amulya Saxena <56781866+Amulya310@users.noreply.github.com> Date: Wed, 17 Mar 2021 11:03:51 +0530 Subject: [PATCH 4/9] Delete C++palindrome_2.cpp --- C++palindrome_2.cpp | 93 --------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 C++palindrome_2.cpp diff --git a/C++palindrome_2.cpp b/C++palindrome_2.cpp deleted file mode 100644 index 2cc7c00d0..000000000 --- a/C++palindrome_2.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//c++ program to check whether a string is a palindrome or not - -/*Find the length of the string say l. Now, find the mid as mid = l / 2. -Push all the elements till mid into the stack i.e. str[0…mid-1]. -If the length of the string is odd then neglect the middle character. -Till the end of the string, keep popping elements from the stack and compare -it with the current character i.e. string[i]. -If there is mismatch then the string is not a palindrome. -If all the elements match then the string is a palindrome.*/ - -#include -#include -#include -#include -#include - -using namespace std; - -char* stack; -int top = -1; - -// push function -void push(char el) -{ - stack[++top] = el; -} - -// pop function -char pop() -{ - return stack[top--]; -} - -// Function that returns 1 -// if str is a palindrome -int isPalindrome(char str[]) -{ - int length = strlen(str); - - // Allocating the memory for the stack - stack = (char*)malloc(length * sizeof(char)); - - // Finding the mid - int i, mid = length / 2; - - for (i = 0; i < mid; i++) { - push(str[i]); - } - - // Checking if the length of the string - // is odd, if odd then neglect the - // middle character - if (length % 2 != 0) { - i++; - } - - // While not the end of the string - while (str[i] != '\0') { - char el = pop(); - - // If the characters differ then the - // given string is not a palindrome - if (el!= str[i]) - return 0; - i++; - } - - return 1; -} - -// Driver code -int main() -{ - char str[100]; - cout<<"Enter a string of your choice: "<>str; - if (isPalindrome(str)) { - cout<<"Yes"< Date: Wed, 17 Mar 2021 11:10:15 +0530 Subject: [PATCH 5/9] Added Check Palindrome -C++ #1096 Solution for #issue1096 Hey, I've added the code for palindrome check separately for numbers and strings in CPP. This is a small contribution under GSSOC'21. I've also included a brief description ,multiline comments and 3 test cases( inputs and outputs ) in my code. --- string/C++palindrome_1.cpp | 41 +++++++++++++++++ string/C++palindrome_2.cpp | 93 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 string/C++palindrome_1.cpp create mode 100644 string/C++palindrome_2.cpp diff --git a/string/C++palindrome_1.cpp b/string/C++palindrome_1.cpp new file mode 100644 index 000000000..5b7d391fc --- /dev/null +++ b/string/C++palindrome_1.cpp @@ -0,0 +1,41 @@ + +#include +using namespace std; + +//palindrome check for a number!!! +/*This program reverses an integer (entered by the user) using while loop. Then, if statement is +used to check whether the reversed number is equal to the original number or not.*/ + +//driver code +int main() +{ + int n, num, digit, rev = 0; + + cout << "Enter a positive number of your choice: "; //taking input from the user + cin >> num; + + n = num; + + do //do while loop to reverse the digits of the number + { + digit = num % 10; + rev = (rev * 10) + digit; + num = num / 10; + } while (num != 0); + + cout << " The reverse of the number is: " << rev << endl; + + if (n== rev) //checking if the reversed number is same as the original input number + cout << " The number is a palindrome!!!"; + else + cout << " The number is not a palindrome!!!"; + + return 0; +} +/*test cases- + 1.input-121 + output-The number is a palindrome!!! + 2.input-34567 + output-The number is not a palindrome!!! + 3.input-123454321 + output-The number is a palindrome!!! */ diff --git a/string/C++palindrome_2.cpp b/string/C++palindrome_2.cpp new file mode 100644 index 000000000..2cc7c00d0 --- /dev/null +++ b/string/C++palindrome_2.cpp @@ -0,0 +1,93 @@ +//c++ program to check whether a string is a palindrome or not + +/*Find the length of the string say l. Now, find the mid as mid = l / 2. +Push all the elements till mid into the stack i.e. str[0…mid-1]. +If the length of the string is odd then neglect the middle character. +Till the end of the string, keep popping elements from the stack and compare +it with the current character i.e. string[i]. +If there is mismatch then the string is not a palindrome. +If all the elements match then the string is a palindrome.*/ + +#include +#include +#include +#include +#include + +using namespace std; + +char* stack; +int top = -1; + +// push function +void push(char el) +{ + stack[++top] = el; +} + +// pop function +char pop() +{ + return stack[top--]; +} + +// Function that returns 1 +// if str is a palindrome +int isPalindrome(char str[]) +{ + int length = strlen(str); + + // Allocating the memory for the stack + stack = (char*)malloc(length * sizeof(char)); + + // Finding the mid + int i, mid = length / 2; + + for (i = 0; i < mid; i++) { + push(str[i]); + } + + // Checking if the length of the string + // is odd, if odd then neglect the + // middle character + if (length % 2 != 0) { + i++; + } + + // While not the end of the string + while (str[i] != '\0') { + char el = pop(); + + // If the characters differ then the + // given string is not a palindrome + if (el!= str[i]) + return 0; + i++; + } + + return 1; +} + +// Driver code +int main() +{ + char str[100]; + cout<<"Enter a string of your choice: "<>str; + if (isPalindrome(str)) { + cout<<"Yes"< Date: Wed, 17 Mar 2021 11:20:04 +0530 Subject: [PATCH 6/9] Delete C++palindrome_1.cpp --- string/C++palindrome_1.cpp | 41 -------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 string/C++palindrome_1.cpp diff --git a/string/C++palindrome_1.cpp b/string/C++palindrome_1.cpp deleted file mode 100644 index 5b7d391fc..000000000 --- a/string/C++palindrome_1.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include -using namespace std; - -//palindrome check for a number!!! -/*This program reverses an integer (entered by the user) using while loop. Then, if statement is -used to check whether the reversed number is equal to the original number or not.*/ - -//driver code -int main() -{ - int n, num, digit, rev = 0; - - cout << "Enter a positive number of your choice: "; //taking input from the user - cin >> num; - - n = num; - - do //do while loop to reverse the digits of the number - { - digit = num % 10; - rev = (rev * 10) + digit; - num = num / 10; - } while (num != 0); - - cout << " The reverse of the number is: " << rev << endl; - - if (n== rev) //checking if the reversed number is same as the original input number - cout << " The number is a palindrome!!!"; - else - cout << " The number is not a palindrome!!!"; - - return 0; -} -/*test cases- - 1.input-121 - output-The number is a palindrome!!! - 2.input-34567 - output-The number is not a palindrome!!! - 3.input-123454321 - output-The number is a palindrome!!! */ From 64d2634b2f3a6fb5ee311d64124abdfacf110e60 Mon Sep 17 00:00:00 2001 From: Amulya Saxena <56781866+Amulya310@users.noreply.github.com> Date: Wed, 17 Mar 2021 11:20:19 +0530 Subject: [PATCH 7/9] Delete C++palindrome_2.cpp --- string/C++palindrome_2.cpp | 93 -------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 string/C++palindrome_2.cpp diff --git a/string/C++palindrome_2.cpp b/string/C++palindrome_2.cpp deleted file mode 100644 index 2cc7c00d0..000000000 --- a/string/C++palindrome_2.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//c++ program to check whether a string is a palindrome or not - -/*Find the length of the string say l. Now, find the mid as mid = l / 2. -Push all the elements till mid into the stack i.e. str[0…mid-1]. -If the length of the string is odd then neglect the middle character. -Till the end of the string, keep popping elements from the stack and compare -it with the current character i.e. string[i]. -If there is mismatch then the string is not a palindrome. -If all the elements match then the string is a palindrome.*/ - -#include -#include -#include -#include -#include - -using namespace std; - -char* stack; -int top = -1; - -// push function -void push(char el) -{ - stack[++top] = el; -} - -// pop function -char pop() -{ - return stack[top--]; -} - -// Function that returns 1 -// if str is a palindrome -int isPalindrome(char str[]) -{ - int length = strlen(str); - - // Allocating the memory for the stack - stack = (char*)malloc(length * sizeof(char)); - - // Finding the mid - int i, mid = length / 2; - - for (i = 0; i < mid; i++) { - push(str[i]); - } - - // Checking if the length of the string - // is odd, if odd then neglect the - // middle character - if (length % 2 != 0) { - i++; - } - - // While not the end of the string - while (str[i] != '\0') { - char el = pop(); - - // If the characters differ then the - // given string is not a palindrome - if (el!= str[i]) - return 0; - i++; - } - - return 1; -} - -// Driver code -int main() -{ - char str[100]; - cout<<"Enter a string of your choice: "<>str; - if (isPalindrome(str)) { - cout<<"Yes"< Date: Tue, 23 Mar 2021 09:55:16 +0530 Subject: [PATCH 8/9] Added Palindrome Check #1096 Cpp solution for palindrome check. Code for numbers and strings included separately .Consider it a small contribution under GSSOC'21.I've also included a brief description ,multiline comments and 3 test cases(inputs and outputs) in my code. --- C++palindrome_1.cpp | 41 ++++++++++++++++++++ C++palindrome_2.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 C++palindrome_1.cpp create mode 100644 C++palindrome_2.cpp diff --git a/C++palindrome_1.cpp b/C++palindrome_1.cpp new file mode 100644 index 000000000..5b7d391fc --- /dev/null +++ b/C++palindrome_1.cpp @@ -0,0 +1,41 @@ + +#include +using namespace std; + +//palindrome check for a number!!! +/*This program reverses an integer (entered by the user) using while loop. Then, if statement is +used to check whether the reversed number is equal to the original number or not.*/ + +//driver code +int main() +{ + int n, num, digit, rev = 0; + + cout << "Enter a positive number of your choice: "; //taking input from the user + cin >> num; + + n = num; + + do //do while loop to reverse the digits of the number + { + digit = num % 10; + rev = (rev * 10) + digit; + num = num / 10; + } while (num != 0); + + cout << " The reverse of the number is: " << rev << endl; + + if (n== rev) //checking if the reversed number is same as the original input number + cout << " The number is a palindrome!!!"; + else + cout << " The number is not a palindrome!!!"; + + return 0; +} +/*test cases- + 1.input-121 + output-The number is a palindrome!!! + 2.input-34567 + output-The number is not a palindrome!!! + 3.input-123454321 + output-The number is a palindrome!!! */ diff --git a/C++palindrome_2.cpp b/C++palindrome_2.cpp new file mode 100644 index 000000000..2cc7c00d0 --- /dev/null +++ b/C++palindrome_2.cpp @@ -0,0 +1,93 @@ +//c++ program to check whether a string is a palindrome or not + +/*Find the length of the string say l. Now, find the mid as mid = l / 2. +Push all the elements till mid into the stack i.e. str[0…mid-1]. +If the length of the string is odd then neglect the middle character. +Till the end of the string, keep popping elements from the stack and compare +it with the current character i.e. string[i]. +If there is mismatch then the string is not a palindrome. +If all the elements match then the string is a palindrome.*/ + +#include +#include +#include +#include +#include + +using namespace std; + +char* stack; +int top = -1; + +// push function +void push(char el) +{ + stack[++top] = el; +} + +// pop function +char pop() +{ + return stack[top--]; +} + +// Function that returns 1 +// if str is a palindrome +int isPalindrome(char str[]) +{ + int length = strlen(str); + + // Allocating the memory for the stack + stack = (char*)malloc(length * sizeof(char)); + + // Finding the mid + int i, mid = length / 2; + + for (i = 0; i < mid; i++) { + push(str[i]); + } + + // Checking if the length of the string + // is odd, if odd then neglect the + // middle character + if (length % 2 != 0) { + i++; + } + + // While not the end of the string + while (str[i] != '\0') { + char el = pop(); + + // If the characters differ then the + // given string is not a palindrome + if (el!= str[i]) + return 0; + i++; + } + + return 1; +} + +// Driver code +int main() +{ + char str[100]; + cout<<"Enter a string of your choice: "<>str; + if (isPalindrome(str)) { + cout<<"Yes"< Date: Mon, 24 May 2021 10:00:07 +0530 Subject: [PATCH 9/9] Add files via upload --- longest bitonic subsequence.cpp | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 longest bitonic subsequence.cpp diff --git a/longest bitonic subsequence.cpp b/longest bitonic subsequence.cpp new file mode 100644 index 000000000..857ed631c --- /dev/null +++ b/longest bitonic subsequence.cpp @@ -0,0 +1,67 @@ +/* +LONGEST BITONIC SUBSEQUENCE- +It is the longest subsequence in which array is sorted such that +it is first in increasing order to the peak and then in decreasing +order . + +*/ + +/* lbs() length of the Longest Bitonic Subsequence in + arr[] of size n. The function mainly creates two temporary arrays + lis[] and lds[] and returns the maximum lis[i] + lds[i] - 1. + + lis[i] -Longest Increasing subsequence ending with arr[i] + lds[i] -Longest decreasing subsequence starting with arr[i] +*/ +int lbs( int arr[], int n ) +{ + int i, j; + + /* Allocate memory for lis[] and initialize LIS values as 1 for + all indexes */ + int *lis = new int[n]; + for (i = 0; i < n; i++) + lis[i] = 1; + + /* Compute LIS values from left to right */ + for (i = 1; i < n; i++) + for (j = 0; j < i; j++) + if (arr[i] > arr[j] && lis[i] < lis[j] + 1) + lis[i] = lis[j] + 1; + + /* Allocate memory for lds and initialize LDS values for + all indexes */ + int *lds = new int [n]; + for (i = 0; i < n; i++) + lds[i] = 1; + + /* Compute LDS values from right to left */ + for (i = n-2; i >= 0; i--) + for (j = n-1; j > i; j--) + if (arr[i] > arr[j] && lds[i] < lds[j] + 1) + lds[i] = lds[j] + 1; + + + /* Return the maximum value of lis[i] + lds[i] - 1*/ + int max = lis[0] + lds[0] - 1; + for (i = 1; i < n; i++) + if (lis[i] + lds[i] - 1 > max) + max = lis[i] + lds[i] - 1; + return max; +} + +/* Driver program to test above function */ +int main() +{ + + int arr[]; + int n; + cout<<"enter the number of array element you want to enter"; + cin>>n; + for(int i=0;i>arr[i]; + } + cout<<"Length of LBS is "<