Found 26504 Articles for Server Side Programming

How to check if a data frame column contains duplicate values in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 07:25:26

2K+ Views

To check if a data frame column contains duplicate values, we can use duplicated function along with any. For example, if we have a data frame called df that contains a column ID then we can check whether ID contains duplicate values or not by using the command −any(duplicated(df$ID))Example1Consider the below data frame − Live DemoID

Find speed of man from speed of stream and ratio of time with up and down streams in C++

sudhir sharma
Updated on 16-Mar-2021 06:41:00

151 Views

In this problem, we are given two values S and N denoting the speed of stream in Km/h and ratio of time with up and down streams. Our task is to Find speed of man from the speed of stream and ratio of time with up and down streams.Let’s take an example to understand the problem, InputS = 5, N = 2Output15Solution ApproachA simple solution to the problem is by using the mathematical formula for the rowing problems. So, let’s see how the formula will work −speed of man = x km/h speed of stream = S km/h speed of ... Read More

Find smallest permutation of given number in C++

sudhir sharma
Updated on 16-Mar-2021 06:38:31

836 Views

In this problem, we are given a large number N. Our task is to find the smallest permutation of a given number.Let’s take an example to understand the problem, InputN = 4529016Output1024569Solution ApproachA simple solution to the problem is by storing the long integer value to a string. Then we will sort the string which is our result. But if there are any leading zeros, we will shift them after the first non zero value.Program to illustrate the working of our solution, Example Live Demo#include using namespace std; string smallestNumPer(string s) {    int len = s.length();    sort(s.begin(), s.end()); ... Read More

Find smallest number with given number of digits and sum of digits in C++

sudhir sharma
Updated on 16-Mar-2021 06:37:29

1K+ Views

In this problem, we are given two values that are the sum (denoting the sum of digits) and digit (denoting the number of digits). Our task is to find the smallest number with a given number of digits and sum of digits.Let’s take an example to understand the problem, Inputsum = 15, dgiti = 2Output69ExplanationAll 2 digits numbers with sum 15 are : 69, 78, 87, 96.Solution ApproachA simple solution to the problem is by considering all the numbers with digit count as digit and find the smallest number whose sum of digit is equal to the sum.An efficient solution ... Read More

Find smallest and largest elements in singly linked list in C++

sudhir sharma
Updated on 16-Mar-2021 06:35:28

890 Views

In this problem, we are given a singly linked list. Our task is to find the smallest and largest elements in single linked list.Let’s take an example to understand the problem, Inputlinked List : 5 -> 2 -> 7 -> 3 ->9 -> 1 -> 4OutputSmallest element = 1 Largest element = 9Solution ApproachA simple solution to the problem is using by traversing the linked list node by node. Prior to this, we will initialise maxElement and minElement to the value of the first element i.e. head -> data. Then we will traverse the linked list element by element. And ... Read More

Find smallest and largest element from square matrix diagonals in C++

sudhir sharma
Updated on 16-Mar-2021 06:33:02

1K+ Views

In this problem, we are given a square matrix of size nXn. Our task is to Find smallest and largest element from square matrix diagonals. We need to find the smallest and largest elements of the primary and secondary diagonals of the matrox.Let’s take an example to understand the problem, Inputmat[][] = {    {3, 4, 7},    {5, 2, 1},    {1, 8, 6} }OutputSmallest element in Primary Diagonal = 2 Largest element in Primary Diagonal = 6 Smallest element in Secondary Diagonal = 1 Largest element in Secondary Diagonal = 7Solution ApproachA simple solution to solve the problem ... Read More

Find single Movement in a Matrix in C++

sudhir sharma
Updated on 16-Mar-2021 06:30:24

141 Views

In this problem, we are given four values x1, y1, x2, y2 denoting two points (x1, y1) and (x2, y2). Our task is to find single movement in a Matrix. We need to find the direction using which we can move from one point (x1, y1) to (x2, y2). There can be any number of moves by the direction needed to be single and we need to return the direction in the form - “left” , “right”, “up”, “down”. Otherwise return -1, denoting “not possible”.Let’s take an example to understand the problem, Inputx1 = 2, y1 = 1, x2 = ... Read More

Find size of the largest ‘+’ formed by all ones in a binary matrix in C++

sudhir sharma
Updated on 16-Mar-2021 06:26:29

231 Views

In this problem, we are given an NxN binary matrix bin[][]. Our task is to find the size of the largest ‘+’ formed by all ones in a binary matrix.Let’s take an example to understand the problem, Input0 1 1 1 1 1 0 1 0Output5Solution ApproachA simple solution to the problem is to find the largest ‘+’ for which we need to find the maximum number of 1’s in one direction for a point in the matrix which needs to be the same in all four directions for a given 1. For this, we will create one matrix for ... Read More

Find single in an array of 2n+1 integer elements in C++

sudhir sharma
Updated on 16-Mar-2021 06:22:50

303 Views

In this problem, we are given an array consisting of (2n+ 1) integer values. Out of all these values, n elements appear twice in the array and there is only one element in the array that appears once. Our task is to Find single in an array of 2n+1 integer elements.Let’s take an example to understand the problem, Inputarr[] = {1, 3, 5, 6, 5, 1, 3}Output5Solution ApproachA simple solution to the problem is using a counter for the elements. If an element is encountered, store its value and occurrence count. After this search for the element in the table ... Read More

Find shortest unique prefix for every word in a given list in C++

sudhir sharma
Updated on 16-Mar-2021 06:19:50

224 Views

In this problem, we are given an array of words arr[]. Our task is to find the shortest unique prefix for every word in the given list.Let’s take an example to understand the problem, Inputarr[] = {“learn”, “programming”, “code”}Outputc leap lear pSolution ApproachA simple solution to the problem is by finding all the prefixes of the word. And then check if it is a prefix of any other word in the array. If it is not, print it.An efficient approach is to use the trie data structure. We will construct a trie and store all words. Then find the frequency ... Read More

Advertisements