Anagrams:Two words or phrases which can be made by arranging the letters of each other in a different order are called anagrams of each other, like rat and tar.We are required to write a JavaScript function that takes in an array of strings that might contain some anagram strings. The function should group all the anagrams into separate subarrays and return the new array thus formed.For example −If the input array is −const arr = ['rat', 'jar', 'tar', 'raj', 'ram', 'arm', 'mar', 'art'];Then the output array should be −const output = [ ['rat', 'tar', 'art'], ['jar', 'raj'], ... Read More
Hamming Distance:The hamming distance between two strings of equal length is the number of positions at which these strings vary.In other words, it is a measure of the minimum number of changes required to turn one string into another. Hamming Distance is usually measured for strings equal in length.We are required to write a JavaScript function that takes in two strings, lets say str1 and str2, of the same length. The function should calculate and return the hamming distance between those strings.ExampleFollowing is the code −const str1 = 'Hello World'; const str2 = 'Heeyy World'; const findHammingDistance = (str1 = ... Read More
We are required to write a JavaScript function that takes in a positive integer, say num.The task of our function is to count the total number of 1s that appears in all the positive integers upto n (including n, if it contains any 1).Then the function should finally return this count.For example −If the input number is −const num = 31;Then the output should be −const output = 14;because 1 appears in, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 31ExampleFollowing is the code −const num = 31; const countOnes = (num = 1) => { ... Read More
We are required to write a JavaScript function that takes in an array of integers as the only argument.Based on the array taken in as input, the function should construct a new array of the same length based on the following criteria.Any corresponding element of the output array should be the product of the three largest numbers encountered thus far. If the corresponding index is less than 3 (we have not encountered three elements yet) then the corresponding value should be -1. And Although we can use non-unique values to calculate the product, but those non-unique values should be present ... Read More
We are required to write a JavaScript function that takes in an array of integers as the only argument.The function should first permute all possible subarrays from the original array that have an odd length. And then the function should find the combined sum of all the elements of those subarrays and return the sum.For example −If the input array is −const arr = [1, 2, 3];Then the output should be −const output = 12;because the desired subarrays are [1], [2], [3], [1, 2, 3]ExampleFollowing is the code −const arr1 = [1, 2, 3]; const arr2 = [1, 2, 3, ... Read More
We are required to write a JavaScript function that takes in an array of integers as the only argument.The function should determine whether there exists any way in which we can split the array into two subarray such that the sum of the elements present in the two subarrays are equal. While dividing the elements into subarrays we have to make sure that no element from the original array is left.For example −If the input array is −const arr = [5, 3, 7, 4, 1, 8, 2, 6];Then the output should be −const output = true;because the desired subarrays are: ... Read More
In this problem, we are given two integer values n and k. Our task is to find the Maximum number possible by doing at-most K swaps. Problem description: Here, we need to calculate the number which is maximum and created after swapping at-most k digits of the number.Let’s take an example to understand the problem, Input: n = 538 k = 1Output: 835Explanation: We will swap 8 and 5.Solution ApproachTo solve the problem, we need to swap digits of the number k times and check if the number from is maximum. We need to find the maximum digit of the number and then swap the ... Read More
In this problem, we are given a binary Tree with positive and negative values. Our task is to Find maximum level sum in Binary Tree. Problem Description: We have a binary tree, we will find the sum of all levels in the binary tree and then return the maximum of them.Let’s take an example to understand the problem, Input: Output: 5Explanation: Sum of elements at level 1: 3Sum of elements at level 2: -3 + 4 = 1Sum of elements at level 3: 5 - 1 + 6 - 5 = 5Solution ApproachTo solve the problem, we need to traverse the tree using the level ... Read More
In this problem, we need to create a program to calculate Prime Factorization using Sieve O(log n) for multiple queries. As the general method takes O(sqrt(n) ) time which will increase the time required to a huge extent from multiple queries.Let’s recap first, Prime factorization of a number includes ONLY the prime factors, not any products of those prime factors.Sieve of Eratosthenes is an algorithm to generate all prime numbers within the given range.Solution ApproachThe solution to the problem is found by finding the smallest factor that divides the number, saving it as a factor and updating the number by dividing ... Read More
Risk Management is the approach that is used to manage all available resources and make the best use of the resources available in the system.The project manager will analyse risks from all categories and there might be some risks in the working of the project in the runtime environment.Principles of Risk ManagementThere are 5 basic principles of Risk management. They are:GLOBAL PERSPECTIVE: This risk analysis of software in context of system and business problems planned to be solved. This analysis takes underconsideration the larger system definition, design and implementation.FORWARD LOOKING VIEW: This analysis considers all possible solutions to future risks to the product. Here, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP