Arrangement of Words Without Changing Relative Position of Vowels and Consonants

Arnab Chakraborty
Updated on 02-Jul-2020 09:53:20

159 Views

Suppose we have a string with n elements (n < 10). We have to find the number of ways that the string can be arranged without changing the relative position of the vowel and consonants.The approach is simple. We have to count the number of vowels and consonants in the given string, then we have to find how many ways we can arrange the vowels only, then find the number of ways to arrange the consonant only, after that multiply these two results to get the total ways.AlgorithmarrangeWayCount(str)Begin    define an array ‘freq’ to store frequency.    count and place ... Read More

Array Element with Minimum Sum of Absolute Differences

Arnab Chakraborty
Updated on 02-Jul-2020 09:50:00

384 Views

Here we will see one interesting problem. We are taking one array ‘a’ with N elements. We have to find an element x such that |a[0] - x| + |a[1] - x|+ … + |a[n-1] - x| is minimized. Then we have to find the minimized sum.Let the array is: {1, 3, 9, 6, 3} now the x is 3. So the sum is |1 - 3| + |3 - 3| + |9 - 3| + |6 - 3| + |3 - 3| = 11.To solve this problem, we have to choose the median of the array as x. If ... Read More

Array Elements with Prime Frequencies

Arnab Chakraborty
Updated on 02-Jul-2020 09:45:57

440 Views

Suppose we have one array. we have to count how many of the elements present in the array prime number of times. So if the array is {1, 2, 2, 0, 1, 5, 2, 5, 0, 0, 1, 1}, then 1 is present 4 times, 2 is present 3 times, 0 is present 3 times, and 5 is present 2 times. So there are three elements {2, 0, 5} that have occurred prime number of times. So the count will be 3.AlgorithmcountPrimeOccurrence(arr, n)Begin    count := 0    define map with int type key and int type value    for ... Read More

Generate Binary Numbers from 1 to N

Arnab Chakraborty
Updated on 02-Jul-2020 09:41:31

470 Views

Here we will see one interesting method for generating binary numbers from 1 to n. Here we are using queue. Initially the queue will hold first binary number ‘1’. Now repeatedly delete element from queue, and print it, and append 0 at the end of the front item, and append 1 at the end of the front time, and insert them into the queue. Let us see the algorithm to get the idea.AlgorithmgenBinaryNumbers(n)Begin    define empty queue.    insert 1 into the queue    while n is not 0, do       delete element from queue and store it ... Read More

Get All Prime Numbers Smaller Than N

Arnab Chakraborty
Updated on 02-Jul-2020 09:40:59

162 Views

Here we will see how to generate all prime numbers that are less than n in an efficient way. In this approach we will use the Wilson’s theorem. According to his theorem if a number k is prime, then ((k - 1)! + 1) mod k will be 0. Let us see the algorithm to get this idea.This idea will not work in C or C++ like language directly, because it will not support the large integers. The factorial will generate large numbers.AlgorithmgenAllPrime(n)Begin    fact := 1    for i in range 2 to n-1, do       fact ... Read More

Add Elements of Given Arrays with Given Constraints

Arnab Chakraborty
Updated on 02-Jul-2020 09:29:33

156 Views

Here we will see one problem. We will add two array elements and store them into another array. But we will follow some constraints. These constraints are like below −Addition should be stated from 0th index of both of the arraySplit the sum if it is more than one-digit number, and place each digit to the corresponding locationsRemaining digits of the larger input array will be stored at output arrayLet us see the algorithm to get the idea.AlgorithmaddArrayConstraints(arr1, arr2)Begin    define empty vector out    i := 0    while i is less than both arr1.length and arr2.length, do   ... Read More

CSS Animation Duration Property

Nishtha Thakur
Updated on 02-Jul-2020 09:22:55

102 Views

Use the animation-duration property to set how long an animation should take to complete one cycleExampleYou can try to run the following code to implement the animation-duration property −Live Demo                    div {             width: 150px;             height: 200px;             position: relative;             background: red;             animation-name: myanim;             animation-duration: 2s;          }          @keyframes myanim {            from {left: 0px; background-color: green;}             to {left: 200px; background-color: blue;}          }                              

CSS Transition Property

Krantik Chavan
Updated on 02-Jul-2020 09:18:48

215 Views

Use the CSS transition property to set all the four transition properties into a single line. You can try to run the following code to work with the transition property −ExampleLive Demo                    div {             width: 150px;             height: 150px;             background: blue;             transition: height 3s;          }          div:hover {             height: 250px;          }                     Heading One       Hover over the below box to change its height.          

Purpose of Using CHANGE Command in MySQL

AmitDiwan
Updated on 02-Jul-2020 09:10:31

159 Views

The CHANGE command in MySQL is used to rename column name. Let us first create a table −mysql> create table DemoTable796 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100), StudentAge int ); Query OK, 0 rows affected (0.56 sec)Let us check the description of table −mysql> desc DemoTable796;This will produce the following output −+------------+--------------+------+-----+---------+----------------+ | Field      | Type         | Null | Key | Default | Extra          | +------------+--------------+------+-----+---------+----------------+ | StudentId  | int(11)      | NO   | PRI | NULL    | auto_increment | | Name ... Read More

Importance of serialVersionUID Keyword in Java

raja
Updated on 02-Jul-2020 09:02:37

6K+ Views

SerialVersionUIDThe SerialVersionUID must be declared as a private static final long variable in Java. This number is calculated by the compiler based on the state of the class and the class attributes. This is the number that will help the JVM to identify the state of an object when it reads the state of the object from a file.The SerialVersionUID can be used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible w.r.t serialization. If the deserialization object is different than serialization, then it can throw an InvalidClassException.If the serialVersionUID is ... Read More

Advertisements