Server Side Programming Articles - Page 1940 of 2650

Day of the Year in Python

Arnab Chakraborty
Updated on 29-Apr-2020 07:54:48

4K+ Views

Suppose, we have a date in the format “YYYY-MM-DD”. We have to return the day number of the year. So if the date is “2019-02-10”, then this is 41st day of the year.To solve this, we will follow these steps −Suppose D is an array of day count like [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]Convert the date into list of year, month and dayif the year is leap year then set date D[2] = 29Add up the day count up to the month mm – 1. and day count after that.ExampleLet us see ... Read More

Number of Equivalent Domino Pairs in Python

Arnab Chakraborty
Updated on 29-Apr-2020 07:52:45

326 Views

Suppose we have a list of dominos. Each domino has two numbers. Two dominos D[i] = [a, b] and D[j] = [c, d] will be same if a = c and b = d, or a = d and b = c. So one domino can be reversed. We have to return number of pairs (i, j) for which 0

Print all paths from top left to bottom right in a matrix with four moves allowed in C++

sudhir sharma
Updated on 16-Jan-2020 12:39:11

277 Views

In this problem, we are given an mXn 2D matrix and we have to print all possible paths from top left to bottom right of matrix. For traversal, we can move in all four directions i.e. left, right, top, bottom.Thought the moves right and top are rarely used but these can be beneficial sometimes.Let’s take an example to understand the topic better :Input:1 3 5 2 8 9Output:1 -> 3 -> 5 -> 9 1 -> 3 -> 8 -> 9 1 -> 2 -> 8 -> 9To solve this problem, we will move from one cell to other ... Read More

Relative Sort Array in Python

Arnab Chakraborty
Updated on 18-May-2020 05:54:15

771 Views

Suppose we have two arrays arr1 and arr2, the elements of arr2 are unique, and all elements in arr2 are also present in arr1. We have to sort the elements of arr1 in such a way that the relative ordering of items in arr1 are the same as in arr2. If there are some elements that are not present in arr2, they should be placed at the end of arr1 in ascending order. So if the arr1 is like [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], and arr2 is like [2, 1, 4, 3, 9, 6], ... Read More

Distribute Candies to People in Python

Arnab Chakraborty
Updated on 29-Apr-2020 07:45:56

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

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

sudhir sharma
Updated on 16-Jan-2020 12:29:24

550 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

Occurrences After Bigram in Python

Arnab Chakraborty
Updated on 28-Apr-2020 17:45:32

177 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

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

386 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

323 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

Advertisements