Add a Month to a Date in R

Nizamuddin Siddiqui
Updated on 21-Aug-2020 05:49:26

704 Views

We have to deal with date data in time series analysis, also sometimes we have a time variable in data set that is recorded to perform another type of analysis. Depending on our objective, we need to process the data and the time variable is also converted into appropriate form that we are looking for. If we want to create a sequence of months from date data then we can do it by adding a month to each upcoming month. This can be easily done by using AddMonths function of DescTools package.ExampleInstalling DescTools package −install.packages("DescTools") Loading DescTools package: library(DescTools) AddMonths(as.Date('2020/01/31'), ... Read More

Maximum Value with Choice in C++

Ayush Gupta
Updated on 21-Aug-2020 05:33:51

109 Views

In this tutorial, we will be discussing a program to find maximum value with the choice of either dividing or considering as it is.For this we will be provided with an integer value. Our task is to find the maximum value with either by dividing the number into four parts recursively or choosing it as it is using the given function F(n) = max( (F(n/2) + F(n/3) + F(n/4) + F(n/5)), n).Example Live Demo#include using namespace std; //calculating the maximum result int findMaximum(int size) {    int term[size + 1];    term[0] = 0;    term[1] = 1;    int i=2;    while(i

Minimum Sum of Distance to A and B in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:40:14

138 Views

Suppose we have a ring, which is made of few numbers from 1 to N. We also have tow numbers A and B. Now, we can stand at any place (say x) and perform the count operation with respect of the total sum of the distance (say Z = distance from X to A + distance from X to B). We have to select X such that Z is minimized. At the end return the value of Z. We have to keep in mind that X will not be same as A and B.So, if the input is like N ... Read More

Minimum Positive Integer Divisible by A with Digit Sum B in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:37:36

268 Views

Suppose we have two numbers A and B, we have to find the minimum positive number M so that M is divisible by A and the sum of the digits of M is same as B. So, if there is no such result, then return -1.So, if the input is like A = 50, B = 2, then the output will be 200 as this is divisible by 50 and sum of its digit = 2 + 0 + 0 = 2.To solve this, we will follow these steps −Define one element type container, that contains two numbers a and ... Read More

Minimum Maximum Length of Jump to Last Island in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:33:21

202 Views

Suppose we have an array A of numbers, in A the i-th number is the position where an island is present, and another integer k is given (1 ≤ k < N). Now, a person is standing on the 0-th island and has to reach the last island, by jumping from one island to another in exactly k jumps, we have to find the minimum of the maximum length of a jump a person will make in his/her journey. We have to keep in mind that the position of all the islands are given in ascending order.So, if the input ... Read More

Find Minimum Number of Rectangles Left After Inserting One into Another in C++

Arnab Chakraborty
Updated on 20-Aug-2020 08:28:52

218 Views

Suppose we have width and height of N different rectangles; we have to find the minimum number of rectangles left after inserting one into another. So, if W1 and W2 be the width of rectangles R1 and R2 respectively. And H1 and H2 be the height of R1 and R2 respectively, then if W1 < W2 and H1 < H2 then rectangle R1 fits inside rectangle R2. Thus, the smallest one can fit into second smallest, then that fits into the next and so on.So, if the input is like {{ 30, 45 }, { 15, 15 }, { 45, ... Read More

Find Minimum Moves to Move Between Cells in Matrix using Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:23:08

373 Views

Suppose we have one N X N matrix M, and this is filled with 1, 0, 2, 3, We have to find the minimum numbers of moves required to move from source cell to destination cell. While visiting through blank cells only, we can visit up, down, right and left.Cell with value 1 indicates Source.Cell with value 2 indicates Destination.Cell with value 3 indicates Blank cell.Cell with value 0 indicates Blank Wall.There will be only one source and only one destination cells. There may be more than one path to reach destination from source cell. Now, each move in matrix ... Read More

Minimum Preprocess Moves to Make Two Strings Equal in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:15:59

265 Views

Suppose we have two strings P and Q of same lengths with only lower case letters, we have to count the minimum number of pre-processing moves on string P are needed to make it equal to string Q after applying below operations −Select any index i and swap characters pi and qi.Select any index i and swap characters pi and pn – i – 1.Select any index i and swap characters qi and qn – i – 1.Note − The value of i in range (0 ≤ i < n)In one move we can change a character in P with any ... Read More

Find Minimum Length Unsorted Subarray to Sort in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:03:50

412 Views

Suppose we have a given unsorted array A[0..n-1] of size n, we have to find the minimum length subarray A[s..e] so that by sorting this subarray the whole array will be sorted. So, if the array is like [2, 6, 4, 8, 10, 9, 15], then the output will be 5. The subarray will be [6, 4, 8, 10, 9].To solve this, we will follow these steps −res := sort the nums as an arrayans := 0set r as a linked listfor i in range 0 to length of resif nums[i] is not same as res[i], then insert i into ... Read More

Find Minimum Difference Between Shifted Tables of Two Numbers in Python

Arnab Chakraborty
Updated on 20-Aug-2020 08:02:29

156 Views

Suppose we have two numbers p and q, we have to find the minimum difference between any terms in the shifted infinite tables of p and q, these shifts are r and s, where r, s >= 0.So, if the input is like p = 7 and q = 17, r = 6 and s = 3, then the output will be 0 as, table of 7 = [7, 14, 21, 28, 35, 42, 49, ...] and table of 17 = [17, 34, 51, 68, 85, 102, 119, ...], then shifted table of 7 will be [13, 20, 27, 34, ... Read More

Advertisements