Find Conversion Rate of Two Currencies in Python

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

269 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

Group 1s with Minimum Swaps in a Given String in Python

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

335 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

Find Dot Product of Run-Length Encoded Vectors in Python

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

439 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

Check for Common Reachable Node in a Graph using Python

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

367 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

Find Maximum Coins from Disappearing Coins Matrix in Python

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

224 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

Check Task Execution with Given Server Cores in Python

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

168 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

Check Forward Path in Circular Cyclic List in Python

Arnab Chakraborty
Updated on 16-Oct-2021 10:34:29

302 Views

Suppose we have a circular list called nums. So the first and the last elements are neighbors. So starting from any index say i, we can move nums[i] number of steps forward if nums[i] is a positive value, otherwise backwards if it's a negative value. We have to check whether there is a cycle whose length is greater than one such that the path only goes forwards or only goes backwards.So, if the input is like nums = [-1, 2, -1, 1, 2], then the output will be True, because there is a forward path [1 -> 3 -> 4 ... Read More

Count Number of Characters in Each Bracket Depth in Python

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

552 Views

Suppose we have a string s which consists of only three characters "X", "(", and ")". The string has balanced brackets and in between some "X"s are there along with possibly nested brackets may also there recursively. We have to find the number of "X"s at each depth of brackets in s, starting from the shallowest depth to the deepest depth.So, if the input is like s = "(XXX(X(XX))XX)", then the output will be [5, 1, 2]To solve this, we will follow these steps −depth := -1out := a new listfor each c in s, doif c is same as ... Read More

Get Final String After Shifting Characters in Python

Arnab Chakraborty
Updated on 16-Oct-2021 10:21:11

680 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 be 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" so, after shifting first character 2 places, it will be 't' to ... Read More

Count Horizontal Brick Patterns from a Set of Bricks in Python

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

279 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 −To solve this, we will follow these steps ... Read More

Advertisements