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
Programming Articles - Page 2135 of 3366
772 Views
In this problem, we are given an integer n. Our task is to print all possible pairs of n balanced parentheses.Balanced parentheses are parentheses pairs that have a closing symbol for every corresponding opening symbol. Also, pairs should be properly nested.Let’s take an example to understand the problem, Input: n = 2 Output: {}{} {{}}To solve this problem, we need to keep track of pairs of brackets. The initial count of brackets is 0. Then we will recursively a function till the total bracket count is less than n. Count brackets, recursively call for brackets based on the count. If ... Read More
302 Views
In this problem, we are given a number n. Our task is to print all combinations of factors of n.Let’s take an example to understand the topic better −Input: 24 Output: 2 2 2 3 2 4 3 8 3 4 6 2 12For this, we will use recursion function which will find a combination of factors of the number. And we will store all our combinations in an array of array.ExampleThis code will show the implementation of our solution. Live Demo#include using namespace std; vector factor_Combo; void genreateFactorCombinations(int first, int eachFactor, int n, vectorfactor) { if (first>n || eachFactor>n) ... Read More
236 Views
In this problem, we are given the total score n. Print all combinations of basketball points that are 1, 2, and 3 that give a total score of n.Let’s see an example to understand the problem, Input: 4 Output: 1 1 1 1 1 1 2 1 2 1 1 3 2 1 1 2 2 3 1To solve this problem, we will use recursion. And fix and resources for rest values n-s, where s is the score. If the combination adds up to n, print the combination.ExampleThe code shows the implementation of our code − Live Demo#define MAX_POINT 3 #define ... Read More
1K+ Views
In this problem, we are given a string. Our task is to print all distinct characters of the string in the order they appear in the string.Let’s take an example to understand our problem, Input: tutorials Point Output: uralsPnThere are multiple ways to solve this problem but we will discuss the most effective one. The simple one includes the nesting of loops.For this, we will use two arrays of size 256(8-bit characters are stored).First we will initialize all values of counter array to 0 and all values of index array to n (length of string). On traversal of the string ... Read More
234 Views
In this problem, we are given a string and an integer M. our task is to print all distinct circular strings of length M in lexicographical order (alphabetical order).Let’s take an example to understand the problem, Input: str= “ssssn” M=3 Output: nss sns ssn sssExplanation − all possible circular strings of length 3 are: sss sss ssn sns nss. Distinct elements in lexicographical order are sss ssn sns nss.To solve this problem, we will iterate over the elements of the string and generate all possible substrings of length M. we will store this generated string in a set that stores ... Read More
850 Views
In this problem, we are given an array of integer values. Our task is to print all distinct elements of the array. The output should contain only distinct values.Let’s take an example to understand the problemInput: array = {1, 5, 7, 12, 1, 6, 10, 7, 5} Output: 1 5 7 12 6 10To solve this problem, we will have to check elements of the array for uniqueness. For this, we will use two nested loops, the outer one will take values and the inner one will check the rest of the values with it. If more than one values ... Read More
270 Views
In this problem, we are given an array of N integers and a number K. Our task is to print all distinct numbers that can be created by adding any K elements from the array. While choosing any number can be repeated K times.Let’s take an example to understand the problem −Input: array = {2, 5, 13, 9} K = 2 Output: 2, 7, 15, 11, 10, 18, 14, 26, 22 Explaination: 2 elements added : 2+2=4, 2+5=7, 2+13=15, 2+9=11, 5+5=10, 5+13=18, 5+9=14, 13+13=26, 13+9=22, 9+9=18To solve this problem, we will find all combinations of the k element from the ... Read More
324 Views
In this problem, we are given a string that may contain duplicate characters. Our task is to print all distinct permutations of the strings.Let’s take an example to understand the problem −Input: string = “XYZ” Output: XYZ XZY YXZ YZX ZYX ZXYTo solve this problem, we have to fix one element of the string. And then iterate all the elements of the strings.ExampleProgram to implement our solution, Live Demo#include #include using namespace std; int compare(const void* a, const void* b) { return (*(char*)a - *(char*)b); } void swapChar(char* a, char* b) { char t = *a; ... Read More
789 Views
Method reference is one of a way in a lambda expression to refer a method without executing it. In the body part of a lambda expression, we can call another method if they are compatible with a functional interface. We can also capture "this" and "super" keywords in method references.In the below two examples, we can create a thread with the help of "this" and "super" keywords using method reference.Example of this keywordpublic class MethodRefThisTest { public void runBody() { for(int i = 1; i < 10; i++) { System.out.println("Square of " + i + " ... Read More
411 Views
A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will find all even nodes of a binary search tree using C++. Find Even-Valued Nodes in BST You are given a binary search tree (BST) as input, and your task is to write a program that finds all the nodes with even values and returns them as output. To understand better, let's consider the ... Read More