Longest String with Two Distinct Characters in JavaScript

AmitDiwan
Updated on 24-Feb-2021 16:16:39

409 Views

We are required to write a JavaScript function that takes in a string as the first argument and a number (smaller than the length of string) as the second argument. The function should delete characters from the original string and prepare a new string such that it's the longest string containing at most two distinct characters.Then at last the function should return the length of that desired string.For example: If the input string is −const str = 'kjeljsdl';Then the output should be −const output = 4;because the longest substring with at most 2 distinct characters is 'jljl'ExampleThe code for this ... Read More

Substring Combination in JavaScript

AmitDiwan
Updated on 24-Feb-2021 16:12:50

259 Views

We are required to write a JavaScript function that takes in two strings as the first and the second argument. Let's call these strings str1 and str2. The function should check whether there exists a substring combination in str2, that when combined yields str2.By substring combination, we mean that we can skip characters but we have to maintain the order of the characters selected from str1.For example −If the input strings are −const str1 = 'desxooajmepwele'; const str2 = 'example';Then the output should be −const output = true;because the string 'example' can be formed by picking some and maintianing the ... Read More

Determine a Pangram String in JavaScript

AmitDiwan
Updated on 24-Feb-2021 16:11:26

3K+ Views

Pangram strings:A pangram is a string that contains every letter of the English alphabet.We are required to write a JavaScript function that takes in a string as the first and the only argument and determines whether that string is a pangram or not. For the purpose of this problem, we will take only lowercase alphabets into consideration.ExampleThe code for this will be − Live Democonst str = 'We promptly judged antique ivory buckles for the next prize'; const isPangram = (str = '') => {    str = str.toLowerCase();    const { length } = str;    const alphabets = 'abcdefghijklmnopqrstuvwxyz'; ... Read More

Calculate Weight of a String in JavaScript

AmitDiwan
Updated on 24-Feb-2021 16:09:53

867 Views

Weight of a character (alphabet):The weight of an English alphabet is nothing just its 1-based index.For example, the weight of 'c' is 3, 'k' is 11 and so on.We are required to write a JavaScript function that takes in a lowercase string and calculates and returns the weight of that string.ExampleThe code for this will be − Live Democonst str = 'this is a string'; const calculateWeight = (str = '') => {    str = str.toLowerCase();    const legend = 'abcdefghijklmnopqrstuvwxyz';    let weight = 0;    const { length: l } = str;    for(let i = 0; i ... Read More

Finding Minimum Deletions in String in JavaScript

AmitDiwan
Updated on 24-Feb-2021 16:06:56

194 Views

Suppose we have a binary string like this −const str = '001001';We are required to write a JavaScript function that takes in one such string as the first and the only argument.The function should then compute and return the number of minimum deletions required in the input so that no two adjacent numbers are the same.For example, for the above string, the output should be −const output = 2;because if we delete '0' at index 0 and 3, the new string will be '0101' which is the longest desired string.ExampleThe code for this will be − Live Democonst str = '001001'; ... Read More

2-Key Keyboard Problem in JavaScript

AmitDiwan
Updated on 24-Feb-2021 14:30:56

235 Views

Suppose the following situation −Initially on a notepad only one character 'A' is present. We can perform two operations on this notepad for each step −Copy All − We can copy all the characters present on the notepad (partial copy is not allowed).Paste − We can paste the characters which were copied last time.We are required to write a JavaScript function that takes in a number, let's call it num as the only argument. Our function is required to compute and return the minimum number of steps (copy all or paste) required to print 'A' num times.For example −If the input ... Read More

New Features in MySQL 8.0

AmitDiwan
Updated on 24-Feb-2021 13:41:41

882 Views

MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most expensive and powerful database packages. It uses a standard form of the well-known SQL data language. MySQL 8.0 released on 19 April 2018 and the current version is 8.0.23.The new features in MySQL 8.0 have been briefly listed below:Atomic DDLAn atomic data definition language (DDL) statement to combine updates made to data dictionary, storage engine operations and so on.Encryption DefaultsThe encryption defaults have been defined and implemented globally for table encryption.  The ‘default_table_encryption’ variable is used to define an ... Read More

Features Added in MySQL 8.0

AmitDiwan
Updated on 24-Feb-2021 12:43:40

298 Views

Let us understand the features that were added to MySQL 8.0Security Levels EnhancedThe security levels have been improved, and DBA (Database administrator) has been given greater flexibility for account management.Resource GroupsResource groups can be created and managed, and the server has the ability to assign threads to resources of specific groups, that are running within the server. Group attributes can be used to control the resources, restrict or provide permission to the threads to consume the resource, and so on.Transactional Data DictionaryA transactional data dictionary is used to store information about objects, which was previously a non-transactional table.Upgrade ProcedureThe upgrade ... Read More

Deprecated Features in MySQL 8.0

AmitDiwan
Updated on 24-Feb-2021 12:32:57

2K+ Views

Some of the features that have been deprecated may be removed in the upcoming versions of MySQL. If applications use the features that have been deprecated in that specific version, that feature should be revised and alternatives should be used wherever possible.Let us understand in brief, the features that have been deprecated in MySQL 8.0:The ‘utf8mb3’ character set is deprecated, use ‘utf8mb4’ instead.The ‘sha256_password’ password authentication is deprecated, may be removed in future updates. Use ‘caching_sha2_password’ instead.Some implementation changes have been made to ‘validate_password’ plugin, may be removed in future versions. Use this plugin by ensuring that component infrastructure is ... Read More

Features Removed in MySQL 8.0

AmitDiwan
Updated on 24-Feb-2021 12:17:35

713 Views

Some of the features have become obsolete and have been removed from MySQL 8.0. When alternatives to these removed items are shown, they need to be used to avoid further complications.The ‘innodb_locks_unsafe_for_binlog’ system variable has been removed.The ‘READ COMMITTED’ isolation level can be used since it behaves in a similar way.After upgrading the system to MySQL version 8.0.3 or later, scripts that reference previous InnoDB INFORMATION_SCHEMA view names have to be upgraded.Some of the account management attributes have been removed. A few have been listed below:Instead of using ‘GRANT’ to create users, use ‘CREATE USER’.The query cache has been removed.The deprecated ... Read More

Advertisements