
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++

338 Views
Suppose there are n soldiers standing in a line. Here each soldier is assigned a unique rating value. We have to make a team of 3 soldiers amongst them using the following rules −Choose 3 soldiers with index (i, j, k) such that the rating (rating[i], rating[j], rating[k]).A team will be valid if − (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]).We have to find the number of teams we can form. (soldiers can be part of multiple teams).So, if the input is like rating = [2, 5, 3, 4, 1], then the output will be 3, ... Read More

252 Views
Suppose we have a matrix consists of 0 and 1, we have to find the distance of the nearest 0 for each cell. Here the distance between two adjacent cells is 1.So, if the input is like000010111then the output will be000010121To solve this, we will follow these steps −Define an array dir of size: 4 x 2 := {{1, 0}, { - 1, 0}, {0, - 1}, {0, 1}}n := row count, m := column countDefine one matrix ret of order (n x m) and fill this with infDefine one queue qfor initialize i := 0, when i < n, ... Read More

173 Views
Suppose we have a list of strings; we have to find the longest uncommon subsequence among them. The longest uncommon subsequence is actually the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings.We know that a subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements.Here we will take a list of strings, and the output needs to be the length of the longest uncommon subsequence. If there is no longest uncommon subsequence, then return -1.So, if ... Read More

319 Views
Suppose we have an array of scores that are non-negative integers. The first player picks one of the numbers from either end of the array followed by the second player and then the first player and so on. Each time a player picks a number, that number will not be available for the other player. This continues until all the scores have been chosen. The player who has got the maximum score wins. So, if we have the scores array, we have to predict whether player 1 is the winner.So, if the input is like [1, 5, 233, 7], then ... Read More

268 Views
Suppose we have a binary tree, a target node, and a one value K. We have to find a list of the values of all nodes that have a distance K from the target node.So, if the input is like root = [3, 5, 1, 6, 2, 0, 8, null, null, 7, 4], target = 5, K = 2, then the output will be [7, 4, 1], this is because the nodes that are a distance 2 from the target node have values 7, 4, and 1.To solve this, we will follow these steps −Define a function dfs(), this will ... Read More

679 Views
Suppose we have n cities connected by m flights. Each flight starts from u and arrives at v with a price w. If we have all the cities and flights, together with starting city src and the destination dst, here our task is to find the cheapest price from src to dst with up to k stops. If there is no such route, then return -1.So, if the input is like n = 3, edges = [[0, 1, 100], [1, 2, 100], [0, 2, 500]], src = 0, dst = 2, k = 1, then the output will be 200To ... Read More

411 Views
Suppose we have one unrooted tree; this is one undirected graph with no cycles. The given input is a graph that started as a tree with N nodes (values of the nodes are distinct values ranging from 1 through N), with one additional edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.The final graph is given as a 2D-array of edges. Each element of edges is a pair [u, v] where u < v, that represents an undirected edge connecting nodes u and v.We have to find ... Read More

246 Views
We are given the root of a binary tree and two integers, val and depth. The root of the binary tree is at depth 1. Our task is to add a new row of nodes with value val at the given depth. If the depth is 1, we have to create a new root node with value val and make the original tree its left child. If the depth is greater than 1, we go to all nodes at depth depth - 1, add new left and right child nodes with value val, and connect the original left and right ... Read More

457 Views
Suppose we have a string containing only digits, we have to restore it by returning all possible valid IP address combinations. We know that a valid IP address consists of exactly four integers (each integer is in range 0 to 255) separated by single points.So, if the input is like "25525511135", then the output will be ["255.255.11.135", "255.255.111.35"]To solve this, we will follow these steps −Define a function convertToNum(), this will take s, start, end, num := 0for initialize i := start, when i 255, then −return 10000return numDefine a function addDots(), this will take positions, res := blank ... Read More

227 Views
Suppose we have a binary tree where each path going from the root to any leaf form a valid sequence, we have to check whether a given string is a valid sequence in such binary tree or not.We will get the given string from the concatenation of an array of integers arr and the concatenation of all values of the nodes along a path results in a sequenceSuppose we have a binary tree like.So, if arr = [0, 1, 0, 1], then the output will be True, as the path 0 -> 1 -> 0 -> 1 is a valid ... Read More