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
C++ Articles - Page 345 of 719
309 Views
Suppose we have an array with even length, here different numbers in this array will represent different kinds of candies. Now each number means one candy of the corresponding kind. we have to distribute candies equally in number to brother and sister. We have to find the maximum number of kinds of candies the sister could receive.So, if the input is like [1, 1, 2, 3], then the output will be 2 as if we consider the sister has candies [2, 3] and the brother has candies [1, 1]. Now the sister has two different kinds of candies, the brother ... Read More
2K+ Views
In different platform there is very useful function called 'reshape', that function is used to reshape a matrix into a new one with different size but data will be same. So, if we have a matrix and two values r and c for the row number and column number of the wanted reshaped matrix, respectively.So, if the input is like [[5, 10], [15, 20]], row = 1 and col = 4, then the output will be [[5, 10, 15, 20]]To solve this, we will follow these steps−Define an array tempDefine one 2D array res of size (r x c)count := ... Read More
183 Views
Suppose we have a Binary Search Tree, we have to convert it into a Greater Tree such that every key of the original BST is changed to the original key + sum of all keys greater than the original key in BST.So, if the input is likethen the output will beTo solve this, we will follow these steps −Define a function revInorder(), this will take tree root and s, if root is null, then −returnrevInorder(right of root, s)s := s + val of rootval of root := srevInorder(left of root, s)From the main method, do the following −if root is ... Read More
361 Views
Suppose we have an array and an integer k, we have to find the number of unique k-diff pairs in the array. Here the k-diff pair is like (i, j), where i and j are both are present in the array and their absolute difference is k.So, if the input is like [3, 1, 4, 1, 5], k = 2, then the output will be 2, as there are two 2-diff pairs in the array-like (1, 3) and (3, 5).To solve this, we will follow these steps −Define maps called seen and doneDefine one set sif k < 0, then ... Read More
224 Views
Suppose we have two strings; we have to find the longest uncommon subsequence of these two strings. The longest uncommon subsequence is actually the longest subsequence of one string and this subsequence should not come in the other string. So, we have to find the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.So, if the input is like "aabbac", "aabbcc", then the output will be 6To solve this, we will follow these steps −if a is same as b, then −return -1Otherwisereturn maximum of size of a and size of bExample Let us see ... Read More
2K+ Views
Suppose we have to check whether a given number is perfect number or not. A number is said to be a Perfect Number when that is equal to the sum of all its positive divisors except itself. The number n will be in range 1^8.So, if the input is like 28, then the output will be True, as its sum of divisors − 1 + 2 + 4 + 7+ 14 = 28.To solve this, we will follow these steps −As the numbers are in range 10^8, there are only few perfect numbers, if the given input is in that ... Read More
219 Views
Suppose we have a list of scores of N athletes, we have to find their relative ranks and the people with the top three highest scores, who will be different medals: "Gold", "Silver" and "Bronze".So, if the input is like [2, 5, 3, 1, 0], then the output will be [Bronze, Gold, Silver, 4, 5]To solve this, we will follow these steps −if size of nums is same as 1, then −return "Gold"if size of nums is same as 2, then −if nums[0] > nums[1], then −return "Gold", "Silver"Otherwisereturn "Silver", "Gold"Define an array vDDefine an array vecfor initialize i := ... Read More
284 Views
Given a list of words, we have to find those words that can be typed using letters of the alphabet on only one row's of standard keyboard layout.So, if the input is like ["hello", "world", "mom", "dad", "try", "type", "tom"], then the output will be ["dad", "try", "type"]To solve this, we will follow these steps −Define an array outputoneRow := trueDefine one map charToRowMap, this will take all pairs such that {letter, line}, the letter is the letter present on the keyboard, and line is the line number on the keyboard.for each word in words array −if the word is ... Read More
348 Views
Suppose we have a specific rectangular web page area, our job is to design a rectangular web page, whose length L and width W that satisfies the following requirements −The area of the web page must equal to the given target area.The width W should not be larger than the length L, and L >= W.The difference between L and W should be as small as possible.So, if the input is like 4, then the output will be [2, 2], as the target area is 4, and all the possible ways to construct it are [1, 4], [2, 2], [4, ... Read More
2K+ Views
Suppose we have an array of size n, we have to find the minimum number of moves required to make all array elements the same, where a move means incrementing n - 1 elements by 1.So, if the input is like [3, 2, 3, 4], then the output will be 4.To solve this, we will follow these steps −n := size of numsif n is same as 0, then −return 0sort the array numsans := 0for initialize i := 0, when i < n, update (increase i by 1), do −ans := ans + nums[i] - nums[0]return ansExample Let us see ... Read More