sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 64 of 98

Print a String in wave pattern in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 611 Views

In this problem, we are given a string and an integer n. Our task is to print the given string in a wave pattern of n lines.Let’s take an example to understand the problem, Input: Tutorial n = 3 Output: T             r    U       o       i       s       t                lWave patterns are printed by printing each character of the string one by one in the next line and tab space away from the next element till ...

Read More

Print a pattern without using any loop in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 754 Views

In this problem, we are given a number n. Our task is to print patterns with decreasing to 0 or negative then increasing back to the number.Let’s take an example to understand the problem,Input: n = 12 Output: 12 7 2 -3 2 7 12To solve this problem, we will use recursion and call the function after each update. The track of update is kept using the flag variable which tells the function to increase or decrease the number by 5.ExampleThe below code gives the implementation of our solution,#include using namespace std; void printNextValue(int m){    if (m > 0){       cout

Read More

Print all permutations in sorted (lexicographic) order in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 624 Views

In this problem, we are given a string of length n and we have to print all permutations of the characters of the string in sorted order.Let’s take an example to understand the problem :Input: ‘XYZ’Output: XYZ, XZY, YXZ, YZX, ZXY, ZYX.Here we have to print all permutations in lexicographical order (alphabetically increasing order).To solve this problem, we have to first sort the array in alphabetically increasing order, the sorted array is the first element of the permutation. And then generate the next higher order permutation of the string.The below code will make the solution more clear to you :Example#include ...

Read More

Print all permutation of a string using ArrayList in Java

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 831 Views

In this problem, we are given a string of size n and we have to print all permutations of the string. But this time we have to print this permutation using ArrayList.Let’s take an example to understand the problem -Input − string = ‘XYZ’Output − XYZ, XZY, YXZ, YZX, ZXY, ZYXTo solve this problem, we will be generating all permutations of the character of the string. We will use a recursive function and will return arrayList.ExampleThe following is ArrayList implementation of the algorithm −import java.util.ArrayList; public class Main{    static void printArrayList(ArrayList combo) {       combo.remove("");     ...

Read More

Print all paths from a given source to a destination in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 451 Views

In this problem we are given a directed graph and we have to print all paths from the source to the destination of the graph.Directed graph is a graph in with edges that are directed from vertex a to b.Let’s take an example to understand the problem Source = K destination = POutput:K -> T -> Y -> A -> P K -> T -> Y -> P K -> A -> PHere, we have found paths from K to P. We have traversed paths and printed all paths from K that direct us to P.To solve this problem, we will ...

Read More

Print all palindromic paths from top left to bottom right in a matrix in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 274 Views

In this problem, we are given a matix which contains aplhabets (lowercase only) and we have to print all palidromic paths in the given matrix from top left to bottom right of the matrix.Allowed moves in this problem are right and down. Diagonal moves are not allowed.Let’s take an example to understand the problem −Input: matrix[][] ={    {"xxxy",    "yxxx",    "xyyx"} Output: xxxxxx , xxxxxx , xyxxyxExplainationLets see all valid moves from top left to bottom right using the position wrt to ith position.i00 -> i01 -> i02 -> i03 -> i13 -> i23 = xxxyxx i00 -> ...

Read More

Print all palindromic partitions of a string in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 275 Views

In this problem, we are given a palindromic string. And we have to print all the partitions of this string. In this problem, we will find all possible palindrome partitions of the string by cutting it.Let’s take an example to understand the problem -Input − string = ‘ababa’Output − ababa , a bab a, a b a b a ….The solution, to this problem, is to check if a substring is a palindrome or not. And print the substring if it is substring.ExampleThe below program will illustrate the solution −#include using namespace std; bool isPalindrome(string str, int low, int high){ ...

Read More

Print all palindrome permutations of a string in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 451 Views

In this problem, we are given a string and we have to print all the palindromic permutations that are possible from the characters of that string.Let’s take an example to understand the problem −Input − string = ‘aabb’Output − abba baabTo solve this problem we have to take the characters of the string and one by one generate all palindrome strings using these characters.Step 1 − Check if the string is a palindrome or not, print ‘Not Possible’ if not.Step 2 − If it can make palindrome, then make it into half and lexicographically select each letter of string.Step 3 ...

Read More

Print all pairs with given sum in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 540 Views

In this problem, we are given an array of integers and an integer sum and we have to print all pairs of integers whose sum is equal to the sum value.Let’s take an example to understand the problem :Input − array = {1, 6, -2, 3} sum = 4Output − (1, 3) , (6, -2)Here, we need pairs with the given sum value.A simple solution to the problem will be checking pairs of elements that generate the sum. This can be done by traversing array and find the number in array that sums up to sum value.ExampleThis program will illustrate ...

Read More

Print all triplets with given sum in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 326 Views

In this problem, we are given an array of unique integers and a sum. And we have to find the triplets which can form the same sum.Let's take an example to solve the problem −Input : array = {0 , 2 , -1 , 1, -2} Sum = 1 Output : 1 2 -2 0 2 -1To solve this problem, we will be finding all the triplets that provide the sum. A simple approach will be using three loops and finding the sum of the elements and return the adequate triplet.Example#include using namespace std; void Triplets(int arr[], int n, ...

Read More
Showing 631–640 of 975 articles
« Prev 1 62 63 64 65 66 98 Next »
Advertisements