AmitDiwan has Published 10740 Articles

Python Program to Find Element Occurring Odd Number of Times in a List

AmitDiwan

AmitDiwan

Updated on 14-Apr-2021 12:22:45

1K+ Views

When it is required to find an element that occurs odd number of times in a list, a method can be defined. This method iterates through the list and checks to see if the elements in the nested loops match. If they do, the counter is incremented. If that count ... Read More

Python Program to Remove the nth Occurrence of the Given Word in a List where Words can Repeat

AmitDiwan

AmitDiwan

Updated on 14-Apr-2021 12:20:26

2K+ Views

When it is required to remove a specific occurrence of a given word in a list of words, given that the words can be repeated, a method can be defined, that iterates through the list, and increments the counter by 1. If the count and the specific occurrence match, then ... Read More

Finding intersection of arrays of intervals in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:56:48

544 Views

ProblemJavaScript function that takes in two arrays, arr1 and arr2 of intervals which are pairwise disjoint and in sorted order.A closed interval [a, b] (with a

Array thirds with equal sums in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:48:05

150 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers as the first and the only argument. Our function should return true if and only if we can partition the array into three non-empty parts with equal sums, false otherwise.For example, if the input to ... Read More

Maximum consecutive 1s after n swaps in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:46:51

203 Views

ProblemWe are required to write a JavaScript function that takes in a binary arr (array that contains only 0 or 1), arr, as the first argument, and a number, num, as the second argument.We can change at most num 0s present in the array to 1s, and our function should ... Read More

Commons including duplicates in array elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:45:02

131 Views

ProblemWe are required to write a JavaScript function that takes in an array of strings, arr, as the first and the only argument.Our function is supposed to return an array of all characters that show up in all strings within the array arr (including duplicates).For example, if a character occurs ... Read More

Problem: Time taken by tomatoes to rot in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:43:24

189 Views

ProblemWe are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the only argument.The numbers in the array can be −the value 0 which represents an empty cell;the value 1 which represents a fresh tomato;the value 2 which represents a rotten tomato.Every minute, ... Read More

Parts of array with n different elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:41:31

189 Views

ProblemWe are required to write a JavaScript function that takes in an array of literals, arr, as the first argument. The second argument to our function will be a number, num. Our function should count and return the number of subarrays of the array that contains exactly num distinct elements.For ... Read More

Finding minimum number of required operations to reach n from m in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:39:42

201 Views

ProblemWe are required to write a JavaScript function that takes in two numbers, m and n, as the first and the second argument.Our function is supposed to count the number of minimum operations required to reach n from m, using only these two operations −Double − Multiply the number on ... Read More

Checking validity of equations in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:37:05

308 Views

ProblemWe are required to write a JavaScript function that takes in an array, arr, as the first and the only argument.The array arr consists of string equations of one of the two following kinds −‘X ===Y’X!==Y’Here, X and Y can be any variables.Our function is supposed to check whether for ... Read More

Advertisements