Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

Find n-th element from Stern's Diatomic Series in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 212 Views

Here we will see how to find the nth term in Sternโ€™s Diatomic series. The series is like 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, โ€ฆ This is also known as fusc function. This series can be defined as โˆ’๐‘(๐‘›)=$p\lgroup\frac{n}{2}\rgroup$ ๐‘คโ„Ž๐‘’๐‘› ๐‘› ๐‘–๐‘  ๐‘’๐‘ฃ๐‘’๐‘›๐‘(๐‘›)=$p\lgroup\frac{n-1}{2}\rgroup+p\lgroup\frac{n+1}{2}\rgroup$ ๐‘คโ„Ž๐‘’๐‘› ๐‘› ๐‘–๐‘  ๐‘œ๐‘‘๐‘‘๐‘(0)=0 ๐‘Ž๐‘›๐‘‘ ๐‘(1)=1Here we will use the Dynamic programming approach to reduce the number of computations. After saving the base case for p(0) and p(1), we will iterate from index i = 2 to n, and compute p(i)Example#include using namespace std; int findTerm(int n) ...

Read More

Goat Latin in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 715 Views

Suppose we have a set of strings (Sentence), in that set there are few words. Each words are consists of lowercase and uppercase letters. Our task is to convert the sentence into Goat-Latin form. The Goat Latin is similar to the Pig Latin. There are some few conditions.If the word starts with a vowel, then append โ€˜maโ€™ with the wordIt the word starts with a consonant, then remove that from beginning, and append it at the end, then add โ€˜maโ€™ at the end.Add one letter โ€˜aโ€™ to the end of each word per its word index in the sentence, starting ...

Read More

Fair Candy Swap in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 593 Views

Suppose A and B are two friends. They have candy bars of different sizes. Here A[i] is the size of the i-th bar of candy owned by A, and B[j] is the size of the j-th bar of candy owned by B.Since they are friends, they want to exchange one candy bar each so that after the exchange, both A and B have the same total amount of candy. (The total amount of candy a person has is the sum of the sizes of candy bars they have.) We have to return an integer array suppose ans, where ans[0] is ...

Read More

Print all distinct characters of a string in order in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

In this problem, we are given a string. Our task is to print all distinct characters of the string in the order they appear in the string.Letโ€™s take an example to understand our problem, Input: tutorials Point Output: uralsPnThere are multiple ways to solve this problem but we will discuss the most effective one. The simple one includes the nesting of loops.For this, we will use two arrays of size 256(8-bit characters are stored).First we will initialize all values of counter array to 0 and all values of index array to n (length of string). On traversal of the string ...

Read More

Program to print a rectangle pattern in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 970 Views

In this tutorial, we will be discussing a program to print a given rectangular pattern.For this we will be given with the height and the breath of the rectangle. Our task is to print the rectangle with the given dimensions using the โ€œ@โ€ character.Example#include using namespace std; void print_rec(int h, int w){ ย  ย for (int i=0; i

Read More

Reverse Only Letters in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a string S, we have to find the reversed string where all characters that are not a letter will not change their positions and all letters reverse their positions. So if the given string is "a-bC-dEf-ghIj", then output will be "j-Ih-gfE-dCba"To solve this, we will follow these steps โˆ’We will use the regular expression library to solve thisif S is empty, then return Sstr := an empty string, index1 := 0 and index2 := length of S โ€“ 1while index1 < length of Sif index2 >= 0 and S[index1] is alphabet and S[index2] is alphabetstr := str ...

Read More

Program to print all palindromes in a given range in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 587 Views

In this tutorial, we will be discussing a program to print all palindromes in a given range.For this we will be given the mathematical range in which the palindromes are to be found. Our task is to find all the palindromes in that range and print it back.Example#include using namespace std; //checking if the number is a palindrome int is_palin(int n){ ย  ย int rev = 0; ย  ย for (int i = n; i > 0; i /= 10) ย  ย rev = rev*10 + i%10; ย  ย return (n==rev); } void countPal(int min, int max){ ย  ย for (int i = min; i

Read More

Long Pressed Name in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 355 Views

Suppose a man is typing some name on keyboard. Sometimes some buttons are long-pressed by mistake. So it may type one or more extra character. So we will take two strings, and check whether the second string is long-pressed name or not. So if the name is โ€œAmitโ€, and second string is โ€œAmmitttโ€ is longpressed name. But โ€œAmmtttโ€ is not, because character i is not present here.To solve this, we will follow these steps โˆ’let j := 0for i := 0, i < second.size, increase i by 1 โˆ’if j < actual_name.size and actual_name[j] = second[i], thenincrease j by 1return ...

Read More

Print all combinations of points that can compose a given number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 306 Views

In this problem, we are given the total score n. Print all combinations of basketball points that are 1, 2, and 3 that give a total score of n.Letโ€™s see an example to understand the problem, Input: 4 Output: 1 1 1 1 1 1 2 1 2 1 1 3 2 1 1 2 2 3 1To solve this problem, we will use recursion. And fix and resources for rest values n-s, where s is the score. If the combination adds up to n, print the combination.ExampleThe code shows the implementation of our code โˆ’#define MAX_POINT 3 #define ARR_SIZE ...

Read More

Program to print all substrings of a given string in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we will be discussing a program to print all the substring of a given string.For this we will be given with a string or an array of characters. Our task is to print all the substrings of that particular string.Example#include using namespace std; //printing all the substrings void print_substr(char str[], int n){ ย  ย for (int len = 1; len

Read More
Showing 28311โ€“28320 of 61,297 articles
Advertisements