AmitDiwan has Published 10744 Articles

Converting whitespace string to url in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:53:57

659 Views

In web urls if we provide space in the url, the browser automatically replaces all the spaces with the string '%20'We are required to write a JavaScript function that takes in a string as the first and the only argument. The function should then construct and return a new string ... Read More

Compressing string in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:52:06

6K+ Views

We are required to write a JavaScript function that takes in a string that might contain some continuous repeating characters.The function should compress the string like this −'wwwaabbbb' -> 'w3a2b4' 'kkkkj' -> 'k4j'And if the length of the compressed string is greater than or equal to the original string we ... Read More

Sum of two elements just less than n in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:48:44

152 Views

We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a single number, num, as the second argument.The function should then find two such numbers whose sum is greatest in the array but just less than the number num. ... Read More

Finding elements whose successors and predecessors are in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:47:10

467 Views

We are required to write a JavaScript function that takes in an array of integers as the first and the only argument.The function should construct and return a new array that contains all such elements from the original array whose successor and predecessor are both present in the array. If ... Read More

Checking for majority element in a sorted array in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:45:54

187 Views

Majority Element:A majority element in an array arr of length l is an element that appears more than l/2 times and hence there is at most one such element.We need to write a JavaScript function, say isMajority() that takes an array arr which is always sorted in the increasing order ... Read More

Meeting Rooms 2 problem in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:44:11

341 Views

We will be given an array of arrays, each subarray consists of exactly two elements indicating the start and end time of a meeting.The task of our function is to find the maximum number of meetings one person can take avoiding the conflict of time. The function should finally return ... Read More

Shifting string letters based on an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:42:30

349 Views

Suppose we have a string that contains only lowercase english alphabets.For the purpose of this question, we define unit shifting of a letter as replacing that very letter to its succeeding letter in alphabets (including wrapping which means next to 'z' is 'a');We are required to write a JavaScript function ... Read More

Performing shifts within a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:41:07

2K+ Views

Suppose we have a string str containing lowercase English letters, and an array of arrays arr, where arr[i] = [direction, amount] −direction can be 0 (for left shift) or 1 (for right shift).amount is the amount by which string s is to be shifted.A left shift by 1 means remove ... Read More

Finding the missing number in an arithmetic progression sequence in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:38:48

407 Views

Arithmetic Progression:An arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant.For instance, the sequence 5, 7, 9, 11, 13...Suppose we have an array that represents elements of arithmetic progression in order. But somehow one of the numbers from ... Read More

Finding confusing number within an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:37:17

249 Views

Confusing Numbers:A number in an array is confusing if it becomes another number which is also present in the array after we rotate the number by 180 degrees vertically and horizontally. For instance, if we rotate 6 by 180 degrees vertically and horizontally it becomes 9 and vice-versa.We have to ... Read More

Advertisements