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 2151 of 3366
1K+ Views
Suppose we want to distribute some number of candies to a row of n people in the following way −We then give 1 candy to the first people, 2 candies to the second people, and so on until we give n candies to the last people.After that, we go back to the start of the row again, give n + 1 candies to the first people, n + 2 candies to the second people, and so on until we give 2 * n candies to the last people.We will repeat this process until we run out of candies. The last ... Read More
765 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 − Live Demoimport java.util.ArrayList; public class Main{ static void printArrayList(ArrayList combo) { combo.remove(""); ... Read More
553 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 Live ... Read More
180 Views
Suppose there are words given. These are first and second, consider occurrences in some text of the form "first second third", here second comes immediately after the first, and third comes immediately after the second.For each such cases, add "third" into the answer, and show the answer. So if the text is like “lina is a good girl she is a good singer”, first = “a”, second = “good”, the answer will be [girl, singer]To solve this, we will follow these steps −text := split the string by spacesres is an empty listfor i := 0 to size of text ... Read More
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
389 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
326 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
951 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
165 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
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