Server Side Programming Articles

Page 286 of 2109

Program to find index whose left and right elements sums are equal in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 764 Views

Suppose we have a list of numbers called nums, we have to find the smallest index i such that the sum of the numbers which are present at the left of i is equal to the sum of numbers present at right of i. If we cannot find any such solution, return -1. So, if the input is like nums = [8, 2, 3, 6, 5, 2, 5, 9, 1, 2], then the output will be 4, because sum of elements that are left of index 4 is [8, 2, 3, 6] = 19, and sum of elements that ...

Read More

Program to check n can be represented as sum of k primes or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 759 Views

Suppose we have two inputs n and k. We have to check whether n can be represented as a sum of k number of prime values or not. So, if the input is like n = 30 k = 3, then the output will be True because 30 can be represented like 2 + 11 + 17. Algorithm To solve this, we will follow these steps − if n < k*2, then return False if k > 2, then return True if k is same as ...

Read More

Program to find all substrings whose anagrams are present in a string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 568 Views

In this problem, we need to find all substrings in a string where there exists another substring at a different location that is an anagram of the first substring. An anagram contains the same characters but in different order. For example, if the input is s = "abcba", we need to find substrings like "a" (appears at positions 0 and 4), "ab" and "ba" (anagrams of each other), etc. Algorithm To solve this problem, we follow these steps − Generate all possible substrings of each length Group substrings by their sorted character representation (anagram signature) ...

Read More

Program to find smallest index for which array element is also same as index in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 216 Views

Suppose we have a list of elements called nums where all items are unique, and they are sorted in ascending order, we have to find the minimum i such that nums[i] = i. If we cannot find any solution, then return -1. We have to solve this problem in O(log(n)) time. So, if the input is like nums = [-4, -1, 2, 3, 8], then the output will be 2, because both nums[2] = 2 and nums[3] = 3 but 2 is smaller. Algorithm To solve this, we will follow these steps − ret := ...

Read More

Program to find first fit room from a list of rooms in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 293 Views

Suppose we have a list of numbers called rooms and another target value t. We have to find the first value in rooms whose value is at least t. If there is no such room, return -1. So, if the input is like rooms = [20, 15, 35, 55, 30] t = 30, then the output will be 35. Because 35 is the first room that can accommodate the target size of 30. Algorithm To solve this, we will follow these steps − for each ...

Read More

Program to check whether elements frequencies are even or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 160 Views

Suppose we have a list of elements called nums, we have to check whether all numbers appear even times or not. We have to solve it using constant space. So, if the input is like nums = [8, 9, 9, 8, 5, 5], then the output will be True, because all numbers have occurred twice. Algorithm To solve this, we will follow these steps ? If size of nums is odd, then return False Sort the list nums For i in range 1 ...

Read More

Program to find multiple of n with only two digits in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 298 Views

Suppose we have a number n. We have to find the least positive value x such that x is made up of only two digits 9's and 0's, and x is multiple of n. So, if the input is like n = 26, then the output will be 90090. Algorithm To solve this, we will follow these steps − m := 9 x := 1 while m is not divisible by n, do x := x + 1 m := replace all 1s with 9s in the binary form of x return ...

Read More

Program to sort given set of Cartesian points based on polar angles in Python

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

Suppose we have a set of Cartesian points in a list. We need to sort them based on their polar angles, which vary between 0 and 2π. If points have the same polar angles, we arrange them by their distance from the origin. For example, if we have points = [(1, 1), (1, -2), (-2, 2), (5, 4), (4, 5), (2, 3), (-3, 4)], the output will be [(5, 4), (1, 1), (4, 5), (2, 3), (-3, 4), (-2, 2), (1, -2)]. ...

Read More

Program to count elements whose next element also in the array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 286 Views

Given an array of numbers, we need to count how many elements x have their next consecutive number (x + 1) also present in the array. This problem involves frequency counting and checking for consecutive elements. Problem Understanding For the input nums = [4, 2, 3, 3, 7, 9], we need to find elements whose next consecutive number exists: Element 2: 2 + 1 = 3 exists in array (count: 1) Element 3: 3 + 1 = 4 exists in array (count: 2, since 3 appears twice) Element 4: 4 + 1 = 5 does not ...

Read More

Program to check all 1s are present one after another or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 206 Views

Suppose we have a list of numbers called nums that contains at least one element whose value is 1. We have to check whether all the 1s appear consecutively or not. So, if the input is like nums = [8, 2, 1, 1, 1, 3, 5], then the output will be True. Algorithm To solve this, we will follow these steps − visited := 0 for each x in nums, do ...

Read More
Showing 2851–2860 of 21,090 articles
« Prev 1 284 285 286 287 288 2109 Next »
Advertisements