Find a String with Lexicographically Greater Characters in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:46:39

220 Views

Suppose we have a number n; we have to check a lower case stringof length n+1 so that the character at any position should be lexicographically bigger than its immediate next character.So, if the input is like 15, then the output will be ponmlkjihgfedcba.To solve this, we will follow these steps −temp_str := blank stringextra := n mod 26if extra >= 1, thenfor i in range 26 -(extra + 1) to 25, dotemp_str := temp_str + str[i]count := n / 26 (integer division)for i in range 1 to count + 1, dofor j in range 0 to 25, dotemp_str := ... Read More

Find String in Lexicographic Order Between Two Strings in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:43:02

273 Views

Suppose we have two strings S and T, we have to check whether a string of the same length which is lexicographically bigger than S and smaller than T. We have to return -1 if no such string is available. We have to keep in mind that S = S1S2… Sn is termed to be lexicographically less than T = T1T2… Tn, provided there exists an i, so that S1= T1, S2= T2, … Si – 1= Ti – 1, Si < Ti.So, if the input is like S = "bbb" and T = "ddd", then the output will be ... Read More

Find Sorted Subsequence of Size 3 in Linear Time in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:38:31

197 Views

Suppose we have an array with N numbers, we have to check whether the 3 elements such that b[i]< b[j] < b[k] and i < j < k in linear (O(n)) time. If there are multiple such triplets, then print any one of them.So, if the input is like [13, 12, 11, 6, 7, 3, 31], then the output will be [6, 7, 31]To solve this, we will follow these steps −n := size of Amaximum := n-1, minimum := 0smaller := an array of size 1000, and fill with 0smaller[0] := -1for i in range 1 to n, doif ... Read More

Find Positive Number m for Maximum GCD in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:32:45

151 Views

Suppose we have a number N, we have to find a positive number M such that gcd(N^M, N&M) is as large as possible and m < n. We will also return the largest gcd thus obtained.So, if the input is like 20, then the output will be 31To solve this, we will follow these steps −if bit_count(n) is same as 0, thenfor i in range 2 to int(square root of (n)) + 1, doif n mod i is same as 0, thenreturn int(n / i)otherwise, val := 0p :=dupn := nwhile n is non-zero, doif (n AND 1) is same ... Read More

Find a Permutation Causing Worst Case of Merge Sort in C++

Arnab Chakraborty
Updated on 28-Aug-2020 08:25:54

145 Views

Suppose we have a set of elements; we have to find which permutation of these elements would result in worst case of Merge Sort? As we know asymptotically, merge sort always consumes O (n log n) time, but some cases need more comparisons and consumes more time. Here we have to find a permutation of input elements that will require higher number of comparisons when sorted implementing a typical Merge Sort algorithm.So, if the input is like [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] , then the output will be [11, ... Read More

Find a Pair with Given Sum in a Balanced BST in C++

Arnab Chakraborty
Updated on 28-Aug-2020 08:20:06

128 Views

Suppose we have a balanced binary search tree and a target sum, we have to define a method that checks whether it is a pair with sum equals to target sum, or not. In this case. We have to keep in mind that the Binary Search Tree is immutable.So, if the input is likethen the output will be (9 + 26 = 35)To solve this, we will follow these steps −Define stacks s1, s2done1 := false, done2 := falseval1 := 0, val2 := 0curr1 := root, curr2 := rootinfinite loop, do −while done1 is false, do −if curr1 is not ... Read More

Find Number for Minimum Sum with XOR in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:12:07

120 Views

Suppose we have an array A, we have to find a number X such that (A[0] XOR X) + (A[1] XOR X) + … + A[n – 1] XOR X is as minimum as possible.So, if the input is like [3, 4, 5, 6, 7], then the output will be X = 7 , Sum = 10To solve this, we will follow these steps −Define a function search_res() . This will take arr, nelement := arr[0]for i in range 0 to size of arr, doif arr[i] > element, thenelement := arr[i]p := integer of (log of element base 2) + ... Read More

Find Non-Empty Subset with Divisible Sum in C++

Arnab Chakraborty
Updated on 28-Aug-2020 08:06:17

359 Views

Suppose we have an array of n numbers; we have to find a non-empty subset such that the sum of elements of the subset is divisible by n. So, we have to output any such subset with its size and the indices of elements in the original array when it is present.So, if the input is like [3, 2, 7, 1, 9], then the output will be [2], [1 2].To solve this, we will follow these steps −Define one map my_mapadd := 0for initialize i := 0, when i < N, update (increase i by 1), do −add := (add ... Read More

Final State of the String After Modification in Python

Arnab Chakraborty
Updated on 28-Aug-2020 08:05:57

148 Views

Suppose we have a string S. The length is n. These n boxes adjacent to each other, a character R at position i represents that i-th box is being pushed towards right. similarly, L at position i represents that i-th box is being pushed towards left, a dot '.' indicates an empty space. Starting from initial configuration, at every time unit, a box being pushed to the right side is able to push next box to right, same action can be applied for the left side also. We have to find the final positions of all boxes when no more ... Read More

Selenium WebDriver: Submit vs Click

Debomita Bhattacharjee
Updated on 28-Aug-2020 06:36:08

11K+ Views

The click() and submit() functions are quite similar in terms of functionalities. However there are minor differences. Let us discuss some differences between them.The submit() function is applicable only for and makes handling of form easier. It can be used with any element inside a form. The click() is only applicable to buttons with type submit in a form.The submit() function shall wait for the page to load however the click() waits only if any explicit wait condition is provided. If a form has a submit of type button, the submit() method cannot be used. Also, if a button ... Read More

Advertisements