Found 26504 Articles for Server Side Programming

Find the next identical calendar year in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:54:41

241 Views

Suppose we have an year Y. Find next identical calendar year to Y. So the calendar of 2017 is identical with 2023.A year X is identical to given previous year Y if it matches these two conditions.x starts with the same day as year, If y is leap year, then x also, if y is normal year, then x also normal year.The idea is to check all years one by one from next year. We will keep track of number of days moved ahead. If there are total 7 moved days, then current year begins with same day. We also ... Read More

Find the fractional (or n/k – th) node in linked list in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:51:30

267 Views

Suppose we have a singly linked list and the number k. We have to write a function to find the (n/k)th element, where n is the number of elements in the list. For decimals, we will choose the ceiling values. So if the list is like 1, 2, 3, 4, 5, 6, and k = 2, then output will be 3, as n = 6 and k = 2, then we will print n/k th node so 6/2 th node = 3rd node that is 3.To solve this we have to follow some steps like below −Take two pointers called ... Read More

To print all elements in sorted order from row and column wise sorted matrix in Python

Niharikaa Aitam
Updated on 20-Jun-2025 19:18:12

292 Views

In Python, we may go through the matrices that are sorted in a particular order. A common case is a matrix where each row and each column is sorted in increasing order, and this does not mean that the entire matrix is sorted. In such cases, we need to extract all elements and print them in a fully sorted order. Row and Column-wise Sorted Matrix? A row and column-wise sorted matrix means each row is sorted from left to right, and each column is sorted from top to bottom. For example, let's consider the following matrix - matrix = ... Read More

Find the count of substrings in alphabetic order in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:37:36

150 Views

Suppose we have a string of length n. It contains only uppercase letters. We have to find the number of substrings whose character is occurring in alphabetical order. Minimum size of the substring will be 2. So if the string is like: “REFJHLMNBV”, and substring count is 2, they are “EF” and “MN”.So to solve this, we will follow these steps −Check whether str[i] + 1 is same as the str[i+1], if so, then increase the result by 1, and iterate the string till next character which is out of alphabetic order, otherwise continue.Example Live Demo#include using namespace std; int countSubstr(string ... Read More

Python - Check if all elements in a List are same

Niharikaa Aitam
Updated on 20-Jun-2025 18:37:26

28K+ Views

In Python, a list is a collection of ordered and mutable elements enclosed in square braces[]. Each element in a list has a unique position index, starting from 0. It can accept duplicate elements. In some cases, we may need to check if all the elements in a list are identical or not to detect a special condition in algorithms. Let's go through the different methods to check if all elements in a list are the same or not. Using set() function The Python set() function (built-in) is an unordered collection of unique elements. To check if all elements in a list ... Read More

Find the count of Strictly decreasing Subarrays in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:34:05

247 Views

Suppose we have an array A. And we have to find the total number of strictly decreasing subarrays of length > 1. So if A = [100, 3, 1, 15]. So decreasing sequences are [100, 3], [100, 3, 1], [15] So output will be 3. as three subarrays are found.The idea is find subarray of len l and adds l(l – 1)/2 to result.Example Live Demo#include using namespace std; int countSubarrays(int array[], int n) {    int count = 0;    int l = 1;    for (int i = 0; i < n - 1; ++i) {       ... Read More

Generate two output strings depending upon occurrence of character in input string in Python

Niharikaa Aitam
Updated on 20-Jun-2025 19:19:22

151 Views

In Python, a string is one of the data structures that is a sequence of characters enclosed within single quotes '' or double quotes "". It is immutable, i.e., once a string is created, it cannot be changed. When we want to generate two output strings based on character occurrence in Python, we have to follow the steps below - First, we need to initialize a dictionary or use the collections.Counter class to count the frequency of each character in the input string. Next, we have to go through the input ... Read More

Find the count of numbers that can be formed using digits 3 and 4 only and having length at max N in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:31:23

110 Views

Given a number N. We have to find the count of such numbers that can be formed using digit 3 and 4. So if N = 6, then the numbers will be 3, 4, 33, 34, 43, 44.We can solve this problem if we look closely, for single digit number it has 2 numbers 3 and 4, for digit 2, it has 4 numbers 33, 34, 43, 44. So for m digit numbers, it will have 2m values.Example Live Demo#include #include using namespace std; long long countNumbers(int n) {    return (long long)(pow(2, n + 1)) - 2; } int main() {    int n = 3;    cout

Find the first repeated word in a string in Python using Dictionary

Pradeep Elance
Updated on 19-Dec-2019 12:30:11

2K+ Views

In a given sentence there may be a word which get repeated before the sentence ends. In this python program, we are going to catch such word which is repeated in sentence. Below is the logical steps we are going to follow to get this result.Splits the given string into words separated by space.Then we convert these words into Dictionary using collectionsTraverse this list of words and check which first word has the frequency > 1Program - Find the Repeated WordIn the below program we use the counter method from the collections package to keep a count of the words.Example Live ... Read More

Exploring Correlation in Python

Pradeep Elance
Updated on 19-Dec-2019 12:26:02

564 Views

Correlation is a statistical term to measure the relationship between two variables. If the relationship is string, means the change in one variable reflects a change in another variable in a predictable pattern then we say that the variables are correlated. Further the variation in first variable may cause a positive or negative variation in the second variable. Accordingly, they are said to be positively or negatively correlated. Ideally the value of the correlation coefficient varies between -1 to +1.If the value is +1 or close to it then we say the variables are positively correlated. And they vary in ... Read More

Advertisements