Found 26504 Articles for Server Side Programming

Print all permutations with repetition of characters in C++

sudhir sharma
Updated on 14-Jul-2020 07:25:19

1K+ Views

In this problem, we are given a string of n characters and we have to print all permutations of characters of the string. Repeating of characters of the string is allowed. The printing of permutation should be done in alphabetical order (lexicographically sorted order).Let’s take an example to understand the topic better :Input − XYOutput − XX, XY, YX, YYTo solve this problem, we need to use fix and recur logic. Here, we will fix one element at first index of the array and then recursively call for the next elements in the sequence.Let’s see an implementation example which will ... Read More

Printing Different pattern Bash in C++

Ajay yadav
Updated on 16-Jan-2020 12:20:09

375 Views

This article is intended to print a half-pyramid pattern bash using the C++ programming language. In the view of the stipulated pattern to be printed, the following algorithm is being orchestrated to achieve our goal as;AlgorithmStep-1 Set the length of the Bash (Height) Step-2 Outer loop to handle the number of rows Step-3 Inner loop to handle columns Step-4 Print the pattern with the character (@) Step-5 Set the pointer to a new line after each row (outside the inner loop) Step-6 Repeat the loop till the Bash HeightExampleSo, the following C++ source code is ultimately carved out by complying ... Read More

Printing Interesting pattern in C++

Ajay yadav
Updated on 16-Jan-2020 12:18:55

312 Views

This article prints an interesting pattern using C++ programming. Here is the algorithm as followingAlgorithmStep-1 Define the size which will be double automatically Step-2 Print the upper section using a loop Step-3 Print the lower section using a loopExampleBased on the above algorithm, the following c++ code is carved out as; Live Demo#include using namespace std; int main(){    int n=3;    int i,j;    // This is upper half of pattern    for (i=1; i

Printing Pyramid using Recursion in C++

Ajay yadav
Updated on 16-Jan-2020 12:18:13

940 Views

This article aims to print a pyramid pattern by using the recursive implementation of C++ programming. Here is the algorithm as following to do so;AlgorithmStep-1 Set the height of the pyramid Step-2 Adjust space using recursion function Step-3 Adjust Hash(#) character using recursion function Step-4 Call both functions altogether to print the Pyramid patternExampleAs said the above algorithm, the following genuine C++ code economics is written as following; Live Demo#include using namespace std; // function to print spaces void print_space(int space){    if (space == 0)       return;    cout

Proj() function for Complex Numbers in C++

Ajay yadav
Updated on 16-Jan-2020 12:14:34

158 Views

This article demonstrate the functioning of proj() in order to perform projection upon complex numbers. Here the syntax of the proj() method in c++ programming as follows;template complex proj (const complex& z);ExampleThe proj() method takes a parameter as argument which represent the complex number and returns the projection of complex number described below in the sample as; Live Demo#include #include using namespace std; int main(){    std::complex c1(3, 5);    cout

Last Stone Weight in Python

Arnab Chakraborty
Updated on 28-Apr-2020 17:36:07

1K+ Views

Suppose we have some rocks, each rock has a positive integer weight. In each turn, we will take two heaviest rocks and smash them together. consider the stones have weights x and y and x 1:          stones.sort()          s1,s2=stones[-1],stones[-2]          if s1==s2:             stones.pop(-1)             stones.pop(-1)          else:             s1 = abs(s1-s2)             stones.pop(-1)             stones[-1] = s1       if len(stones):          return stones[-1]       return 0 ob1 = Solution() print(ob1.lastStoneWeight([2,7,4,1,6,1]))Input[2,7,4,1,6,1]Output1

Two City Scheduling in C++

Arnab Chakraborty
Updated on 28-Apr-2020 17:33:00

503 Views

Suppose there are 2N persons. A company wants to organize one interview. The cost for flying the i-th person to city A is costs[i][0], and the cost for flying the i-th person to city B is costs[i][1]. We have to find the minimum cost to fly every person to a city, such that N people arrive in every city. So if the given list is [[10, 20], [30, 200], [400, 50], [30, 20]] The output will be 110. So we will send the person P1 to city A with cost 10, Second person to city A with cost 30, third ... Read More

Partition Array Into Three Parts With Equal Sum in Python

Arnab Chakraborty
Updated on 28-Apr-2020 17:30:30

457 Views

Suppose we have an array A of integers, our output will be true if and only if we can partition the array into three non-empty parts whose sum is equal.Formally, we can partition the array if we can find the indexes i+1 < j with (A[0] + A[1] + ... + A[i] is same as A[i+1] + A[i+2] + ... + A[j-1] and A[j] + A[j-1] + ... + A[A.length - 1])So if the input is [0, 2, 1, -6, 6, -7, 9, 1, 2, 0, 1], then the output will be true. Three arrays will be [0, 2, 1], ... Read More

Pairs of Songs With Total Durations Divisible by 60 in Python

Arnab Chakraborty
Updated on 28-Apr-2020 17:27:04

2K+ Views

Suppose we have a list of songs, the i-th song has a duration of time[i] seconds. We have to find the number of pairs of songs for which their total time in seconds is divisible by 60.So if the time array is like [30, 20, 150, 100, 40], then the answer will be 3. Three pairs will be (3, 150), (20, 100), (20, 40) for all cases the total duration is divisible by 60.To solve this, we will follow these steps −Take a map rem to store remainders. Set ans := 0for all elements i in time −if i is ... Read More

Sum of Even Numbers After Queries in Python

Arnab Chakraborty
Updated on 28-Apr-2020 17:19:35

3K+ Views

Suppose we have an array of integers called A, and an array queries. For the i-th query value = queries[i][0] and index = queries[i][1], we will add value to A[index]. Then, the answer of the i-th query is the sum of the even values of A. We have to find the answer to all queries. We will find an array, that should have answer[i] as the answer to the i-th query. So if the array is like [1, 2, 3, 4], and the query array is like [[1, 0], [-3, 1], [-4, 0], [2, 3]], then the answer array will ... Read More

Advertisements