AmitDiwan has Published 10744 Articles

Unique substrings in circular string in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 11:26:29

206 Views

ProblemSuppose we have a S, str. which is an infinite wraparound string of the string −"abcdefghijklmnopqrstuvwxyz".Therefore, S will look like this −"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".We are required to write a JavaScript function that takes in str, let’s call that string str, as the only argument.Our function should find out how many unique non-empty ... Read More

Finding the smallest good base in JavaScript

AmitDiwan

AmitDiwan

Updated on 04-Mar-2021 06:01:59

149 Views

Good BaseFor an integer num, we call k (k >= 2) a good base of num, if all digits of num base k are 1.For instance: 13 base 3 is 111, hence 3 is a good base for num = 13ProblemWe are required to write a JavaScript function that takes ... Read More

Finding the maximum number using at most one swap in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:52:53

247 Views

We are required to write a JavaScript function that takes in a number as the first and the only argument.The task of our function is to perform at most one swap between any two digits of the number and yield the maximum possible number. If, however, the number is already ... Read More

Is a number sum of two perfect squares in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:50:55

287 Views

Perfect Square Numbers:A natural number in mathematics is called a perfect square if it can be obtained by multiplying any other natural number into that very number.For instance, 9, 16, 81, 289 are all perfect squares.We are required to write a JavaScript function that takes in a natural number, say ... Read More

Finding longest line of 1s in a matrix in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:49:14

205 Views

Suppose, we have a binary matrix (an array of array that contains only 0 or 1) like this −const arr = [    [0, 1, 1, 0],    [0, 1, 1, 0],    [0, 0, 0, 1] ];We are required to write a JavaScript function that takes in one such ... Read More

Distance of nearest 0 in binary matrix in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:47:05

224 Views

A binary matrix is an array of arrays containing only 0 or 1. We are required to write a JavaScript function that takes in a binary matrix as the only argument.Our function should create a new matrix containing the same number of rows and columns, and for each element of ... Read More

Reversing strings with a twist in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:45:26

225 Views

We are required to write a JavaScript function that takes in a string str as the first argument and an integer num as the second argument.Our function should reverse the first num characters for every 2 * num characters counting from the start of the string. And if there are ... Read More

Preparing encoding and decoding algorithms for shortening URLs in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:42:40

852 Views

We often come through services like bit.ly and tinyurl which takes in any url and (usually one bigger in length), performs some encryption algorithm over it and returns a very short url. And similarity when we try to open that tiny url, it again runs some decryption algorithm over it ... Read More

Finding minimum absolute difference within a Binary Search Tree in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:40:44

219 Views

We are required to write a JavaScript function that takes in the root of a BST that holds some numerical data like this −1 \ 3 / 2The function should return the minimum absolute difference between any two nodes of the tree.For example −For the above tree, the output should ... Read More

Finding the third maximum number within an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 03-Mar-2021 08:36:44

198 Views

We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.The task of our function is to pick and return the third maximum number from the array. And if the array does not contain any third maximum number then ... Read More

Advertisements