
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
Found 33676 Articles for Programming

345 Views
Suppose we have a list of closed intervals and another list of intervals. Individually, each list is non-overlapping and they are sorted in non-decreasing order. We have to find the overlap of the two intervals sorted in non-decreasing order.So, if the input is like inv1 = [[50, 100],[190, 270],[310, 330]] inv2 = [[40, 120],[180, 190]], then the output will be [[50, 100], [190, 190]]To solve this, we will follow these steps −ans := a new listi := 0, j := 0while i < size of A and j < size of B, doif start

1K+ Views
Suppose we have a list of intervals where each list represents an interval [start, end] (inclusive). We have to find the total unique duration it covers.So, if the input is like intervals = [[2, 11], [13, 31], [41, 61]], then the output will be 50, as the total unique covered distance is (11 - 2 + 1) = 10 then (31 - 13 + 1) = 19 and (61 - 41 + 1) = 21, so total is 50.To solve this, we will follow these steps −if intervals list is empty, thenreturn 0sort the list intervals[start, end] := intervals[0]ans := ... Read More

235 Views
Suppose we have a sorted and disjoint intervals list and another list cut, that represents an interval. We have to delete all parts of intervals that are intersecting with cut interval, and return the new list.So, if the input is like intervals = [[2, 11], [13, 31], [41, 61]] cut = [8, 46], then the output will be [[2, 8], [46, 61]]To solve this, we will follow these steps −cut_start, cut_end := cutans := a new listfor each start, end in intervals, doif maximum of cut_start and start < minimum of end and cut_end, thenif start < cut_start, theninsert interval ... Read More

699 Views
Suppose we have a binary search tree BST and another value of a node, we have to find the in-order successor of that node in the BST. As we all know that the successor of a node p is the node with the smallest key greater than the value of p.So, if the input is likeAnd p = 1, then the output will be 2, To solve this, we will follow these steps −Define recursive method inorderSuccessor(), this will take root and pif root null, then:return nullif val of root val val){ return inorderSuccessor(root->right, ... Read More

533 Views
Suppose we have a list of numbers called nums and we are placed currently at nums[0]. On each step, we can either jump from the current index i to i + 1 or i - 1 or j where nums[i] == nums[j]. We have to find the minimum number of steps required to reach the final index.So, if the input is like nums = [4, 8, 8, 5, 4, 6, 5], then the output will be 3, as we can jump from index 0 to index 4 as their values are both 4. And then we jump back to index ... Read More

349 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

790 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

278 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

915 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