Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Find n-th element from Stern's Diatomic Series in C++
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 MoreGoat Latin in Python
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 MoreFair Candy Swap in Python
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 MorePrint all distinct characters of a string in order in C++
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 MoreProgram to print a rectangle pattern in C++
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 MoreReverse Only Letters in Python
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 MoreProgram to print all palindromes in a given range in C++
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 MoreLong Pressed Name in C++
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 MorePrint all combinations of points that can compose a given number in C++
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 MoreProgram to print all substrings of a given string in C++
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