AmitDiwan has Published 10744 Articles

Hamming Distance between two strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:54:59

2K+ Views

Hamming DistanceThe Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.For example, consider the following strings −const str1 = 'delhi'; const str2 = 'delph';The Hamming Distance of these strings is 2 because the fourth and the fifth characters of ... Read More

Function to calculate the least common multiple of two numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:52:47

474 Views

The least common multiple, (LCM) of two integers a and b, is the smallest positive integer that is divisible by both a and b.For example −LCM of 4 and 6 is 12 because 12 is the smallest number that is exactly divisible by both 4 and 6.We are required to ... Read More

Combination sum problem using JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:51:51

538 Views

Suppose we are given a set of candidate numbers (without duplicates) and a target number (target).We are required to write a function that finds all unique combinations in candidates where the candidate numbers sum to the target.The same repeated number may be chosen from candidates an unlimited number of times.Note ... Read More

Regular Expression Matching in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:50:06

276 Views

Suppose we are given an input string str and a pattern p, we are required to implement regular expression matching with support for. and *.The functions of these symbols should be −. --> Matches any single character.* --> Matches zero or more of the preceding elements.The matching should cover the ... Read More

Checking power of 2 using bitwise operations in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:47:20

381 Views

We are required to write a JavaScript function that takes in a number and determines whether or not it is a power of two.For example −f(23) = false f(16) = true f(1) = true f(1024) = trueApproach −Powers of two in binary form always have just one bit. Like this ... Read More

Euclidean Algorithm for calculating GCD in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:46:15

2K+ Views

In mathematics, Euclid's algorithm, is a method for computing the greatest common divisor (GCD) of two numbers, the largest number that divides both of them without leaving a remainder.The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger ... Read More

Primality test of numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 08:44:50

421 Views

A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. All other natural numbers greater than 1 are called composite numbers. A primality test is an algorithm for determining whether an input number is prime.We are required ... Read More

Condition to check for due date and current date records in MySQL where clause

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 05:57:50

655 Views

To check for such conditions, use IF() in MySQL.Let us create a table −Examplemysql> create table demo89    -> (    -> duedate date    -> ); Query OK, 0 rows affected (0.78Insert some records into the table with the help of insert command −Examplemysql> insert into demo89 values('2020-01-10'); Query ... Read More

Creating a table with MySQL - Hibernate

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 05:55:53

2K+ Views

To create a table, you need to insert below line into application.properties −spring.jpa.hibernate.ddl-auto=updateHere, Hibernate will create the table demo88 automatically. The application.properties code is as follows −spring.datasource.platform=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hibernate.ddl-auto=update server.port=8191 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sampledatabase spring.datasource.username=root spring.datasource.password=123456The demo88 entity class is as follows to create table columns −Examplepackage com.automaticallytablecreation; import javax.persistence.Column; ... Read More

Display MySQL table values using Java

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 05:50:52

4K+ Views

For this, you can use the ResultSet concept. For connection, we will be using the MySQL JDBC Driver.Let us create a table −Examplemysql> create table demo87    -> (    -> name varchar(20),    -> age int    -> )    -> ; Query OK, 0 rows affected (0.62Insert some ... Read More

Advertisements