Found 26504 Articles for Server Side Programming

Program to find out is a point is reachable from the current position through given points in Python

Arnab Chakraborty
Updated on 16-Oct-2021 11:15:48

352 Views

Suppose in a 2D space a pointer is located at a point p that has coordinates (px, py). Now the pointer has to move to another point q having coordinates (qx, qy). The pointer just cannot move freely, it can travel to q if there are some points located in between. We are given an array of points "paths" that contain various coordinate points. The pointer can move to a point if it is located at (x+1, y) or (x, y+1) or (x-1, y) or (x, y-1) from the current position of the pointer. The given points in the array ... Read More

Program to find out the maximum points collectable in a game in Python

Arnab Chakraborty
Updated on 16-Oct-2021 11:11:56

265 Views

Suppose we are playing a game of cards. We are given several cards arranged linearly with a number on each of them. The numbers on the cards are randomly distributed; and at the beginning and the end of the cards, two cards are inserted with the number 1 on them. Now, in the game, we have to collect the maximum points by picking up the given cards. The cards are represented in an array 'cards' where the elements in the array represent the number of cards[i]. When we pick up card i, we collect points cards[i - 1] * cards[i] ... Read More

Program to find out if we win in a game in Python

Arnab Chakraborty
Updated on 16-Oct-2021 11:09:01

605 Views

Suppose we are playing a two-player game where there are n number of marbles and in each round, a player has to take a positive square number of marbles. If a player can't take that square number of marbles, he/she loses. So, given a number n, we have to find out if we can win the game or not. We always make the first turn and select an optimal number of marbles.So, if the input is like 14, then the output will be True. Because at the first turn, we take 9 marbles. That leaves 5 marbles from which the ... Read More

Program to find out the minimum number of intercountry travels in a road trip in Python

Arnab Chakraborty
Updated on 16-Oct-2021 11:06:24

328 Views

Suppose we have to plan a road trip that involves visiting various cities from different countries. We have a list of roads 'R', where each element is described as (x, y, cost). x signifies the starting city of the road, y signifies the destination city of the road, and cost signifies the cost of traveling by that road. We also have a list 'C' where each element is a country and an element contains the cities of that country. Now, we also have a starting city 's' and a destination city 'e', and we want to travel to the destination ... Read More

Program to find out the conversion rate of two currencies in Python

Arnab Chakraborty
Updated on 16-Oct-2021 11:01:39

259 Views

Suppose we are given three arrays; curr_a, curr_b, and conv_rate. The first array contains some currency names and so does the second one, and the array conv_rate contains the rates of conversion within an item curr_a[i] to cuur_b[i]. The item of conv_rate[i] is the conversion rate between curr_a[i] and curr_b[i]. Now, we are given two currencies src and dest. We have to find out the rate of conversion from src to dest. We return the value as output, and if it is not possible we return 0.So, if the input is like src = "INR", dest = "JPY", curr_a = ... Read More

Program to group the 1s with minimum number of swaps in a given string in Python

Arnab Chakraborty
Updated on 16-Oct-2021 10:57:45

322 Views

Suppose we are given a binary string input_str that contains 0s and 1s. Our task is to group the 0s and 1 by swapping the 1s in the given string. We have to perform a minimum number of swap operations, and we have to return that value. One thing to be kept in mind, we can swap the adjacent values only.So, if the input is like input_str = 10110101, then the output will be 4The swap will be like following −10110101->01110101->01111001->01111010->01111100The total number of swaps: 4.To solve this, we will follow these steps −one := a new list containing the ... Read More

Program to find dot product of run length encoded vectors in Python

Arnab Chakraborty
Updated on 16-Oct-2021 10:48:22

421 Views

Suppose we have two lists nums1 and nums2. Each of these two list are representing a vector in run-length encoded form. So as an example, a vector [1, 1, 1, 2, 2, 2, 2] is represented as [3, 1, 4, 2]. (because there are 3 ones and 4 twos). So we have to find the dot product of these two vectors. (The dot product is the sum of element wise multiplication of items present in two vectors).So, if the input is like nums1 = [2, 7, 5, 3] nums2 = [3, 5, 4, 2], then the output will be 109 ... Read More

Program to check there is any common reachable node in a graph or not in Python

Arnab Chakraborty
Updated on 16-Oct-2021 10:44:54

348 Views

Suppose we have an edge list of a directed graph, there are n nodes and node names are 0 to n- 1. We also have two integer values a and b. We have to check whether there is any node c such that we can go from c to a and also c to b.So, if the input is likeAnd a = 2, b = 3, then the output will be True, because here c = 0, so we have route from 0 to 2 and also 0 to 3.To solve this, we will follow these steps −Define a function ... Read More

Program to find maximum coins we can get from disappearing coins matrix in Python

Arnab Chakraborty
Updated on 16-Oct-2021 10:41:14

206 Views

Suppose we have a 2D matrix where each cell matrix[r, c] represents the number of coins present in that cell. When we pick up coins from matrix[r, c], all the coins on row (r - 1) and (r + 1) will disappear, as well as the coins at the two cells matrix[r, c + 1] and matrix[r, c - 1]. We have to find the maximum number of coins we can collect.So, if the input is like28761010425923then the output will be 26 because we can pick cells with the coins 8, 6, and 9 and 3, so total is 26.To ... Read More

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

Arnab Chakraborty
Updated on 16-Oct-2021 10:36:57

162 Views

Suppose we have two lists, they are cores and tasks. The cores[i] indicates 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 in only one server. And a server may have multiple tasks to run. We have to check whether it's possible to run all the tasks with the given cores or not.So, if the input is like cores = [10, 7] tasks = [7, 3, 2, 2, 1], then the output will be True, because we can put tasks[0] and tasks[1] into first ... Read More

Advertisements