Programming Articles

Page 1183 of 2547

Print all longest common sub-sequences in lexicographical order in C++

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

In this problem, we are given two string str1 and str2. Our task is to create a program to Print all longest common subsequences in lexicographical order. Let’s take an example to understand the problem,  Input: str1 = “gfare” ,  str2 = “rfare”Output: fareSolution ApproachIn this problem, we will find all possible longest common subsequences and store them in a 2D matrix using Dynamic programming. After this, we will print sorted output by searching characters from a to z in the LCS.Program to illustrate the working of our solution, Example#include #include #define MAX 100 using namespace std; int LCSLength = 0; int ...

Read More

Write a Golang program to search an element in a sorted array

Kiran P
Kiran P
Updated on 11-Mar-2026 686 Views

Approach to solve this problemStep 1: Iterate the array from the 0th index to n-1, where n is the size of the given array.Step 2: Declare low=0th index and high=n-1. Start a for loop till low is lesser than high.Step 3: Find mid=(low+high)/2, if the element at the middle is equal to key, then return mid index.Step 4: If the element at mid is greater than the key, then make high = mid.Step 5: If the element at mid is lesser than the key, then make low = mid + 1.Step 6: If key is not present in the given ...

Read More

Print a number as string of 'A' and 'B' in lexicographic order in C++

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

In this problem, we are given a number N. Our task is to create a program to Print a number as string of ’A’ and ‘B’ in lexicographic order. Representation of all numbers as string of ‘A’ and ‘B’ is1 = A 2 = B 3 = AA 4 = AB 5 = BA 6 = BB 7 = AAA 8 = AABLet’s take an example to understand the problem,  Input: N = 12Output: BABSolution ApproachThe string of ‘A’ and ‘B’ is similar to a binary number. To find the string, we will first find the length of string, using the fact that there are 2 numbers of length 1 ...

Read More

How to create a categorical variable using a data frame column in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

If a variable is numerical then it can be converted into a categorical variable by defining the lower and upper limits. For example, age starting from 21 and ending at 25 can be converted into a category say 21−25. To convert an R data frame column into a categorical variable, we can use cut function.Example1y1

Read More

Write a Golang program to find the frequency of each element in an array

Kiran P
Kiran P
Updated on 11-Mar-2026 771 Views

ExamplesInput Array = [1, 3, 4, 3, 2, 3, 4, 0, 2]Element13420Frequency13221Approach to solve this problemStep 1: Define a method that accepts an array.Step 2: Define a map, where key would be the array’s elements and the starting value is 0.Step 3: Start iterating the input array. If an element is present in the map, then increment the count.Step 4: If the element is not present in the map, then store in map and make its value 1.Programpackage main import (    "fmt" ) func findFrequencyOfArray(arr []int){    frequency := make(map[int]int)    for _, item := range arr{       ...

Read More

How to find the counts of categories in categorical columns in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 6K+ Views

If we have two categorical columns in an R data frame then we can find the frequency/count of each category with respect to each category in the other column. This will help us to compare the frequencies for all categories. To find the counts of categories, we can use table function as shown in the below examples.Example1y1

Read More

Prime Factorization using Sieve O(log n) for multiple queries in C++

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

In this problem, we need to create a program to calculate Prime Factorization using Sieve O(log n) for multiple queries. As the general method takes O(sqrt(n) ) time which will increase the time required to a huge extent from multiple queries.Let’s recap first, Prime factorization of a number includes ONLY the prime factors, not any products of those prime factors.Sieve of Eratosthenes is an algorithm to generate all prime numbers within the given range.Solution ApproachThe solution to the problem is found by finding the smallest factor that divides the number, saving it as a factor and updating the number by dividing ...

Read More

Find maximum level sum in Binary Tree in C++

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

In this problem, we are given  a binary Tree with positive and negative values. Our task is to Find maximum level sum in Binary Tree. Problem Description: We have a binary tree, we will find the sum of all levels in the binary tree and then return the maximum of them.Let’s take an example to understand the problem, Input: Output: 5Explanation: Sum of elements at level 1: 3Sum of elements at level 2: -3 + 4 = 1Sum of elements at level 3: 5 - 1 + 6 - 5 = 5Solution ApproachTo solve the problem, we need to traverse the tree using the level ...

Read More

How to find the frequency of values greater than or equal to a certain value in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

In Data Analysis, we often need to look for less than, less than equal to, greater than, or greater than equal to values to compare them with some threshold. Sometimes we also require the frequency of these values. Therefore, we can use sum function for this purpose. For example, if a vector x has 10 integer values then to check how many of them are greater than or equal to 10, we can use the command sum(x>=10).Example1x1=5)Output[1] 83Example2x2=5)Output[1] 8Example3x3=0.25)Output[1] 38Example4x4=10)Output[1] 49Example5x5=4)Output[1] 21

Read More

Find Maximum number possible by doing at-most K swaps in C++

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

In this problem, we are given two integer values n and k. Our task is to find the Maximum number possible by doing at-most K swaps. Problem description: Here, we need to calculate the number which is maximum and created after swapping at-most k digits of the number.Let’s take an example to understand the problem,  Input: n = 538 k = 1Output: 835Explanation: We will swap 8 and 5.Solution ApproachTo solve the problem, we need to swap digits of the number k times and check if the number from is maximum.  We need to find the maximum digit of the number and then swap the ...

Read More
Showing 11821–11830 of 25,466 articles
Advertisements