In this tutorial, we will be discussing a program to find maximum sum alternating subsequence.For this we will be provided with an array of integers. Our task is to find the maximum sum of an alternating subsequence i.e sequence which is first decreasing, then increasing, then decreasing and so on.Example Live Demo#include using namespace std; //returning maximum sum alternating series int maxAlternateSum(int arr[], int n) { if (n == 1) return arr[0]; int dec[n]; memset(dec, 0, sizeof(dec)); int inc[n]; memset(inc, 0, sizeof(inc)); dec[0] = inc[0] = arr[0]; int flag = 0 ; for (int i=1; i
In this tutorial, we will be discussing a program to find maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST.For this we will be provided with a binary tree. Our task is to print the sum of a sub-tree which is also a binary search tree.Example Live Demo#include using namespace std; //creating binary tree node struct Node { struct Node* left; struct Node* right; int data; Node(int data) { this->data = data; this->left = NULL; this->right = NULL; } }; struct Info ... Read More
In this tutorial, we will be discussing a program to find maximum subsequence sum such that no three are consecutive.For this we will be provided with a series of positive integers. Our task is to find the maximum sum without taking in their consecutive positive integers in the sum value.Example Live Demo#include using namespace std; //returning maximum subsequence without involving //three consecutive numbers int maxSumWO3Consec(int arr[], int n) { int sum[n]; if (n >= 1) sum[0] = arr[0]; if (n >= 2) sum[1] = arr[0] + arr[1]; if (n > 2) sum[2] = max(sum[1], max(arr[1] + arr[2], ... Read More
In this tutorial, we will be discussing a program to find maximum sub-matrix area having count of 1’s one more than count of 0’s.For this we will be provided with a matrix containing 0’s and 1’s. Our task is to get the sub-matrix of maximum area containing more 1’s than 0’sExample Live Demo#include using namespace std; #define SIZE 10 //finding length of longest sub-matrix int lenOfLongSubarr(int arr[], int n, int& start, int& finish) { unordered_map um; int sum = 0, maxLen = 0; for (int i = 0; i < n; i++) { sum ... Read More
An interface defined with only one abstract method is known as Functional Interface. It's not mandatory to mark the functional interface with @FunctionalInterface annotation, the compiler doesn't throw any error. But it’s good practice to use @FunctionalInterface annotation to avoid the addition of extra methods accidentally. If an interface annotated with @FunctionalInterface annotation and more than one abstract method then it throws a compile-time error.Syntax@FunctionalInterface interface interface_name { // only one abstarct method declaration }Example@FunctionalInterface interface Shape { void printArea(int x); } public class SquareTest { public static void main (String args[]) { Shape square ... Read More
The lambda expression composed of two parts, one is an argument and another one is code or expression. These two parts have separated by an arrow operator "->". We can use different IDE's like Netbeans, IntelliJ, and Eclipse to debug the lambda expressions in Java. It is always possible to create multi-line lambda expressions and use print statements to display the values of a variable. The debugger can also provide additional information about the state of a java program. It allows some variables to be modified while the debugger is executing.Syntax(parameters) -> expression or (parameters) -> { statements; }Exampleimport java.util.*; public class LambdaDebugTest { ... Read More
In this tutorial, we will be discussing a program to find maximum subarray sum in an array created after repeated concatenation.For this we will be provided with an array and an integer K. Our task is to find the subarray with the maximum elements when the given array is repeated K times.Example Live Demo#include using namespace std; //returning sum of maximum subarray int maxSubArraySumRepeated(int a[], int n, int k) { int max_so_far = INT_MIN, max_ending_here = 0; for (int i = 0; i < n*k; i++) { max_ending_here = max_ending_here + a[i%n]; if ... Read More
Lambda expression is an anonymous method that has used to provide an implementation of a method defined by a functional interface. In Java 8, it is also possible for the body of a lambda expression to be a complex expression or statement, which means a lambda expression consisting of more than one line. In that case, the semicolons are necessary. If the lambda expression returns a result then the return keyword is also required.Syntax([comma seperated argument-list]) -> { multiline statements }Exampleinterface Employee { String displayName(String s); } public class MultilineLambdaTest { public static void main(String[] s) { ... Read More
In this tutorial, we will be discussing a program to find maximum Subarray Sum Excluding Certain Elements.For this we will be provided with two arrays of size M and N. Our task is to find a sub-array in the first array such that no element inside the subarray is present inside the second array and the elements of subarray sum up to be maximum.Example Live Demo#include using namespace std; //checking if element is present in second array bool isPresent(int B[], int m, int x) { for (int i = 0; i < m; i++) if (B[i] == x) ... Read More
Yes, using the below syntax −select * from information_schema.tables where table_name=yourTableName;Let us first create a table −mysql> create table DemoTable1600 -> ( -> StudentId int, -> StudentFirstName varchar(20) -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1600 values(100, 'Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1600 values(101, 'David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1600 values(102, 'Carol'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select * from ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP