In this problem we have to validate that a given number is a power of n. If the given number is power of n then it should return the true value of it otherwise it should return false. To check this kind of validation we generally use arithmetic operators like Modulus - %, Division - /, comparison operators like less than < or greater than >. Lets understand this problem with an example. True value: N = 27 So 33 = 27 False Value: N = 28 So 33 != ... Read More
In python we are can use simple for loop and max, count and operator function to find the maximum value from the dictionary whose key is present in the list. Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. Example Assume we have taken an input dictionary and input list. We will now find the maximum value from an input dictionary whose key is also present in the input list. ... Read More
As the problem stated, create a program for a unique sort in javascript. Basically we have to remove duplicate elements from an array. Understand the problem In this problem statement we need to eliminate the same or duplicated item from an array. For solving this kind of problem we can use some predefined methods of javascript. In this article you will be able to learn usage of forEach(), spread operator, set() method, filter() method and indexOf() methods. Lets understand this problem with an example. Array before sorting and with duplicates [535, 646, ... Read More
The problem statement is saying that we have to find a solution for a given array and split it to form an object with a key-value pair in javascript. Understand the problem In simple terms we have to convert a given array into an object. There are several methods present in javascript to convert an array into an object. We will use and code each of them one by one. Using reduce() and split() methods In this method we will use reduce and split functions of javascript. Algorithm The algorithm here discusses ... Read More
Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. In this article, we will learn how to extract keys with specific value type in python. Methods Used The following are the various methods to accomplish this task − Using for loop and isinstance() method Using list comprehension and isinstance() method Using keys() & type() methods Example Assume we have taken an input dictionary. We will now Input ... Read More
In this problem, we have to group all the duplicate data in the array by making their subarray. After making the subarray we have to arrange them in a sorted order. This problem can be solved by searching techniques of data structures. Understanding the Problem So for solving this problem, we will use javascript’s reduce() method in two ways. The reduce method is an iterative method which uses a reducer function to iterate through all the items in the array. So by checking one by one we will keep track of all the elements and ... Read More
Given problem says to sort the given array of objects by two properties and create a program in javascript. Understanding the problem Let's have a deep understanding of the problem statement. You will be given an array of objects with key and value. As per the problem statement we need a sorted form of that array. To implement this problem we will first sort the first column of array and then second column of array. And then again arrange it in sorted form. As we understand arrays are basic data structures in computer science. Array can also ... Read More
Merging the sorted arrays together in javascript can be done using the sorting techniques available in data structures. In this problem we will be given two sorted arrays and we have to merge them. After merging them, return a single array which is also in a sorted form. For solving this problem we will use greedy approach. What are Sorted Arrays ? In javascript arrays are the collection of similar data types and we can resize the array in run time. Sorted arrays are sequential forms of items of an array. Their order should be ... Read More
Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. In this article, we will learn a python program to extract dictionaries with a given Key from a list of dictionaries. Methods Used The following are the various methods to accomplish this task: Using list comprehension and keys() function Using filter() and lambda functions Using operator.countOf() method Example Assume we have taken an input list containing dictionaries and an input ... Read More
In python we can use various internal functions like isupper(), islower() and and join() that can help us adding k symbol between case shifts. The following example will help you understand what is case shift and how we can add k symbol between them. Example Assume we have taken an input string and K. We will now add the input k symbol between Case shifts using the above methods. Case shift simply means the words shifting between uppercase and lowercase. Input inputString = tUtoRialsPoInt k = ‘# Output Resultant String after adding # between caseshifts − t#U#to#R#ials#P#o#I#nt ... Read More