
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 7197 Articles for C++

237 Views
Suppose we have a non-negative integer represented as non-empty a singly linked list of digits, now we have to plus one to the integer. We may assume the integer do not contain any leading zero, except the number 0 itself. In the linked list the most significant digit is at the head of the list.So, if the input is like [1, 2, 3], then the output will be [1, 2, 4]To solve this, we will follow these steps −if head is null, then −return headcurr = headreq = NULLwhile curr is non-zero, do −if val of curr is not equal ... Read More

650 Views
Suppose we have a binary tree. We will collect and remove all leaves and repeat until the tree is empty.So, if the input is likethen the output will be [[4, 5, 3], [2], [1]]To solve this, we will follow these steps −Define one map szDefine one 2D array retDefine a function dfs(), this will take node, if node is null, then −sz[val of node] := 1 + maximum of dfs(left of node) and dfs(right of node)if size of ret < sz[val of node], then −Define an array tempinsert temp at the end of retinsert val of node at the end ... Read More

679 Views
Suppose we want to design a hit counter which counts the number of hits received in the past 5 minutes. There will be a function and that accepts a timestamp parameter in the second unit and we may assume that calls are being made to the system in chronological order (so, the timestamp is monotonically increasing). We also assume that the earliest timestamp starts at 1.It is possible that several hits arrive roughly at the same time.So we will call the hit() function to hit and getHits() function to get the count of hits.To solve this, we will follow these ... Read More

359 Views
Suppose we have a 2D grid, here each cell is either a wall 'W', an enemy 'E' or that is empty '0', We have to find the maximum enemies we can kill using one bomb. The bomb kills all the enemies in the same row and column from the planted point until it hits the wall. And we can put bombs only on blank spaces.So, if the input is likethen the output will be 3, as placing bomb at the green place, it will kill three enemies.To solve this, we will follow these steps −ret := 0n := row count ... Read More

257 Views
Suppose we have a sorted array of integer nums and integer values a, b and c. We have to apply a quadratic function of the form f(x) = ax^2 + bx + c to each element x in the array. And the final array must be in sorted order.So, if the input is like nums = [-4, -2, 2, 4], a = 1, b = 3, c = 5, then the output will be [3, 9, 15, 33]To solve this, we will follow these steps −Define function f(), that takes x, a, b, c −return ax^2 + bx + cFrom ... Read More

491 Views
Suppose we have n points on a 2D plane, we have to check whether there is any line parallel to y-axis that reflect the given points symmetrically, in other words, check whether there exists a line that after reflecting all points over the given line the set of the original points is the same that the reflected ones.So, if the input is like points = [[1, 1], [-1, 1]]then the output will be trueTo solve this, we will follow these steps −Define one set okn := size of pointsminVal := infmaxVal := -inffor initialize i := 0, when i < ... Read More

574 Views
Suppose we have a singly linked list where elements are arranged in non-decreasing order, we have to convert it to a height balanced binary search tree. So if the list is like [-10, -3, 0, 5, 9], The possible tree will be like −To solve this, we will follow these steps −If the list is empty, thenreturn nullDefine a recursive method called sortedListToBST() this will take list start nodex := address of the previous node of mid node from list amid := exact mid nodecreate a new node with value by taking from value of midnextStart := next of mid ... Read More

698 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

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

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