Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 256 of 2109
Program to check there is any common reachable node in a graph or not in Python
Suppose we have an edge list of a directed graph with n nodes numbered from 0 to n-1. Given two integer values a and b, we need to check whether there exists a node c such that we can reach both a and b from c. 0 1 2 3 4 ...
Read MoreProgram to find maximum coins we can get from disappearing coins matrix in Python
When we have a 2D matrix where each cell represents coins, we need to find the maximum coins we can collect with specific constraints. When we pick coins from matrix[r, c], all coins in adjacent rows (r-1 and r+1) and adjacent columns (c-1 and c+1) disappear. This problem can be solved using dynamic programming by treating it as two separate "House Robber" problems − first for each row, then for the resulting row sums. Problem Understanding Given the input matrix ? 2876 101042 5923 We can pick cells with coins 8, 6, 9, ...
Read MoreProgram to check all tasks can be executed using given server cores or not in Python
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 MoreProgram to check there is any forward path in circular cyclic list or not in Python
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 MoreProgram to count number of characters in each bracket depth in Python
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 MoreProgram to get final string after shifting characters with given number of positions in Python
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 MoreProgram to count number of horizontal brick pattern can be made from set of bricks in Python
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 MoreProgram to find number of pairs where elements square is within the given range in Python
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 MoreProgram to check whether robot is moving inside a bounded box or not in Python
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 MoreProgram to find bitwise AND of range of numbers in given range in Python
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