Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 305 of 377

Program to find removed term from arithmetic sequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 279 Views

Suppose we have an array called nums holding n-1 arithmetic sequence terms. One element except the first or last element of nums was removed before. We have to find the removed number.So, if the input is like nums = [5, 7, 11, 13], then the output will be 9 because, the items are following the formula 2i+5, so for i = 2 it will be 2*2 + 5 = 9 which is missing.To solve this, we will follow these steps −if size of nums is same as 2, thenreturn floor of (sum of all elements present in nums)/2if nums[0] is ...

Read More

Program to find list that shows closest distance of character c from that index in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 476 Views

Suppose we have a string s and another character c, c must be present in s, we have to find a list whose length is same as length of s where for each index i its value is set the closest distance of s[i] to c.So, if the input is like s = "ppqppq" c = "q", then the output will be [2, 1, 0, 1, 1, 0]To solve this, we will follow these steps −j := size of sd := [j - 1] * jx := index of c in sfor i in range 0 to j - 1, ...

Read More

Program to check two spheres can ever meet by accelerating or not in a 3D space in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 143 Views

Suppose there are two spheres whose radius values are r1 and r2. They are at (x1, y1, z1) and (x2, y2, z2) coordinates. And their acceleration values are given like (ax1, ay1, az1) and (ax2, ay2, az2). We have to check whether these two spheres will ever meet on 3D space if they move with given acceleration or not.So, if the input is like r1 = 1 r2 = 2 pos1 = (0, 0, 0) acc1 = (100, 0, 0) pos2 = (4, 0, 0) acc2 = (0, 0, 0), then the output will be True, because second sphere has ...

Read More

Program to find sum of digits that are inside one alphanumeric string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 653 Views

Suppose we have an alphanumeric string s with digits from "0" to "9" and lowercase English letters. We have to find the sum of the numbers that are present in s. If digits are consecutive then consider them into a single number.So, if the input is like s = "hello25world63power86", then the output will be 174 because 25+63+86 = 174To solve this, we will follow these steps −ret := 0, curr := 0for each ch in s, doif ch is a digit, thencurr := 10 * curr + (ch as an integer)otherwise, ret := ret + currcurr := 0return ret ...

Read More

Program to check we can rearrange array to make difference between each pair of elements same in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 239 Views

Suppose we have a list called nums, we have to check whether we can rearrange the order of nums in such a way that the difference between every pair of consecutive two numbers is same.So, if the input is like nums = [8, 2, 6, 4], then the output will be True, because if we rearrange nums like [2, 4, 6, 8], then the difference between every two pair of consecutive numbers is 2.To solve this, we will follow these steps −N := size of numsif N

Read More

Program to find the maximum sum of the subarray modulo by m in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 321 Views

Program to find the maximum sum of the subarray modulo by m in PythonSuppose we have an array nums with n elements. We have another integer m. We have to find the maximum value of sum of any of its subarrays modulo m.So, if the input is like nums = [1, 5, 7, 3] m = 5, then the output will be 3 because[1] mod 5 = 1[5] mod 5 = 0[7] mod 5 = 2[3] mod 5 = 3[1, 5] mod 5 = 1[5, 7] mod 5 = 2[7, 3] mod 5 = 0[1, 5, 7] mod 5 = ...

Read More

Program to add one to a number that is shown as a digit list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 760 Views

Suppose we have an array called nums, containing decimal digits of a number. For example, [2, 5, 6] is for 256. We have to add 1 with this number and return the list in same format as before.So, if the input is like nums = [2, 6, 9], then the output will be [2, 7, 0].To solve this, we will follow these steps −i := size of nums - 1while i >= 0, doif nums[i] + 1 = 0:       if nums[i] + 1

Read More

Program to count number of 5-star reviews required to reach threshold percentage in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 864 Views

Suppose we have a list called reviews and a threshold value t. Each item in reviews[i] has [x, y] means product i had x number of 5-star rating and y number of reviews. We have to find the minimum number of additional 5-star reviews we need so that the percentage of 5-star reviews for those items list is at least t percent.So, if the input is like reviews = [[3, 4], [1, 2], [4, 6]] threshold = 78, then the output will be 7, as in total there were 8 5-star reviews and 12 reviews. To reach 78% 5-star reviews, ...

Read More

Program to count number of similar substrings for each query in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 417 Views

Suppose we have two strings s and a set of query Q. Where Q[i] contains pair (l, r), for each substring of s from l to r, we have to find number of substrings s from x to y where they are similar. Two strings s and t are similar if they follow these rules −They are of same lengthFor each pair of indices (i, j), if s[i] is same as s[j], then it must satisfy t[i] = t[j], and similarly if s[i] is not same as s[j], then t[i] and t[j] must be different.So, if the input is like ...

Read More

Program to create a lexically minimal string from two strings in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 09-Oct-2021 203 Views

Suppose, we have two strings. We want to make a lexically minimum string from those strings. To make the string we compare the first letter of the two strings and extract the lexically smaller letter from one of the strings. In the case of a tie i.e, the letters are the same; we extract the letter from the first string. We repeat this process until both the strings are empty. The minimal string constructed has to be returned.So, if the input is like input_1 = 'TUTORIALS', input_2 = 'POINT', then the output will be POINTTUTORIALSIf we compare the two strings, ...

Read More
Showing 3041–3050 of 3,768 articles
« Prev 1 303 304 305 306 307 377 Next »
Advertisements