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

384 Views
Suppose Rima plays the following game, that is loosely based on the card game "21". So Rima starts with 0 points, and draws numbers while she has less than K points. Now, during each draw, she gains an integer number of points randomly from the range [1, W], where W is given, and that is an integer. Now each draw is independent and the outcomes have equal probabilities. Rima stops drawing numbers when she gets K or more points. We have to find the probability that she has N or less points?So if N = 6, K is 1 and ... Read More

2K+ Views
Suppose we have a string S, we will perform some replacement operations that replace groups of letters with new ones. In each replacement operation there are 3 parameters − a starting index i, a source word x and a target word y. Now the rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. otherwise, we do nothing.So as an example, consider, if we have S = "abcd" and we have some replacement operation i = 2, x = "cd", y = "ffff", then because "cd" ... Read More

252 Views
Suppose some people will make friend requests. We know their ages, these are stored in ages[i]. So this indicates that the age of the ith person. Now a A will NOT friend request person B (B != A) if any of the following conditions are true −age[B] age[A]age[B] > 100 && age[A] < 100Otherwise, A will friend request B. You can consider that if A requests B, B does not necessarily request A. And also, people will not friend request themselves. So we have to find how many total friend requests are made?Suppose if the age array is like ... Read More

208 Views
Suppose we have a list of positive integers; whose value is greater than 1. We will make a binary tree, using these integers, and each number may be used as many times as we want. Each non-leaf node should be the product of its children. So we have to find how many trees can we make? The answer will be returned in modulo 10^9 + 7. So if the input is like [2, 4, 5, 10], then the answer will be 7, as we can make 7 trees like [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, ... Read More

662 Views
Suppose on a table are N cards, with a positive integer printed on both side of each card (possibly different). We have to flip any number of cards, and after we choose one card. If the number X on the back side of the chosen card is not on the front of any card, then the number X is known as good. We have to find the smallest number that is good? When no number is good, return 0. Here, fronts[i] and backs[i] represent the number on the front and back side of card i. A flip will swap the ... Read More

238 Views
Suppose we have a list of words, we may encode it by writing a reference string S and a list of indexes A. So for example, let us consider if the list of words is ["time", "me", "bell"], then we can write it as S = "time#bell#" and indexes = [0, 2, 5]. Here for each index, we will recover the word by reading from the reference string from that index until we reach the "#" symbol.So we have to find what is the length of the shortest reference string S possible that encodes the given words? So for the ... Read More

412 Views
Suppose we have given a head; this is the head node of a linked list containing unique integer values. Now we are also given the list G, a subset of the values in the linked list. We have to find the number of connected components in G, where two values are connected if they appear consecutively in the linked list. So if the list is like [0, 1, 2, 3] and G = [0, 1, 3], then output will be 2, as 0 and 1 are connected, so there are two lists [0, 1] and [3].To solve this, we will ... Read More

155 Views
Suppose we partition a row of numbers A into at most K adjacent groups, then we will set score as the sum of the average of each group. We have to find that what is the largest score that we can achieve. Suppose A = [9, 1, 2, 3, 9] and K is 3, then the result will be 20, this is because, the best choice is to partition A into [9], [1, 2, 3], [9]. So the answer is 9 + (1 + 2 + 3) / 3 + 9 = 20. We could have also partitioned A into ... Read More

324 Views
Suppose we are playing a simplified Pacman game. Now we start at the point (0, 0), and our destination is (target[0], target[1]). There are several ghosts on the map, Here the i-th ghost starts at (ghosts[i][0], ghosts[i][1]). In each turn, we and all ghosts simultaneously (may) move in one of 4 cardinal directions − north, east, west, or south, going from the last point to a new point 1 unit of distance away. We can escape if and only if we can reach the target before any ghost reaches us (for any given moves the ghosts may take.) If we ... Read More

479 Views
Suppose In a forest, each rabbit has some color. Now some subset of rabbits (possibly all of them) will tell us how many other rabbits have the same color as them. Those answers are placed in an array. We have to find the minimum number of rabbits that could be in the forest. So if the input is like [1, 1, 2], then the output will be 5, as the two rabbits that answered "1" that could both be the same color, say white. Now the rabbit than answered "2" can't be white or the answers would be inconsistent. Say ... Read More