Server Side Programming Articles

Page 517 of 2109

Program to group a set of points into k different groups in Python

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

Suppose we have a list of points and a number k. The points are in the form (x, y) representing Cartesian coordinates. We can group any two points p1 and p2 if the Euclidean distance between them is ≤ k. We have to find the total number of disjoint groups. So, if the input is like points = [[2, 2], [3, 3], [4, 4], [11, 11], [12, 12]], k = 2, then the output will be 2, as it can make two groups: ([2, 2], [3, 3], [4, 4]) and ([11, 11], [12, 12]). Algorithm To solve ...

Read More

How to find the statistical summary of an R data frame with all the descriptive statistics?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 25-Mar-2026 522 Views

When analyzing data in R, the default summary() function provides basic statistics like minimum, quartiles, mean, and maximum. However, for comprehensive statistical analysis, we need additional descriptive measures such as variance, standard deviation, skewness, and kurtosis. The basicStats() function from the fBasics package provides all these descriptive statistics in one output. Loading Required Package First, install and load the fBasics package ? library(fBasics) Example 1: mtcars Dataset Let's examine the built-in mtcars dataset ? data(mtcars) head(mtcars, 10) ...

Read More

Program to count number of strings we can make using grammar rules in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 306 Views

Suppose we have a number n, we have to find the number of strings of length n can be generated using the following grammar rules ? Each character is a lower case vowel [a, e, i, o, u] "a" may only be followed by one "e" "e" may only be followed by any of "a" and "i" "i" may not be followed by another "i" "o" may only be followed by any of "i" and "u" "u" may only be followed by one "a" If the result is very large, mod the result by 10^9 + ...

Read More

Program to implement the fractional knapsack problem in Python

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

The fractional knapsack problem is a greedy optimization algorithm where we can take fractions of items to maximize value within a weight capacity. Unlike the 0/1 knapsack, we can break items and take partial amounts. The strategy is to sort items by their value-to-weight ratio in descending order, then greedily select items starting with the highest ratio. Algorithm Steps To solve this problem, we follow these steps − Calculate value-to-weight ratio for each item Sort items by ratio in descending order For each ...

Read More

Program to find correct order of visited cities in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 258 Views

Given a list of airline tickets represented by pairs of departure and arrival airports, we need to reconstruct the correct travel itinerary. All tickets belong to a traveler who starts from KLK airport, so the itinerary must begin there. For example, if the input is [["MUC", "LHR"], ["KLK", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]], the output should be ["KLK", "MUC", "LHR", "SFO", "SJC"]. Algorithm We'll use a depth-first search (DFS) approach with the following steps − Build a graph where each airport maps to its destinations Use DFS ...

Read More

Program to find first positive missing integer in range in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 400 Views

Suppose we have a list of sorted distinct integers of size n, we have to find the first positive number in range [1 to n+1] that is not present in the array. So, if the input is like nums = [0, 5, 1], then the output will be 2, as 2 is the first missing number in range 1 to 4. Algorithm To solve this, we will follow these steps − target := 1 for each i in arr, do if i is same as target, then target := target + 1 ...

Read More

Program to find lowest possible integer that is missing in the array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 262 Views

Finding the first missing positive integer is a common programming problem. Given an array that may contain duplicates and negative numbers, we need to find the lowest positive number that is not present in the array. So, if the input is like nums = [0, 3, 1], then the output will be 2 because 1 and 3 are present, but 2 is missing. Algorithm Approach To solve this problem, we follow these steps: Create a set containing only positive numbers from the input array If the set is empty (no positive numbers), return 1 Iterate ...

Read More

Program to find minimum amount needed to be paid all good performers in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 430 Views

Suppose we have a list of performance ratings for coders. The manager wants to pay each coder at least Rs 1000, but if two coders are adjacent, the better performing coder must receive at least Rs 1000 more than the worse performing one. We need to find the minimum total amount required following these constraints. So, if the input is like ratings = [1, 2, 5, 1], then the output will be 7000, as the minimum payment for each coder is [1000, 2000, 3000, 1000]. Algorithm To solve this problem, we use a two-pass approach ? ...

Read More

Program to check a number can be written as a sum of distinct factorial numbers or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 307 Views

Suppose we have a positive number n, we have to check whether n can be written as the sum of unique positive factorial numbers or not. So, if the input is like n = 144, then the output will be True, as 4! + 5! = 24 + 120 = 144 Algorithm To solve this, we will follow these steps − Generate all factorial numbers up to n Use a greedy approach: start from the largest factorial and subtract it if possible Continue until we either reach 0 (success) or can't subtract any more factorials ...

Read More

Program to check we can reach leftmost or rightmost position or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 426 Views

Suppose we have a string containing letters of three types: R, B, and dot(.). Here R stands for our current position, B stands for a blocked position, and dot(.) stands for an empty position. In one step, we can move to any adjacent position to our current position, as long as it is valid (empty). We have to check whether we can reach either the leftmost position or the rightmost position. So, if the input is like s = "...........R.....BBBB.....", then the output will be True, as R can reach the leftmost position because there is no block between ...

Read More
Showing 5161–5170 of 21,090 articles
« Prev 1 515 516 517 518 519 2109 Next »
Advertisements