AmitDiwan has Published 10744 Articles

Squared and square rooted sum of numbers of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:15:18

401 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should take each number in the array and square it if it is even, or square root the number if it is odd and then return the sum of all the new numbers ... Read More

Finding next prime number to a given number using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:14:52

1K+ Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should that smallest number which is just greater than n and is a prime number.ExampleFollowing is the code − Live Democonst num = 101; const isPrime = (num) => {    let sqrtnum = Math.floor(Math.sqrt(num)); ... Read More

Python Program to solve Maximum Subarray Problem using Divide and Conquer

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:13:29

403 Views

When it is required solve the maximum subarray problem using the divide and conquer method, Below is the demonstration of the same −Example Live Demodef max_crossing_sum(my_array, low, mid, high):    sum_elements = 0    sum_left_elements = -10000    for i in range(mid, low-1, -1):    sum_elements = sum_elements + ... Read More

Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple using Python program

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:12:41

876 Views

When it is required to sort a list of tuples in increasing order based on last element of every tuple, a method is defined, that iterates over the tuple and performs a simple swap to achieve the same.Below is the demonstration of the same −Example Live Demodef sort_tuple(my_tup):    my_len ... Read More

Python Program to Generate Random Numbers from 1 to 20 and Append Them to the List

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:12:22

568 Views

When it is required to generate random numbers within a given range and append them to a list, a method is defined, that generates random numbers and ‘append’s them to an empty list.Below is the demonstration of the same −Example Live Demoimport random def random_gen(beg, end, my_num):    my_result = [] ... Read More

Python Program to Find the Cumulative Sum of a List where the ith Element is the Sum of the First i+1 Elements From The Original List

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:11:58

421 Views

When it is required to find the sum of a list where the specific element is sum of first few elements, a method is defined, that takes list as parameter. It uses list comprehension to find the cumulative sum.Below is the demonstration of the same −Example Live Demodef cumulative_sum(my_list):    cumulative_list ... Read More

Python Program to Find all Numbers in a Range which are Perfect Squares and Sum of all Digits in the Number is Less than 10

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:11:40

1K+ Views

When it is required to find all numbers in a range where there are perfect square, and sum of digits in the number is less than 10, list comprehension is used.Below is the demonstration of the same −Example Live Demolower_limit = int(input(“Enter the lower range: “)) upper_limit = int(input(“Enter the upper ... Read More

Volume difference of cuboids in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:08:58

125 Views

ProblemWe are required to write a JavaScript function that takes in two arrays, specifying the lengths, widths, and heights of two cuboids.Our function should calculate the volume of both cuboids and return their absolute difference.ExampleFollowing is the code − Live Democonst h1 = 10; const w1 = 12; const l1 = ... Read More

Finding the length of the diagonal of a cuboid using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:08:36

219 Views

ProblemWe are required to write a JavaScript function that takes in the length, width and height of a cuboid and return the length of its diagonal.ExampleFollowing is the code − Live Democonst height = 10; const width = 12; const length = 15; const findDiagonal = (l, w, h) => { ... Read More

Integers have sum of squared divisors as perfect square in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:08:20

252 Views

ProblemWe are required to write a JavaScript function that takes in a range specified by an array of two numbers m and n.Our function is supposed to find all integers between m and n (m and n integers such as 1

Advertisements