Create JS Radial Gradient with Matrix in HTML

Sreemaha
Updated on 02-Jun-2020 07:40:33

274 Views

JSRadial gradient with matrix is created in the following way. You can try to run the following way to create JS Radial gradient with matrix −var canvas1 = document.getElementById("canvas"); //canvas1 variable to identify given canvas var ctx1 = canvas.getContext("2d"); //This is used to tell context is 2D   var gradient1 = ctx1.createRadialGradient(100/horizontalScale, 100/verticalScale, 100, 100/horizontalScale, 100/verticalScale, 0); //This will create gradient with given canvas context   gradient1.addColorStop(1, "green"); //New color green is added to gradient gradient1.addColorStop(0, "red"); //New color red is added to gradient ctx1.scale(horizontalScale, verticalScale); //Context matrix ctx1 is shrinked according to horizaontal and vertical scale ... Read More

Redundant Connection II in C++

Arnab Chakraborty
Updated on 01-Jun-2020 12:06:06

269 Views

Suppose we have a rooted tree. This is a directed graph such that, there is exactly one node (which is the root) for which all other nodes are descendants of this node, and every node has exactly one parent, except for the root node. Root has no parents.In the given input a directed graph that started as a rooted tree with N nodes (All values are unique), with one additional directed edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.Graph will be a 2D-array of edges. Each ... Read More

24 Game in C++

Arnab Chakraborty
Updated on 01-Jun-2020 12:00:53

1K+ Views

Suppose we have four cards; these cards are holding some number from 1 to 9. We have to check whether they could operate through some operators like +, -, *, /, to get 24. So if we have some numbers like [4,9,2,6], then we can get 24 by (4 * 9) – (2 * 6), answer will be true.To solve this, we will follow these steps −epsilon := 10.0^-5Define a function solve(), this will take an array v,if size of v is same as 1, then −return true when |v[0] - 24.0|

Kth Smallest Number in Multiplication Table in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:58:51

373 Views

Suppose we know about one Multiplication Table. But could we find out the k-th smallest number quickly from the multiplication table? So if we have to height m and the length n of a m * n Multiplication Table, and one positive integer k, we have need to find the k-th smallest number in this table.So if m = 3 and n = 3 and k is 6, then the output will be 4., this is because the multiplication table is like −1231123224633696th smallest element is 4 as [1, 2, 2, 3, 3, 4, 6, 6, 9]To solve this, we ... Read More

Strange Printer in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:56:58

283 Views

Suppose there is a strange printer It has some requirements −The printer can print only a sequence of the same character each time.In each turn, the printer can print new characters starting from and ending at any places, and will cover the original existing characters.So if we have a string consists of lower letters, our task is to count the minimum number of turns the printer needed in order to print it.So if the input is like “aaabba”, then it will take 2 turns, first prints aaaaa then b’s by replacing the characters.To solve this, we will follow these steps ... Read More

Decode Ways II in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:53:28

287 Views

Suppose there is a message, that is containing letters from A-Z is being encoded to numbers using the following mapping way −'A' -> 1, 'B' -> 2, ... , 'Z' -> 26Now, the encoded string can also contain the character '*', which can be treated as one of the numbers from 1 to 9. So if we have the encoded message containing digits and the character '*', then we have to find the total number of ways to decode it. If the answer is very long, we can use mod 109 + 7 to get the final result. So if ... Read More

Smallest Range Covering Elements from K Lists in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:49:49

298 Views

Suppose we have k lists of sorted integers. We have to search the smallest range that includes at least one number from each of the k lists. Here the range [a, b] is smaller than range [c, d] when b-a < d-c or a < c if b-a == d-c.So if the input is like [[4, 10, 15, 25, 26], [0, 9, 14, 20], [5, 18, 24, 30]], then the output will be [14, 18]To solve this, we will follow these steps −minRange := inf, maxRange := -inf, rangeSize := inf, tempMinRange := inf, tempMaxRange := -infn := size of ... Read More

K Inverse Pairs Array in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:47:00

298 Views

Suppose we have two integers n and k, we have to find how many different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. The inverse pair is for ith and jth element in the array, if i < j and a[i] > a[j] it is called an inverse pair. Here the answer may be very large, the answer should be modulo $10^{9}$ + 7.So if the input is like n = 3 and k = 1, then the output will be 2 as the arrays [1, 3, 2] and [2, 1, 3] ... Read More

Non-Negative Integers Without Consecutive Ones in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:42:46

369 Views

Suppose we have a positive integer n. We have to find the non-negative integers less than or equal to n. The constraint is that the binary representation will not contain consecutive ones. So if the input is 7, then the answer will be 5, as binary representation of 5 is 101.To solve this, we will follow these steps −Define a function convert(), this will take n, ret := empty stringwhile n is non-zero, do −ret := ret + (n mod 2)n := right shift n, 1 timereturn retFrom the main method, do the following −bits := call the function convert(num)n ... Read More

Find the Closest Palindrome in C++

Arnab Chakraborty
Updated on 01-Jun-2020 11:40:05

263 Views

Suppose we have a number n, we have to get the closest number that is palindrome. So the palindrome could be less than or greater than the number whose absolute difference is smaller. So if the number is like 145, then the result will be 141.To solve this, we will follow these steps −sn := size of nif sn is same as 1, then −decrease n[0] by 1 and return a string of 1s of size n[0]half_sn := (sn + 1) / 2half_val := stol(substring of n from index 0 to half_snDefine an array candidates = {10^(sn) – 1, 10^(sn ... Read More

Advertisements