Programming Articles

Page 260 of 2547

Program to check all tasks can be executed using given server cores or not in Python

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

Suppose we have two lists: cores and tasks. The cores[i] indicates the number of cores available in the ith server, and tasks[i] indicates the number of cores needed to execute that task. Each task must be run on only one server, and a server may have multiple tasks to run. We need to check whether it's possible to run all tasks with the given server cores. For example, if cores = [10, 7] and tasks = [7, 3, 2, 2, 1], the output will be True because we can assign tasks[0] (7 cores) and tasks[1] (3 cores) to the ...

Read More

Program to check there is any forward path in circular cyclic list or not in Python

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

Suppose we have a circular list called nums where the first and last elements are neighbors. Starting from any index i, we can move nums[i] number of steps forward if nums[i] is positive, or backwards if it's negative. We need to check whether there is a cycle with length greater than one that moves only in one direction (either all forward or all backward). For example, if the input is nums = [-1, 2, -1, 1, 2], the output will be True because there is a forward path: [1 → 3 → 4 → 1]. Algorithm Steps ...

Read More

Program to count number of characters in each bracket depth in Python

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

Sometimes we need to count characters at different bracket depths in a string. This problem involves parsing a string with balanced brackets "(", ")" and characters "X", then counting how many "X" characters appear at each depth level. So, if the input is like s = "(XXX(X(XX))XX)", then the output will be [5, 1, 2] Bracket Depth Visualization ( X X X ( X ( X X ) ...

Read More

Program to get final string after shifting characters with given number of positions in Python

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

Suppose we have a lowercase string s and another list of integers called shifts whose length is same as the length of s. Here each element in shifts[i] indicates it to shift the first i + 1 letters of s by shifts[i] positions. If shifting crosses 'z' it will wrap up to 'a'. We have to find the resulting string after applying shifts to s. So, if the input is like s = "tomato" shifts = [2, 5, 2, 3, 7, 4], then the output will be "qjcoes". After shifting first character 2 places, it will be 't' to ...

Read More

Program to count number of horizontal brick pattern can be made from set of bricks in Python

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

Suppose we have a list of numbers called bricks and two other values width and height. Each element in bricks[i] represents a brick whose length is bricks[i] units and width is 1 unit. We have to find the number of ways to lay the bricks such that we get full layout of bricks with the given width and height. We can reuse the bricks but can only be laid horizontally. So, if the input is like bricks = [2, 1] width = 3 height = 2, then the output will be 9 because − ...

Read More

Program to find number of pairs where elements square is within the given range in Python

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

Given two lists of numbers nums1 and nums2, and two boundary values lower and upper, we need to find the number of pairs (i, j) such that lower ≤ nums1[i]² + nums2[j]² ≤ upper. Problem Understanding For example, if nums1 = [5, 3, 2], nums2 = [8, 12, 6], lower = 10, and upper = 50, we need to check all possible combinations: Pair (1, 2): 3² + 6² = 9 + 36 = 45 (10 ≤ 45 ≤ 50) ✓ Pair (2, 2): 2² + 6² = 4 + 36 = 40 (10 ≤ 40 ...

Read More

Program to check whether robot is moving inside a bounded box or not in Python

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

Suppose we have a string s that represents the moves of a robot. The robot starts at position (0, 0) and faces north. We need to determine if the robot stays within a bounded area after repeatedly executing the move sequence. Move Commands The move string s contains these characters ? "F" − move forward one unit in current direction "L" − rotate 90 degrees left "R" − rotate 90 degrees right Algorithm Logic If a robot returns to its starting position (0, 0) after executing the move sequence up to 4 times, ...

Read More

Program to find bitwise AND of range of numbers in given range in Python

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

Suppose we have two values start and end, we have to find the bitwise AND of all numbers in the range [start, end] (both inclusive). So, if the input is like start = 8 end = 12, then the output will be 8. Here's why: 8 is 1000 in binary and 12 is 1100 in binary, so 1000 AND 1001 AND 1010 AND 1011 AND 1100 is 1000 which is 8. Algorithm To solve this, we will follow these steps − n := end - start + 1 ...

Read More

Program to find number of sublists with sum k in a binary list in Python

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

Given a binary list containing only 0s and 1s, we need to find the number of contiguous sublists whose sum equals a given value k. This problem can be efficiently solved using the prefix sum technique with a hash map to track cumulative sums. Problem Understanding For a binary list nums = [1, 0, 0, 1, 1, 1, 0, 1] and k = 3, we need to find all contiguous sublists that sum to 3. The valid sublists are: [1, 0, 0, 1, 1] starting at index 0 [0, 0, 1, 1, 1] starting at index ...

Read More

Program to find list showing total distance required to move all balls to current position in Python

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

Suppose we have a binary list called nums containing only 0s and 1s where a 0 indicates empty cell and 1 indicates the cell is filled by a ball. We have to find a new list of say L, whose size is also same like nums size, where L[i] is set to the total distance required to move all the balls to L[i]. Here the distance to move a ball from index j to index i is |j - i|. So, if the input is like nums = [1, 1, 0, 1], then the output will be [4, 3, ...

Read More
Showing 2591–2600 of 25,466 articles
« Prev 1 258 259 260 261 262 2547 Next »
Advertisements