 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 280 of 719
 
 
			
			330 Views
Suppose we have a partially filled Sudoku grid and we have to solve this. We know that Sudoku is a 9 × 9 number grid, and the whole grid are also divided into 3 × 3 boxes There are some rules to solve the Sudoku.We have to use digits 1 to 9 for solving this problem.One digit cannot be repeated in one row, one column or in one 3 × 3 box.Using backtracking algorithm, we will try to solve Sudoku problem. When some cell is filled with a digit, it checks whether it is valid or not. When it is ... Read More
 
 
			
			2K+ Views
Suppose we have two strings S and T. We have to check whether S is subsequence of T or not.So, if the input is like S = "abc", T = "adbrcyxd", then the output will be TrueTo solve this, we will follow these steps −if s is same as t, then −return truen := size of s, m := size of tj := 0for initialize i := 0, when i < n, update (increase i by 1), do −if t[j] is same as s[i], then −(increase j by 1)if j is same as size of t, then −return truereturn falseLet ... Read More
 
 
			
			1K+ Views
Suppose we have two numbers as string. We have to multiply them and return the result also in string. So if the numbers are “28” and “25”, then the result will be “700”To solve this, we will follow these steps −Taking two arguments x and y it indicates x divides yif x < −Infinity and y = 1, then return infinitya := |x|, b := |y| and ans := 0while a − b >= 0p := 0while a − (left shifted b (left shifted 1 p times)) >= 0p := p + 1a := a − (left shift b, p ... Read More
 
 
			
			1K+ Views
Suppose we have one input string sentence where each element is stored as single character, we have to reverse the strings word by word.So, if the input is like ["t", "h", "e", " ", "m", "a", "n", " ", "i", "s", " ", "n", "l", "c", "e"], then the output will be ["n", "l", "c", "e", " ", "i", "s", " ", "m", "a", "n", " ", "t", "h", "e"]To solve this, we will follow these steps −reverse the array sj := 0n := size of sfor initialize i := 0, when i < n, update (increase i by 1), ... Read More
 
 
			
			383 Views
Suppose we have a linked list. We have to rotate the list to the right by k places. The value of k will be positive. So if the list is like [1 −> 2 −> 3 −> 4 −> 5 −> NULL], and k = 2, then the output will be [4 −> 5 −> 1 −> 2 −> 3 −> NULL]Let us see the steps −If the list is empty, then return nulllen := 1create one node called tail := headwhile next of tail is not nullincrease len by 1tail := next of tailnext of tail := headk := ... Read More
 
 
			
			766 Views
Suppose we have a rod is given of length n. We also have a list, that contains different size and price for each size. We have to find the maximum price by cutting the rod and selling them in the market. To get the best price by making a cut at different positions and comparing the prices after cutting the rod.So, if the input is like prices = [1, 5, 8, 9, 10, 17, 17, 20], n = 8, then the output will be 22, as by cutting the rod in length 2 and 6. The profit is 5 + ... Read More
 
 
			
			174 Views
Suppose we have a list of numbers called nums and another number k, we can remove any sublist at most once from the list. We have to find the length of the longest resulting list such that the amount of numbers strictly less than k and strictly larger than k is the same.So, if the input is like nums = [6, 10, 8, 9, 3, 5], k = 6, then the output will be 5, as if we remove the sublist [9] then we will get [6, 10, 8, 3, 5] and there are two numbers [3, 5] which are ... Read More
 
 
			
			499 Views
Suppose we have a set of intervals; we have to find the minimum number of intervals that should be removed to make the rest of the intervals non-overlapping. So if the intervals are [[8, 10], [3, 5], [6, 9]], then the output will be 1, as we have to remove [6, 9] to make all others are non-overlapping.To solve this, we will follow these steps −n := size of arrayif n is 0, then return 0count := 1sort the array based on the end time of the intervalsend := end date of the first intervalfor i in range 1 to ... Read More
 
 
			
			14K+ Views
Suppose we have postfix expression and we have to evaluate the value. Postfix expression is also known as Reverse polish notation. Here we have to use the stack data structure to solve the postfix expressions.So if the expression is “21+3*”, then the answer will be 9.Let us see the steps −for each character ch in the postfix expression, doif ch is an operator $\odot$ , thena := pop first element from stack, b := pop second element from the stackres := b $\odot$ apush res into the stackelse if ch is an operand, thenadd ch into the stackreturn element of ... Read More
 
 
			
			127 Views
Suppose we have a positive number n, we have to find the least number of perfect square numbers whose sum is same as n. So if the number is 10, then the output is 2, as the numbers are 10 = 9 + 1.To solve this, we will follow these steps −create one table for dynamic programming, of length n + 1, and fill it with infinitydp[0] := 0for i := 1, when i*i dp(n+1,INF); dp[0] = 0; for(int i =1;i*i