Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 17 of 377

Check whether the sum of absolute difference of adjacent digits is Prime or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 256 Views

Suppose we have a number n. We have to check whether the sum of the absolute difference of adjacent digit pairs is prime or not.So, if the input is like n = 574, then the output will be True as |5-7| + |7-4| = 5, this is prime.To solve this, we will follow these steps −num_str := n as stringtotal := 0for i in range 1 to size of num_str - 1, dototal := total + |digit at place num_str[i - 1] - digit at place num_str[i]|if total is prime, thenreturn Truereturn FalseLet us see the following implementation to get ...

Read More

Program to find number of ways we can reach from top left point to bottom right point in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 446 Views

Suppose we have one N x M binary matrix. Where 0 means empty cell and 1 means blocked cell. Now starting from the top left corner, we have to find the number of ways to reach the bottom right corner. If the answer is very large, mod it by 10^9 + 7.So, if the input is like001000110then the output will be 2, as There are two ways to get to the bottom right: [Right, Down, Right, Down] and [Down, Right, Right, Down].To solve this, we will follow these steps −dp := a matrix of same size of given matrix and ...

Read More

Check if a sorted array can be divided in pairs whose sum is k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 181 Views

Suppose we have an array of numbers and have another number k, we have to check whether given array can be divided into pairs such that the sum of every pair is k or not.So, if the input is like arr = [1, 2, 3, 4, 5, 6], k = 7, then the output will be True as we can take pairs like (2, 5), (1, 6) and (3, 4).To solve this, we will follow these steps −n := size of arrif n is odd, thenreturn Falselow := 0, high := n - 1while low < high, doif arr[low] + ...

Read More

Check whether the sum of prime elements of the array is prime or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 218 Views

Suppose we have an array nums. We have to check whether the sum of all prime elements in the given array is also prime or notSo, if the input is like nums = [1, 2, 4, 5, 3, 3], then the output will be True as sum of all primes are (2+5+3+3) = 13 and 13 is also prime.To solve this, we will follow these steps −MAX := 10000sieve := a list of size MAX and fill with trueDefine a function generate_list_of_primes()sieve[0] := False, sieve[1] := Falsefor i in range 2 to MAX - 1, doif sieve[i] is true, thenfor ...

Read More

Check if a string can be converted to another string by replacing vowels and consonants in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 446 Views

Suppose we have two strings s and t. We can only change a character at any position to any vowel if it is already a vowel or to a consonant if it is already a consonant. We have to check whether s can be represented to t or vice-versa.So, if the input is like s = "udpmva", t = "itmmve", then the output will be True as we can transform u -> i, d -> t, p -> m, a -> eTo solve this, we will follow these steps −s_size := size of sif s_size is not same as size ...

Read More

Check whether the two numbers differ at one-bit position only in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 531 Views

Suppose we have two numbers x and y. We have to check whether these two numbers differ at one-bit position or not.So, if the input is like x = 25 y = 17, then the output will be True because x = 11001 in binary and y = 10001. Only one-bit position is different.To solve this, we will follow these steps −z = x XOR yif number of set bits in z is 1, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example Codedef bit_count(n):    count = 0    while n:       count ...

Read More

Program to find maximum sum of two sets where sums are equal in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 216 Views

Suppose we have a list of numbers called nums, now find two sets as their sums are same and maximum, then find sum value.So, if the input is like nums = [2, 5, 4, 6], then the output will be 6, as the sets are [2, 4] and [6].To solve this, we will follow these steps −sum := 0for each number i in nums, dosum := sum + in := size of numsDefine one 2D array dp of size (n + 1) x (2 * sum + 5) and fill with -1dp[0, sum] := 0for initialize i := 1, when ...

Read More

Program to find largest sum of 3 non-overlapping sublists of same sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 188 Views

Suppose we have a list of numbers called nums and another value k, we have to find the largest sum of three non-overlapping sublists of the given list of size k.So, if the input is like nums = [2, 2, 2, -6, 4, 4, 4, -8, 3, 3, 3] k = 3, then the output will be 27, as we can select the sublists [2, 2, 2], [4, 4, 4], and [3, 3, 3], total sum is 27.To solve this, we will follow these steps −P := [0]for each x in A, doinsert P[-1] + x at the end of ...

Read More

Check if a string can be obtained by rotating another string 2 places in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 330 Views

Suppose we have two strings s and t. We have to check whether we can get s by rotating t two place at any direction left or right.So, if the input is like s = "kolkata" t = "takolka", then the output will be True as we can rotate "takolka" to the left side two times to get "kolkata".To solve this, we will follow these steps −if size of s is not same as size of t, thenreturn Falseright_rot := blank stringleft_rot := blank stringl := size of tleft_rot := left_rot concatenate t[from index l - 2 to end] concatenate ...

Read More

Check whether triangle is valid or not if sides are given in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 972 Views

Suppose we have three sides. We have to check whether these three sides are forming a triangle or not.So, if the input is like sides = [14,20,10], then the output will be True as 20 < (10+14).To solve this, we will follow these steps −sort the list sidesif sum of first two sides

Read More
Showing 161–170 of 3,768 articles
« Prev 1 15 16 17 18 19 377 Next »
Advertisements