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
In this tutorial, we will be discussing a program to find maximum subarray size, such that all subarrays of that size have sum less than k.For this we will be provided with an array of size N and an integer k. Our task is to find the length of subarray such that all the sub-arrays of that length in the given array sum to be less than or equal to k.Example Live Demo#include using namespace std; //finding maximum length subarray int bsearch(int prefixsum[], int n, int k) { int ans = -1; //performing binary search int left = ... Read More
In this tutorial, we will be discussing a program to find maximum students to pass after giving bonus to everybody and not exceeding 100 marks.For this we will be provided with an array containing marks of N students. Our task is to get more student pass the exam (50 marks required) by giving each student the same amount of bonus marks without any student exceeding 100 marks.Example Live Demo#include #include using namespace std; int check(int n, int marks[]) { int* x = std::max_element(marks, marks+5); int bonus = 100-(int)(*x); int c = 0; for(int i=0; i= 50) ... Read More
The java.util.function package defines several in-built functional interfaces that can be used when creating lambda expressions or method references.Inbuilt functional interfaces:1) Function InterfaceThe Function interface has only one single method apply(). It can accept an object of any data type and returns a result of any datatype.Exampleimport java.util.*; import java.util.function.*; public class FunctionTest { public static void main(String args[]) { String[] countries = {"India", "Australia", "England", "South Africa", "Srilanka", "Newzealand", "West Indies", "Scotland"}; Function converter = (all) -> { // lambda expression String names = ""; ... Read More