Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1457 of 2650
362 Views
Suppose we have an array of citations of a researcher. We have to define a function to compute the researcher's h-index. As we know the h-index is a metric used to calculate the impact of a researcher's papers. Formally H-index can be defined as: "A researcher has index h if h of their N papers have at least h citations each, and the other N − h papers have no more than h citations each."So, if the input is like citations = [5, 4, 1, 2, 6], then the output will be 3, as at least 3 papers have at ... Read More
802 Views
Suppose we have a a friends list, where friends[i] is a list of people i is friends with. The connection of friendships are two-way. And each person is friend with themselves and two people are in a friend group as long as there is some path of mutual friends connecting them. We have to find the total number of friend groups.So, if the input is like friends = [[0, 1, 5], [1, 0], [2], [3, 4], [4, 3], [5, 0]], then the output will be 3, as The three friend groups are as below −To solve this, we will follow ... Read More
288 Views
Suppose we have a 2D binary matrix. For any row or column in the given matrix we can flip all the bits. If we can perform any number of these operations, and that we treat each row as a binary number, we have to find the largest sum that can be made of these numbers.So, if the input is like010001then the output will be 11, as if we flip both rows we get 101 and 110, then the sum is 5 + 6 = 11To solve this, we will follow these steps −for each row r in matrix, doif r[0] ... Read More
935 Views
The union function in base R helps us to find the union of two vectors but if we have three vectors then the union cannot be directly created. For this purpose, we need to use union function twice. For example, if we have three vectors defined as x, y, and z then the union of these vectors can be found by using the command union(x, union(y, z)).Example1Live Demo> x1 y1 z1 union(x1, union(y1, z1))Output[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Example2Live Demo> x2 x2Output[1] 13 6 16 11 9 11 3 15 ... Read More
3K+ Views
Mostly, we use histogram to understand the distribution of a variable but if we have an overlay line on the histogram that will make the chart smoother, thus understanding the variation will become easy. To display the curve on the histogram using ggplot2, we can make use of geom_density function in which the counts will be multiplied with the binwidth of the histogram so that the density line will be appropriately created.ExampleConsider the below data frame:Live Demo> x df head(df, 20)Output x 1 4 2 5 3 6 4 4 5 9 6 ... Read More
411 Views
Plotly in R is a package specifically designed to create highly-interactive and publication-quality charts. The chart can be created by using plot_ly function of the package and there are three main arguments of plot_ly defined as x, y, and type, where x refers to the X-axis, y refers to the Y-axis and type refers to the chart type but the axes values are stored in a data frame or itself a shared.ExampleLoading plotly package:> library(plotly)Consider the below data frame:Live Demo> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Creating the bar plot ... Read More
681 Views
To create a covariance matrix, we first need to find the correlation matrix and a vector of standard deviations is also required. The correlation matrix can be found by using cor function with matrix object. For example, if we have matrix M then the correlation matrix can be found as cor(M). Now we can use this matrix to find the covariance matrix but we should make sure that we have the vector of standard deviations.Example1Live Demo> M1 M1Output [, 1] [, 2] [, 3] ... Read More
3K+ Views
We can manually fill the color of bars in a bar plot which is created by using ggplot2 but for this we would be needing color aesthetics already used for the bars. That means we need to use filling of bars inside aes of ggplot2 and then the colors can be mentioned inside the scale_fill_manual function.ExampleConsider the below data frame:Live Demo> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Loading ggplot2 package and creating bar plot:Example> library(ggplot2) > ggplot(df, aes(x, count))+geom_bar(stat="identity")Output:Creating the bar plot by using scale_fill_manual:Example> ggplot(df, aes(x, count))+geom_bar(stat="identity")+scale_fill_manual(values=c("blue", "green", "grey", ... Read More
1K+ Views
Suppose we have an Android 3x3 key lock screen and two integers m and n, the values of m and n are in range 1 ≤ m ≤ n ≤ 9, We have to count the total number of unlock patterns of the Android lock screen, which consist of minimum of m keys and maximum n keys.The rule is like, each pattern must connect at least m keys and at most n keys. All the keys must be unique. If there is a line connecting two consecutive keys in the pattern passes through any other keys, the other keys must ... Read More
172 Views
Suppose we have a binary tree; we have to find the largest subtree of it where largest means subtree with largest number of nodes in it.So, if the input is like, then the output will be 3, as the Largest BST Subtree, in this case, is the highlighted one.To solve this, we will follow these steps −Define one structure called data, there will be four values, size, maxVal, minVal, and ok, the ok can hold only true/false valuessolve(TreeNode * node)if node is null, then &miuns;return Data by initializing (0, infinity, -infinity, true)left := solve(left of node)left := solve(right of node)Define ... Read More