Arnab Chakraborty has Published 4452 Articles

Program to find maximum XOR for each query in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 13:04:49

197 Views

Suppose we have an array which is presorted called nums of size n and also have one value b. We want to perform the following query n times −Search for a non-negative value k < 2^m such that XOR of all elements in nums and k is maximized. So k ... Read More

Program to find length of longest fibonacci subsequence in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:59:42

132 Views

Suppose we have one sequence like X_1, X_2, ..., X_n is fibonacci-like if −n >= 3X_i + X_i+1 = X_i+2 for all i + 2 last, thencome out from loopreturn bestExampleLet us see the following implementation to get better understanding −from collections import Counter def solve(A):    sA = ... Read More

Program to find total similarities of a string and its substrings in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:55:37

246 Views

Suppose we have a string s. We have to find the sum of similarities of string s with each of it's suffixes. Here the similarity between two strings are the length of the longest prefix common to both strings.So, if the input is like s = "pqpqpp", then the output ... Read More

Program to count number of nice subarrays in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:55:07

645 Views

Suppose we have an array called nums and another value k. We have to find the number of nice sub-arrays. A subarray is said to be nice subarray if there are k odd numbers on it.So, if the input is like nums = [1, 1, 2, 1, 1], k = ... Read More

Program to find minimum absolute sum difference in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:51:40

332 Views

Suppose we have two positive valued arrays nums1 and nums2, of same size. The absolute sum difference of these two arrays is the sum of |nums1[i] - nums2[i]| for each 0 [2, 2, 6], orReplace the element at index 1 with the element at index 2: [2, 8, 6] ... Read More

Program to get maximum length merge of two given strings in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:48:18

122 Views

Suppose we have two strings s and t. We have to make a string called merge in the following way: while either s or t are non-empty, select one of the following options −If s is non-empty, then append the first character in s to merge and delete it from ... Read More

Program to count nice pairs in an array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:44:31

282 Views

Suppose we have an array called nums with non-negative values. We have to find number nice pairs of indices present in the array, if the answer is too large, then return answer mod 10^9+7. Here a pair of indices (i, j) is said to be nice when they satisfy all ... Read More

Program to convert hour minutes’ time to text format in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:42:35

435 Views

Suppose we have two inputs hour and minutes. We have to show the time in text format. This is like −8:00 : 8'o clock8:01 : one minute past eight8:10 : ten minutes past eight8:15 : quarter past eight8:30 : half past eight8:40 : twenty minutes to nine8:45 : quarter to ... Read More

Program to check whether two sentences are similar or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:39:15

862 Views

Suppose we have two sentences s and t. We have to check whether they are similar or not. Here sentence has only English letters. Two sentences are said to be similar when it is possible to add an arbitrary sentence (possibly empty) inside one of these given sentences such that ... Read More

Program to find total sum of all substrings of a number given as string in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2021 12:36:02

354 Views

Suppose we have a number in string format, and we have to find the sum of all substrings of s. The answer may be very large, so return result modulo 10^9+7.So, if the input is like s = "268", then the output will be 378 as the substrings are "2", ... Read More

Advertisements