AmitDiwan has Published 10744 Articles

Ways to get to a specific sum in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 12:51:08

134 Views

ProblemWe are required to write a JavaScript function that takes in an array of Integers, arr, as the first argument and a single integer, target, as the second argument.For each Integer in the array, our function can either assign ‘+’ or ‘-’ to it.Our function should find out how many ... Read More

Finding peculiar pairs in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 12:49:54

134 Views

ProblemWe are required to write a JavaScript function that takes in an array of Integers, arr, as the first and the only argument.Our function should count the occurrence of all such index pairs (i, j) that satisfy the following conditions −I < j, andarr[i] > 2 * arr[j]For example, if ... Read More

Consecutive ones with a twist in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 12:48:15

182 Views

ProblemWe are required to write a JavaScript function that takes in a binary array (an array that consists of only 0 and 1), arr, as the only argument. Our function should find the maximum number of consecutive 1s in this array if we can flip at most one 0.For example, ... Read More

Formatting Software License Key in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 12:15:05

224 Views

ProblemWe are required to write a JavaScript function that takes in a string str, as the first argument and an Integer, n as the second argument. The string str is composed of alphanumeric characters and dashes.The dashes split the alphanumeric characters within the string into groups. (i.e. if there are ... Read More

Magical String: Question in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:49:25

497 Views

ProblemA magical string str consists of only '1' and '2' and obeys the following rules −The string str is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string str itself.The first few elements of string str is the following −str = "1221121221221121122……"If we ... Read More

Finding median for every window in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:47:31

851 Views

MedianMedian in mathematics, median is the middle value in an ordered(sorted) integer list.If the size of the list is even, and there is no middle value. Median is the mean (average) of the two middle values.ProblemWe are required to write a JavaScript function that takes in an array of Integers, ... Read More

Forming string using 0 and 1 in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:44:25

249 Views

ProblemWe are required to write a JavaScript function that takes in an array of strings, arr, formed using 0 and 1 only as the first argument.The function takes two numbers as the second and third argument, m and respectively. The task of our function is to find how many strings ... Read More

Encoding string to reduce its size in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:41:31

1K+ Views

ProblemWe are required to write a JavaScript function that takes in a string of characters, str, as the only argument. Our function should encode the input string and compare its size with the original string and return the string which is smaller in size.The rule to encode a particular string ... Read More

Checking for convex polygon in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:38:16

452 Views

Convex PolygonA convex polygon is defined as a polygon with all its interior angles less than 180°.ProblemWe are required to write a JavaScript function that takes in an array of coordinates, basically the array will be an array of arrays each subarray containing exactly two numbers, specifying a point on a ... Read More

Deriving Random10() function from Random7() in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:34:44

259 Views

Problemconst random7 = () => Math.ceil(Math.random() * 7);Suppose we have the above fat arrow function. This function yields a random number between 0 (exclusive) and 7 (inclusive) everytime we make a call to it.We are required to write a similar random10() JavaScript function that takes no argument and makes no ... Read More

Advertisements