Arnab Chakraborty has Published 4452 Articles

Python program to check a number n is weird or not

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:25:28

1K+ Views

Suppose we have a number n. We shall have to check whether n is weird or not. Here a number is weird when − 1. The number is odd 2. The number is not in range 2 to 5 3. The number is even and in range 6 to 20So, ... Read More

Program to minimize hamming distance after swap operations in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:21:07

214 Views

Suppose we have two integer arrays, src and tgt, both are of same length. We also have an array allowedSwaps where allowedSwaps[i] contains a pair (ai, bi) indicates that we can swap the elements at index ai with element index bi of the array src. (We can swap elements at ... Read More

Program to swap nodes in a linked list in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:14:20

860 Views

Suppose we have a list L and another value k. We have to swap kth node from start and kth node from end and return the final list at end.So, if the input is like L = [1, 5, 6, 7, 1, 6, 3, 9, 12] k = 3, then ... Read More

Program to find out if k monitoring stations are enough to monitor particular points in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:08:28

56 Views

Suppose there is a sensor module that can monitor its nearby environment up to a radius of r. There are some things in the lattice point of the module's monitoring circle that needs to be monitored. So, k number of low-powered modules are placed so that they can monitor only ... Read More

Program to construct the lexicographically largest valid sequence in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:07:41

211 Views

Suppose we have a number n, we have to find a sequence that satisfies all of the following rules −1 occurs once in the sequence.Each number in between 2 and n occurs twice in the sequence.For every i in range 2 to n, the distance between the two occurrences of ... Read More

Program to find maximum weighted sum for rotated array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:05:51

142 Views

Suppose we have an array of few elements. We shall have to find the maximum weighted sum if the array elements are rotated. The weighted sum of an array nums can be calculated like below −$$\mathrm{𝑆=\sum_{\substack{𝑖=1}}^{n}𝑖∗𝑛𝑢𝑚𝑠[𝑖]}$$So, if the input is like L = [5, 3, 4], then the output will ... Read More

Program to count average of all special values for all permutations of a list of items in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 13:03:17

86 Views

Suppose we have a list of elements we can calculate the value of S by the following algorithm.while size of L > 1 is non-zero, do    a := L[0]    b := L[1]    remove L[1]    L[0] := a + b + a*b return L[0] mod (10^9 + ... Read More

Program to find out the length between two cities in shortcuts in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 12:59:26

374 Views

Suppose there are n number of cities and the cities are connected with two types of roads; highways and shortcuts. Now, there is a map and only the highways are present on the map and all the shortcuts are absent. The transport division of the cities wants to launch a ... Read More

Program to count maximum score from removing substrings in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 12:58:19

131 Views

Suppose we have a string s and two values x and y. We can perform given two types of operations any number of times.Search substring "ab", if present, then we can gain x points by removing it.Search substring "ba", if present, then we can gain y points by removing it.We ... Read More

Program to find out the sum of minimum cost within a graph among all vertices in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2021 12:55:40

358 Views

Suppose there is a weighted graph with n vertices and m edges. The edges have the weights in powers of 2. Any vertex can be reached from any vertex in the graph, and the cost of travel will be the addition of all the edge weights in the graph. We ... Read More

Advertisements