Check for Duplicate Elements in a Series using Python

Vani Nalliappan
Updated on 24-Feb-2021 06:12:06

163 Views

Input − Assume, you have the following series, 0    1 1    2 2    3 3    4 4    5The above series contains no duplicate elements. Let’s verify using the following approaches.Solution 1Assume, you have a series with duplicate elements0    1 1    2 2    3 3    4 4    5 5    3Set if condition to check the length of the series is equal to the unique array series length or not. It is defined below, if(len(data)==len(np.unique(data))):    print("no duplicates") else:    print("duplicates found")Exampleimport pandas as pd import numpy as np data = ... Read More

Finding Three Elements with Required Sum in an Array in JavaScript

AmitDiwan
Updated on 24-Feb-2021 06:08:44

324 Views

We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should then pick three such numbers from the array, (if they exist) whose sum is equal to the number specified by the second argument.The function should finally return an array of arrays of all such triplets if they exist, an empty array otherwise.For example −If the input array and the number is −const arr = [2, 5, 7, 8, 9, 11, 1, 6]; const sum = 22;Then the output should be ... Read More

Filter Perfect Squares in a Given Series using Python

Vani Nalliappan
Updated on 24-Feb-2021 06:03:23

612 Views

Input −Assume you have a series, 0    14 1    16 2    30 3    49 4    80Output −The result for perfect square elements are, 0    4 1    16 3    49Solution 1We can use regular expression and lambda function filter method to find the perfect square values.Define a Series.Apply lambda filter method to check the value is a perfect square or not. It is defined below,    l = [14, 16, 30, 49, 80]    data=pd.Series([14, 16, 30, 49, 80])    result =pd.Series(filter(lambda x: x==int(m.sqrt(x)+0.5)**2, l))Finally, check the list of values to the series ... Read More

Determine Beautiful Number String in JavaScript

AmitDiwan
Updated on 24-Feb-2021 06:03:08

362 Views

A numeric string, str, is called a beautiful string if it can be split into a sequence arr of two or more positive integers, satisfying the following conditions −arr[i] - arr[i - 1] = 1, for any i in the index of sequence, i.e., each element in the sequence is more than the previous element.No element of the sequence should contain a leading zero. For example, we can split '50607' into the sequence [5, 06, 07], but it is not beautiful because 06 and 07 have leading zeros.The contents of the sequence cannot be rearranged.For example −If the input string ... Read More

Plot Cluster Using ClusterMaps Class in Matplotlib

Dev Prakash Sharma
Updated on 23-Feb-2021 19:45:42

289 Views

Let us suppose you have given a dataset with various variables and data points thus in order to plot the cluster map for the given data points we can use Clustermaps class.In this example, we will import the wine quality dataset from the https://archive.ics.uci.edu/ml/datasets/wine+quality.import matplotlib.pyplot as plt import numpy as np import seaborn as sns sns.set(style='white') #Import the dataset wine_quality = pd.read_csv(‘winequality-red.csv’ delimeter=‘;’)Let us suppose we have raw data of wine Quality datasets and associated correlation matrix data.Now let us plot the clustermap of the data, row_colors = wine_quality["quality"].map(dict(zip(wine_quality["quality"].unique(), "rbg"))) g = sns.clustermap(wine_quality.drop('quality', axis=1), standard_scale=1, robust=True, row_colors=row_colors, cmap='viridis')Plot the ... Read More

Check If a Given Binary Tree is a Full Binary Tree in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:41:10

2K+ Views

Given a Binary Tree, the task is to check whether it is a Full Binary Tree or not. A Binary Tree is said to be a Full Binary Tree if every node has zero or two children.For ExampleInput-1Output:1Explanation: Every node except the leaf node has two children, so it is a full binary tree.Input-2: Output:0Explanation: Node 2 has only one child, so it is not a full binary tree.Approach to Solve this ProblemTo check whether a given binary tree is full or not, we can check recursively for the left subtree and right subtree.Input a given Binary Tree having nodes and its children.A ... Read More

Find the Smallest Digit in a Given Number using C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:39:23

4K+ Views

Given a non-negative number, the task is to find its smallest digit.For exampleInput:N = 154870Output:0Explanation: In the given number '154870', the smallest digit is '0'.Approach to Solve this ProblemThe simplest approach to solve this problem is to extract the last digit in the given number using the remainder theorem. While traversing the number, we will check if the extracted digit is less than the last digit, then return the output.Take a number n as the input.An integer function smallest_digit(int n) takes 'n' as the input and returns the smallest digit in the given number.Now initialize min as the last digit of the ... Read More

Circle Sort in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:38:17

463 Views

Circle Sort is an interesting sorting algorithm to sort a given array of elements. The algorithm compares the elements of the array diametrically and once the elements in one part is sorted, then continuously sort the other end of the array diametrically.ExampleLet us visualize the circle sort for an array. Let us suppose we have an array with 6 elements.Input:N = 6arr [ ] = { 2, 1, 5, 8, 7, 9 }When we draw concentric circles for each array element, then it will appear as followsOutput:1 2 5 7 8 9Explanation: After sorting the elements in the array using Circle ... Read More

Copy List with Random Pointer in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:35:41

804 Views

A Linked List is a linear data structure in which each node is having two blocks such that one block contains the value or data of the node and the other block contains the address of the next field.Let us assume that we have a linked list such that each node contains a random pointer which is pointing to other nodes in the list. The task is to construct the list with the same as the original list. Copying the list from the original list which is having some random pointer is called a 'Deep Copy' of the linked list.For ... Read More

Find the Number of 1 Bits in a Large Binary Number in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:34:20

3K+ Views

Given a 32-bit Unsigned Binary Number, the task is to count the set bits, i.e., '1's present in it.For ExampleInput:N = 00000000000000100111Output:4Explanation: Total set bits present in the given unsigned number is 4, thus we will return the output as '4'.Approach to Solve this ProblemWe have given an unsigned 32-bit binary number. The task is to count how many '1's present in it.To count the number of '1's present in the given binary number, we can use the inbuilt STL function '__builin_popcount(n)' which takes a binary number as the input parameter.Take a binary number N as the input.A function count1Bit(uint32_t n) ... Read More

Advertisements