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

199 Views
Suppose we have a Binary Search Tree and one target value; we have to check whether there exist two elements in the BST such that their sum is equal to the given target or not.So, if the input is likethen the output will be True.To solve this, we will follow these steps −Define an array vDefine a function inorder(), this will take root, if root is null, then −returninorder(left of root)insert value of root into vinorder(left of root)Define a function findnode(), this will take k, n := size of vwhile i < j, do −t := v[i] + v[j]if t ... Read More

274 Views
Suppose there is a set S that is originally containing numbers from 1 to n. But unfortunately, due to some error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.Now if we have an array called nums that is representing the data status of this set after the error. Our task is to find the number occurs twice and then find the number that is missed. return the results in the form of an array.So, if the input is like [1, 2, ... Read More

185 Views
Suppose we have an array with n elements, we have to find the contiguous subarray of given length k that has the maximum average value. We have to return the maximum average value.So, if the input is like [1, 13, -5, -8, 48, 3] and k = 4, then the output will be 12.0, as (13-5-8+48)/4 = 12.0.To solve this, we will follow these steps −sum := 0for initialize i := 0, when i < k, update (increase i by 1), do −sum := sum + nums[i]maxi := sumfor initialize i := k, when i < size of nums, update ... Read More

204 Views
Suppose we have a non-empty binary tree; we have to find the average value of the nodes on each level in the return the average values as an array.So, if the input is likethen the output will be [3, 14.5, 11].To solve this, we will follow these steps −Define an array resultDefine one queue qinsert root into qwhile (not q is empty), do −n := size of qDefine an array tempwhile n is non-zero, do −t := first element of qinsert value of t into tempdelete element from qif left of t is not null, then −insert left of t ... Read More

1K+ Views
Suppose we have a non-negative integer c, we have to decide whether there're two integers a and b such that it satisfies a^2 + b^2 = c.So, if the input is like 61, then the output will be True, as 61 = 5^2 + 6^2.To solve this, we will follow these steps −Define a function isPerfect(), this will take x, sr := square root of xreturn true when (sr - floor of sr) is 0From the main method do the following, if c is same as 0, then −return truefor initialize i := 0, when i < the ceiling of ... Read More

800 Views
Suppose we have an integer array; we have to find three numbers whose product is maximum then return the maximum product.So, if the input is like [1, 1, 2, 3, 3], then the output will be 18, as the three elements are [2, 3, 3].To solve this, we will follow these steps −sort the array numsl := size of numsa := nums[l - 1], b := nums[l - 2], c := nums[l - 3], d := nums[0], e := nums[1]return maximum of a * b * c and d * e * aExample Let us see the following implementation to get ... Read More

1K+ Views
Suppose we have a long flowerbed in which some of the plots are planted and some are empty. Now there is a constraint, flowers cannot be planted in adjacent plots, they would compete for water and both would die. So if we have a flowerbed, represented by an array containing 0 and 1, 0 indicates empty and 1 indicates fill, and a number n is also given, we have to check whether n new flowers can be planted in it without violating the no-adjacent-flowers rule or not.So, if the input is like flowerbed = [1, 0, 0, 0, 1], n ... Read More

193 Views
Suppose there are two fiends Amal and Bimal want to choose a restaurant for dinner, now they both have a list of favorite restaurants represented by strings. We have to help them to find out their common interest with the least list index sum. If there is a choice tie between different answers, then return all of them with no order requirement.So, if the input is like ["ABC", "PQR", "MNO", "XYZ"], and ["TUV", "GHI", "KLM", "ABC"], then the output will be ["ABC"]To solve this, we will follow these steps −Define one map mpleast := inffor initialize i := 0, when ... Read More

215 Views
Suppose we have one m * n matrix called M and this is initialized with all 0's and we also have several update operations. Now, operations are represented by a 2D array, and each operation is represented by an array with two positive integers x and y, it means M[i][j] should be added by one for all values i in range 0 to a - 1 and all values j in range 0 to b - 1. We have to find the count of the number of maximum integer in the matrix after performing all the operations.So, if the input ... Read More

511 Views
Suppose we have an integer array; we have to find the length of its longest harmonious subsequence among all its possible subsequences. As we know a harmonious sequence array is an array where the difference between its maximum value and its minimum value is exactly 1.So, if the input is like [1, 3, 2, 2, 5, 2, 3, 7], then the output will be 5, as the longest harmonious subsequence is [4, 3, 3, 3, 4].To solve this, we will follow these steps −Define one map mfor n in nums −(increase m[n] by 1)for key-value pair (k, v) in m ... Read More