Server Side Programming Articles

Page 1424 of 2109

Greatest Common Divisor of Strings in Python

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

Suppose there are two strings A and B. We can say that A is divisible by B, when A is created by concatenating B one or more times. So if A = “abcabc”, and B = “abc”, then A is divisible by B. In this section, we will see what is the greatest common divisor of a String. So return the largest string that divides both of the strings. So if two strings are “ABABAB”, and “ABAB”, then GCD will be “AB”To solve this, we will follow these steps −temp := shorter string between A and Bm := length of ...

Read More

Height Checker in Python

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

Suppose a set of students have to be arranged in non-decreasing order of their heights for a photograph. If we have an array of students, we have to return the minimum number of students that are not present in correct position. So if the array is like [1, 1, 4, 2, 1, 3], then output will be 3. So students with height 4, 3 and the last 1 are not standing in the correct position.To solve this, we will follow these steps −answer := 0let x := Array in sorted formley y := Arrayfor i := 0 to size of ...

Read More

Find minimum of each index in list of lists in Python

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 2K+ Views

In some problems we need to identify the minimum of each element in a list. But in solving the matrix operations, we need to find the minimum of each column in the matrix. That needs us to find the minimum value from list of lists. Because each column of a matrix is a list of lists.Using min() and zip()In the below example we use the min() and zip(). Here the zip() function organizes the elements at the same index from multiple lists into a single list. Then we apply the min() function to the result of zip function using a ...

Read More

Print all the duplicates in the input string in C++

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

In this problem, we are given a string and we have to find all the characters that are duplicated along with their number of occurrences in the string.Let’s take an example to understand the problem −Input: TutorialsPoint Output: t (3) o (2) i (2)Explanation− The frequencies of occurrence of each character are t → 3; u → 1; o → 2; r → 1; i → 2; a → 1; s → 1; n → 1.Now, to solve this problem we will find the character count and store it in an array from the string. And then print the characters ...

Read More

Contains Duplicate in Python

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

Suppose we have a list of numbers. We have to check whether the list is holding some duplicate elements or not. So if the list is like [1, 5, 6, 2, 1, 3], then it will return 1 as there are two 1s, but if the list is [1, 2, 3, 4], then it will be false, as there is no duplicate present.To solve this, we will follow this approach −We know that the set data structure only holds unique data. But the list can fold duplicate contents. So if we convert the list into the set, its size will ...

Read More

Complement of Base 10 Integer in Python

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

Suppose we have a number in decimal number system. We have to get the complement of the number in binary form, then again change it to decimal and return the result. So if the number is 20, then the binary form will be 10100, the complement will be 01011, this is 11 in decimalTo solve this, we will follow these steps −s := binary string of the number nsum := 0 and num := 1for each element i in s in reverse directionif i = ‘b’, then return sumotherwise when i = ‘0’, then sum := sum + numnum := ...

Read More

Sorting string in Descending order C++

Ajay yadav
Ajay yadav
Updated on 11-Mar-2026 766 Views

The sorting in ascending or descending order, however, can duly be performed by using string sort method and other means too in the C++ programming. But here, the string compare (first words with the second) and copy (copy the first word in a temp variable) method involved in the inner and outer traversing loop to put the words in descending order as following.Example#include using namespace std; int main(){    char str[3][20]={"Ajay","Ramesh","Mahesh"};    char t[20];    int i, j;    for(i=1; i

Read More

Print all the combinations of a string in lexicographical order in C++

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

In this problem, we are given string str, and we have to print all the combinations of the characters in a lexicographical order.Let’s take an example to understand the problem better −Input: str = ‘XYZ’ Output : X XY XYZ XZ XZY Y YX YXZ YZ YZX Z ZX ZXY ZY ZYXTo solve this problem, we will print all the combinations of characters in the string. For this, we need a map data structure to store the characters of the string. For the implementation, we will need to use backtracking to keep track of all combinations.Example#include using namespace std; ...

Read More

Defanging an IP Address in Python

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

Suppose we have a valid IPv4 IP address. We have to return the Defanged version of the IP address. A Defanged IP address is basically replace every period “.” by “[.]” So if the IP address is “192.168.4.1”, the output will be “192[.]168[.]4[.]1”To solve this, we will follow these steps −We will split the string using dot, then put each element separated by “[.]”ExampleLet us see the following implementation to get better understanding −class Solution(object):    def defangIPaddr(self, address):       address = address.split(".")       return "[.]".join(address) ob1 = Solution() print(ob1.defangIPaddr("192.168.4.1"))Input"192.168.4.1"Output"192[.]168[.]4[.]1"

Read More

Duplicate Zeros in Python

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

Suppose we have a fixed length array of integers, we have to duplicate each occurrence of zero, shifting the remaining elements to the right side.Note that elements beyond the length of the original array are not written.So suppose the array is like [1, 0, 2, 3, 0, 4, 5, 0], then after modification it will be [1, 0, 0, 2, 3, 0, 0, 4]To solve this, we will follow these steps −copy arr into another array arr2, set i and j as 0while i < size of arr −if arr2[i] is zero, thenarr[i] := 0increase i by 1if i < ...

Read More
Showing 14231–14240 of 21,090 articles
Advertisements