Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 195 of 2544
How to find the sum of division in R if zero exists in the vectors?
To find the sum of division if zero exists in the vectors, we need to assign NA to zeros in both the vectors and then use the sum function with na.rm set to TRUE. For example, if we have two vectors x and y that contains some zeros then we can divide x by y using the below commands −x[x==0] y yOutput[1] 1 5 3 1 9 1 3 8 9 0 1 7 3 2 3 3 2 9 3 1 9 5 5 2 5 4 4 7 4 5 9 1 9 9 4 2 3 [38] ...
Read MoreEquidigital Numbers in C++
Equidigital numbers are mathematically special numbers in which the number of digits in the number is equal to the number in its prime factorization.In this problem, we are given an integer value n. Our task is to create a program to all equidigital numbers up to n.Let’s take an example to understand the problem, Input: n = 12Output: 1 2 3 5 7 10 11Solution Approach:A simple solution to the problem would be finding the factors of the number and check if the number of primes is equal to the number of digits in the number .The prime factors can be ...
Read MoreProgram to find size of sublist where product of minimum of A and size of A is maximized in Python
Suppose we have a list of numbers called nums and another value pos. We have to find a sublist A of nums that includes the index pos such that (minimum of A) * (size of A) is maximized then return the value.So, if the input is like nums = [-2, 2, 5, 4] pos = 3, then the output will be 8, as the best sublist is [5, 4], because (5, 4) = 4 and its size is 2 we have 4 * 2 = 8.To solve this, we will follow these steps −ans := A[pos], m := A[pos]i := ...
Read MoreHow to change the width of whisker lines in a boxplot using ggplot2 in R?
In R, by default the whisker lines are as wide as the box of the boxplot but it would be great if we reduce that width or increase it because it will get attention of the viewer in that way. This can be done by using the width argument inside the stat_boxplot function of ggplot2 package. Check out the below example to understand how it works.ExampleConsider the below data frame −Example> x y df dfOutputx y 1 B 5 2 B 4 3 A 6 4 A 9 5 B 2 6 B 4 7 B 6 8 B 2 ...
Read MoreCheck if absolute difference of consecutive nodes is 1 in Linked List in Python
Suppose, we have a singly linked list where each node contains an integer value. We have to find out if the absolute difference between two successive nodes is 1.So, if the input is like start_node->5->6->7->8->7->6->5->4, then the output will be True.To solve this, we will follow these steps −temp := start_nodewhile temp is not null, doif temp.link is same as null, thencome out from the loopif |value of (temp) - value of (temp.link)| is not same as 1, thenreturn Falsetemp := temp.linkreturn TrueExampleLet us see the following implementation to get better understanding −import math class link_node: def __init__(self, value): ...
Read MoreEquilibrium index of an array in C++
In this problem, we are given an array arr[] consisting of n integer values. Our task is to create a program to find the equilibrium index of an array.Equilibrium Index is the index at which the sum of all elements before the index is the same as the sum of all elements after the index.For array arr[] of size n, the equilibrium index is e such that, sum (arr[0… e-1] ) = sum (arr[e… n-1])Let’s take an example to understand the problem, Input: arr[] = {5, 1, 2, 8, 3, 4, 1}Output: 3Explanation: arr[0] + arr[1] + arr[2] = arr[4] + arr[5] + arr[6]=> ...
Read MoreProgram to find number of sublists containing maximum and minimum after deleting only one element in Python
Suppose we have a list of numbers called nums and we can delete at most one element in the list. We have to find the maximum number of sublists that contain both the maximum and minimum values of the resulting list.So, if the input is like nums = [3, 2, 6, 2, 4, 10], then the output will be 8, as if we remove 10 we will get [3, 2, 6, 2, 4] and there are eight sublists where it contains both the max and the min −[2, 6][6, 2][2, 6, 2][3, 2, 6][6, 2, 4][2, 6, 2, 4][3, 2, ...
Read MoreHow to create a column in an R data frame that contains the multiplication of two columns?
Sometimes we need the multiplication of two columns and create a new column so that the multiplication can be used further for analysis. For example, to calculate BMI we need mass and height and the height is squared, therefore, we would be needing the square of height. For this purpose, we can either multiply height with height or simply take the square both the ways work. Hence, if only have height column in an R data frame then we can multiply it with itself.ExampleConsider the below data frame −> set.seed(957) > x y z df dfOutputx y z 1 0 ...
Read MoreEuler Method for solving differential equation in C++
In this problem, we are given a differential equation f(x, y) = dy/dx with initial value y(x0) = y0. Our task is to find the solution of the equation using the Euler method for solving differential equations.EULER METHODEuler method also known as forward euler Method is a first order numerical procedure to find the solution of the given differential equation using the given initial value.For a differential equation f(x, y) = dy / dx. Euler method is defined as, y(n+1) = y(n) + h * f( x(n), y(n) )The value h is step size which is calculated as, h = (x(n) - x(0)) ...
Read MoreCount palindrome words in a sentence in C++
We are given a string containing an English sentence. The goal is to find the number of words in the string that are palindromes. Palindrome words are those that when read from start or end have the same alphabet sequence. If the sentence is “Madam speaks good Malayalam”, then count of palindrome words is 2. (Madam and Malayalam)Note − Words can contain both upper and lowercase alphabets.Let us understand with examples.Input − str = "My Mom and Anna left at Noon";Output − Count of palindrome words in a sentence are − 3Explanation − Palindrome words in above sentence are − ...
Read More