AmitDiwan has Published 8358 Articles

Sum of two elements just less than n in JavaScript

AmitDiwan

AmitDiwan

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

176 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

504 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

224 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

380 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

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

456 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

294 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

Checking digit sum of smallest number in the array in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:35:00

255 Views

We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument. The function should first pick the smallest number from the array and then calculate the sum of all the digits of the number.If the digit sum of that ... Read More

Finding all valid word squares in JavaScript

AmitDiwan

AmitDiwan

Updated on 27-Feb-2021 17:29:33

291 Views

Word Square:A word square consists of a set of words written out in a square grid, such that the same words can be read both horizontally and vertically.For instance, once valid word square is −H E A R T E M B E R A B U S E R ... Read More

Find Smallest Letter Greater Than Target in JavaScript

AmitDiwan

AmitDiwan

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

460 Views

Suppose we are given an array of sorted characters letters containing only lowercase letters. And given a target letter target.We are required to write a JavaScript function that takes in the array as the first argument and the letter as the second. The function is supposed to find the smallest ... Read More

Advertisements