Found 33676 Articles for Programming

Find the largest rectangle of 1’s with swapping of columns allowed in Python

Arnab Chakraborty
Updated on 20-Aug-2020 07:34:45

200 Views

Suppose we have a binary matrix, we have to find the largest rectangle of all 1's in that given matrix. The rectangle can be built by swapping or exchanging any pair of columns of that matrix.So, if the input is like100101001111010then the output will be the 6 in this case. The rectangle can be generating by exchanging column 1 with 3. The matrix after exchanging will be −001100011110110To solve this, we will follow these steps −row := size of matcol := size of mat[0]temp := a matrix of order (row + 1) x (col + 1), and fill with 0for ... Read More

Find the largest Perfect Subtree in a given Binary Tree in Python

Arnab Chakraborty
Updated on 20-Aug-2020 07:31:46

781 Views

Suppose we have a given Binary Tree; we have to find the size of largest Perfect sub-tree in that given Binary Tree. As we know the perfect binary tree is a binary tree in which all internal nodes have two children and all leaves are at the identical level.So, if the input is likethen the output will be 3, and the subtree isTo solve this, we will follow these steps −Define one block called RetType, this will hold isPerfect, height and rootTree, they are all initially 0Define a function called get_prefect_subtree(), this takes rootr_type := a new RetTypeif root is ... Read More

Find the largest multiple of 3 from array of digits - Set 2 in C++

Arnab Chakraborty
Updated on 20-Aug-2020 07:28:27

178 Views

Suppose we have an array of different digits; we have to find the largest multiple of 3 that can be generated by concatenating some of the given digits in that array in any order. The answer may be very large so make it as string. If there is no answer return an empty string.So, if the input is like [7, 2, 8], then the output will be 87.To solve this, we will follow these steps −Define one 2D array d, there will be three rowssort the array digitssum := 0for initialize i := 0, when i < size of digits, ... Read More

Find the largest area rectangular sub-matrix whose sum is equal to k in C++

Arnab Chakraborty
Updated on 20-Aug-2020 07:25:23

290 Views

Suppose we have a 2D matrix mat and a value K, we have to find the longest rectangular submatrix whose sum is same as K.So, if the input is like28-56-778-311-1443-43110And K = 9then the output will be Top-Left point is (1, 0) and Bottom-Right point is (3, 2).-77811-144-431To solve this, we will follow these steps −MAX := 100Define a function sum_k(), this will take one array arr, start, end, n, k, Define one mapsum := 0, maximum_length := 0for initialize i := 0, when i < n, update (increase i by 1), do −sum := sum + arr[i]if sum is ... Read More

How to change the column names in R within aggregate function?

Nizamuddin Siddiqui
Updated on 29-Aug-2020 07:36:13

545 Views

The column names in an R data frame are an important part of the data because by reading the column names any viewer is likely to understand the theoretical background behind it. If that name is not appropriate then we might want to change it. While using the aggregate function to calculate mean or any other statistical summary, it is possible to change that name with another name by defining the new name with list.ExampleConsider the below data frame −set.seed(1) x1

How to create a vector with zero values in R?

Nizamuddin Siddiqui
Updated on 20-Aug-2020 05:49:42

627 Views

In data analysis, sometimes we need to use zeros for certain calculations, either to nullify the effect of a variable or for some other purpose based on the objective of the analysis. To deal with such type of situations, we need a zero value or a vector of zeros. There are many ways to create a vector with zeros in R. The important thing is the length of the vector.Examples> x1 x1 [1] 0 0 0 0 0 0 0 0 0 0 > x2 x2 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 ... Read More

What is parameter binding in C# ASP.NET WebAPI?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 14:21:24

2K+ Views

Binding is a process to set values for the parameters when Web API calls a controller action method.Web API methods with the different types of the parameters and how to customize the binding process.If the parameter is a simple type like int, bool, double, etc., Web API tries to get the value from the URI (Either from route data or from the Query String)if the parameter is a complex type like Customer, Employee, etc., then the Web API Framework tries to get the value from the request body.We can change this default behavior of the parameter binding process by using ... Read More

How to configure C# ASP.NET WebAPI in web.configure file?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 14:20:18

1K+ Views

No we cannot configure WEB API in web.configure file.Web API supports code based configuration. It cannot be configured in web.config file.We can configure WEB API, to customize the behaviour of Web Api hosting Infrastructure and component such asRoutesFormattersFiltersDependency ResolverMessage HandlersParameterBindingRulesPropertiesServicesRoutes − The public methods of the controller are called action methods or simply actions.When the Web API framework receives a request, it routes the request to an action. To determine which action to invoke, the framework uses a routing tableroutes.MapHttpRoute(    name: "API Default",    routeTemplate: "api/{controller}/{id}",    defaults: new { id = RouteParameter.Optional } );Formatters −ASP.NET Core MVC supports ... Read More

What are the advantages of using C# ASP.NET WebAPI?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 14:15:49

2K+ Views

WEB API is a better choice for simpler, light weight services. WEB API can use any text format including XML and is faster than WCF.It works the way HTTP works using standard HTTP verbs like GET, POST, PUT, DELETE for all the crud operation.Complete Support for routingResponse generated in Json and XML format using MediaTypeFormatter.It has the ability to be hosted in IIS as well as self-host outside of IIS.Supports Model binding and Validation.Support for ODATA.Supports stateless transfer of data.Supports Url patterns and Http methods.Note − ODATA (Open Data Protocol )is an open protocol which allows the creation and consumption ... Read More

What are Async Streams in C# 8.0?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 14:14:19

205 Views

C# 8.0 introduces async streams, which model a streaming source of data. Data streams often retrieve or generate elements asynchronously.The code that generates the sequence can now use yield return to return elements in a method that was declared with the async modifier.We can consume an async stream using an await foreach loop.This below Syntaxstatic IEnumerable Message(){    yield return "Hello!";    yield return "Hello!"; } Can be replaced by IAsyncEnumerable static async IAsyncEnumerable MessageAsync(){    await Task.Delay(2000);    yield return "Hello!";    await Task.Delay(2000);    yield return "Hello!"; }Exampleclass Program{    public static async Task Main(){       ... Read More

Advertisements