Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 31 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 288 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 156 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 292 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 273 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 195 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

Program to find number of optimal steps needed to reach destination by baby and giant steps in Python

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

Suppose we have a list of queries Q, where each query Q[i] contains a triplet [a_i, b_i, d_i]. Consider we are at position (0, 0) initially, then in one step we can move from some position (x1, y1) to (x2, y2) where Euclidean distance between these two points is at least a and at most b. Now for each query we have to find minimum number of steps needed to reach (d_i, 0) from (0, 0). For example, if the input is Q = [(2, 3, 1), (1, 2, 0), (3, 4, 11)], then the output will be [2, ...

Read More

Program to find removed term from arithmetic sequence in Python

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

Suppose we have an array called nums holding n-1 arithmetic sequence terms. One element except the first or last element was removed from the original sequence. We have to find the removed number. So, if the input is like nums = [5, 7, 11, 13], then the output will be 9 because the items follow an arithmetic sequence with common difference 2, and the missing term at index 2 should be 9. Algorithm To solve this, we will follow these steps ? If size of nums is 2, return the average ...

Read More

Program to find list that shows closest distance of character c from that index in Python

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

Given a string s and a character c that exists in the string, we need to find the closest distance from each character position to any occurrence of character c. The result is a list where each element represents the minimum distance from that index to the nearest occurrence of c. For example, if s = "ppqppq" and c = "q", the output will be [2, 1, 0, 1, 1, 0] because: Index 0 ('p'): closest 'q' is at index 2, distance = 2 Index 1 ('p'): closest 'q' is at index 2, distance = 1 Index ...

Read More

Program to check two spheres can ever meet by accelerating or not in a 3D space in Python

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

Suppose there are two spheres with radius values r1 and r2. They are at coordinates (x1, y1, z1) and (x2, y2, z2). Their acceleration values are given as (ax1, ay1, az1) and (ax2, ay2, az2). We need to check whether these two spheres will ever meet in 3D space if they move with given accelerations. So, if the input is like r1 = 1, r2 = 2, pos1 = (0, 0, 0), acc1 = (100, 0, 0), pos2 = (4, 0, 0), acc2 = (0, 0, 0), then the output will be True, because the second sphere has no ...

Read More
Showing 301–310 of 3,768 articles
« Prev 1 29 30 31 32 33 377 Next »
Advertisements