Maximum Length Chain of Pairs in C++

Arnab Chakraborty
Updated on 25-Sep-2019 12:32:39

105 Views

There is a chain of pairs is given. In each pair, there are two integers and the first integer is always smaller, and second one is greater, the same rule can also be applied for the chain construction. A pair (x, y) can be added after a pair (p, q), only if q < x.To solve this problem, at first we have to sort given pairs in increasing order of first element. After that we will compare the second element of a pair, with the first element of next pair.Input − A chain of number pairs. {(5, 24), (15, 25), ... Read More

MySQL query to delete table rows if string in cell is matched

AmitDiwan
Updated on 25-Sep-2019 12:27:43

186 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('Carol Taylor'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name) values('John Doe'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Name) values('Chris Brown'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('John Brown'); Query OK, 1 row ... Read More

Python Program to Print Matrix in Z form

Pavitra
Updated on 25-Sep-2019 12:26:13

274 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given a square matrix of order n*n, we need to display elements of the matrix in Z form.Z form is traversing the matrix in the following steps −Traverse the first rowNow, traverse the second principal diagonalFinally, traverse the last row.We will take an input matrix here implicitly taken to demonstrate the flow of code.demostrateExample Live Demoarr = [[1, 2, 6, 9],    [1, 2, 3, 1],    [7, 1, 3, 5],    [1, 8, 7, 5]] n = len(arr[0]) i = 0 ... Read More

Update existing column data in MySQL and remove the last string from a varchar column with strings and numbers

AmitDiwan
Updated on 25-Sep-2019 12:25:42

175 Views

Let us first create a table −mysql> create table DemoTable (    Download varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('120 Gigabytes'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('190 Gigabytes'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('250 Gigabytes'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('1000 Gigabytes'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------------+ ... Read More

How to find a particular varchar id in MySQL from a list of values?

AmitDiwan
Updated on 25-Sep-2019 12:23:55

174 Views

To get a particular varchar ID from a list, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable (    Id varchar(255) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10, 100, 1000'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('101, 120, 2'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('3, 4, 5'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

Matrix Chain Multiplication (A O(N^3) Solution) in C++

Arnab Chakraborty
Updated on 25-Sep-2019 12:22:56

2K+ Views

If a chain of matrices is given, we have to find minimum number of correct sequence of matrices to multiply.We know that the matrix multiplication is associative, so four matrices ABCD, we can multiply A(BCD), (AB)(CD), (ABC)D, A(BC)D, in these sequences. Like these sequences, our task is to find which ordering is efficient to multiply.In the given input there is an array say arr, which contains arr[] = {1, 2, 3, 4}. It means the matrices are of the order (1 x 2), (2 x 3), (3 x 4).Input − The orders of the input matrices. {1, 2, 3, 4}. ... Read More

Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!

Pavitra
Updated on 25-Sep-2019 12:21:44

2K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given an integer input n, we need to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!Here we are implementing for loop, therefore, we get O(n) as the time complexity.Here to reach the efficiency we calculate factorial within the same loop.Here we frame a sumofseries function as described below −Example Live Demodef sumOfSeries(num):    res = 0    fact = 1    for i in range(1, num+1):       fact *= i       res ... Read More

Populate null columns in a MySQL table and set values

AmitDiwan
Updated on 25-Sep-2019 12:21:18

542 Views

For this, you can use IS NULL property. Let us first create a table −mysql> create table DemoTable (    ProductPrice int,    ProductQuantity int,    TotalAmount int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductPrice, ProductQuantity) values(100, 2); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ProductPrice, ProductQuantity) values(500, 4); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ProductPrice, ProductQuantity) values(1000, 10); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce ... Read More

How to make a pair of columns unique in MySQL?

AmitDiwan
Updated on 25-Sep-2019 12:18:45

599 Views

To make a pair of columns unique, use UNIQUE with ALTER TABLE command. Following is the syntax −alter table yourTableName add unique yourUniqueName(yourColumnName1, yourColumnName2, ...N);Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(100),    StudentLastName varchar(100),    StudentAge int,    StudentPhoneNumber varchar(20) ); Query OK, 0 rows affected (0.81 sec)Following is the query to make a pair of unique columns in MySQL −mysql> alter table DemoTable add unique DemoTable_unique_StudentFirstName_StudentPhoneNumber(StudentFirstName, StudentPhoneNumber); Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the ... Read More

Python Program to find the area of a circle

Pavitra
Updated on 25-Sep-2019 12:18:21

440 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given the radius of a circle, we need to find a circle.The area of a circle can simply be evaluated using the following formula.Area = Pi*r*rLet’s see the implementation below −Example Live Demodef findArea(r):    PI = 3.142    return PI * (r*r); # Driver method print("Area is %.6f" % findArea(5));OutputArea is 78.550000All variables and functions are declared in the global scope as shown in the figure below.ConclusionIn this article, we learned about the approach to find whether it is possible to make ... Read More

Advertisements