Find Character in First String Present at Minimum Index in Second String in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:31:23

347 Views

Suppose we have a string str and another string patt, we have to find determine the character in patt that is present at the minimum index of str. If no character patt1 is present in str1 then return -1.So, if the input is like str = "helloworld" and patt = "wor", then the output will be 'o' as 'o' is present at minimum index in strTo solve this, we will follow these steps −for i in range 0 to size of patt, dofor j in range 0 to size of Str, doif patt[i] is same as Str[j] and j < ... Read More

Find Sum of All Elements in a Matrix Except Given Cell's Row and Column in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:30:03

913 Views

Suppose we have a 2D matrix and a set of cell indexes. Cell indices are represented as (i, j) where i is row and j is column, now, for every given cell index (i, j), we have to find the sums of all matrix elements excluding the elements present in ith row and/or jth column.So, if the input is like223457643cell indices = [(0, 0), (1, 1), (0, 1)], then the output will be [19, 14, 20]To solve this, we will follow these steps −n := size of ind_arrans := a new listfor i in range 0 to n, doSum := ... Read More

Find Substrings that Contain All Vowels in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:28:19

873 Views

Suppose we have a string in lowercase alphabets, we have to find substrings that contain all the vowels at least once and there exist no consonants in that substrings.So, if the input is like "helloworldaeiouaieuonicestring", then the output will be ['aeiou', 'aeioua', 'aeiouai', 'aeiouaiu', 'eioua', 'eiouai', 'eiouaiu']To solve this, we will follow these steps −n := size of sfor i in range 0 to n, domy_map := a new mapfor j in range i to n, doif s[j] not vowel, thencome out from the loopmy_map[s[j]] := 1if size of my_map is same as 5, thendisplay s[from index i to j ... Read More

Get Path to Desktop for Current User in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:27:58

5K+ Views

The desktop path of the current user can be fetched by using Environment.SpecialFolder. The Environment.SpecialFolder gets the path to the system special folder that is identified by the specified enumeration.string desktopPath =Environment.GetFolderPath(Environment.SpecialFolder.Desktop)The System.Environment Class provides information about the current environment and platform. The System.Environment Class uses to retrieve Environment variable settings, Version of the common language runtime, contents of the call stack etc. This class cannot be inherited.Environment class is static class which Provides the system configuration, Current program execution Environment as wel some properties for string manipulation such as news line, System Namespace represents the Environment Class.Environment class is ... Read More

Find Subsequences with Maximum Bitwise AND and Bitwise OR in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:26:24

746 Views

Suppose we have an array of n elements, we have to show the maximum sum by choosing two subsequences of the array (they may or may not be different) so that the sum of bit-wise AND operation of all elements of the first subsequence and bit-wise OR operation of all the elements of the second subsequence is maximum.So, if the input is like A = {4, 6, 7, 2}, then the output will be 14 as we are getting maximum AND value by selecting 7 only and maximum OR value by selecting all (4 | 6 | 7 | 2) ... Read More

Best Data Type for Currency in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:24:37

7K+ Views

The best datatype to use for currency in C# is decimal. The decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal type can represent values ranging from 1.0 * 10^-28 to approximately 7.9 * 10^28 with 28-29 significant digits. To initialize a decimal variable, use the suffix m or M.decimal b = 2.1m;The below example shows the min and max value of decimal.Example Live Demousing System; namespace DemoApplication{    public class Program{       public static void Main(){          Console.WriteLine($"Deciaml Min Value: {decimal.MinValue}");          Console.WriteLine($"Deciaml Max Value: {decimal.MaxValue}"); ... Read More

Find Sub-Arrays with Equal Sum in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:24:34

369 Views

Suppose we have two arrays P and Q whose size are N, they are holding numbers 1 to N. We have to find sub-arrays from the given arrays so that they have equal sum. Finally return the indices of such sub-arrays. If there is no solution, then return -1.So, if the input is like P = [2, 3, 4, 5, 6], Q = [9, 3, 2, 6, 5], then the output will be Indices in first array : 0, 1, 2 and indices in second array: 0, so P[0..2] = 2 + 3 + 4 = 9 and Q[0] = ... Read More

Find Smallest Range Containing Elements from K Lists in C++

Arnab Chakraborty
Updated on 19-Aug-2020 11:22:18

85 Views

Suppose we have k different lists. The elements are sorted. We have to search the smallest range that includes at least one number from each of the k different lists. Here the range [a, b] is smaller than range [c, d] when b-a < d-c or a < c if b-a == d-c.So if the input is like [[4, 10, 15, 25, 26], [0, 9, 14, 20], [5, 18, 24, 30]], then the output will be [14, 18]To solve this, we will follow these steps −minRange := inf, maxRange := -inf, rangeSize := inf, tempMinRange := inf, tempMaxRange := -infn ... Read More

Find Shortest Distance from a Guard in a Bank in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:19:35

184 Views

Suppose we have a matrix that is filled with three letters 'O', 'G', and 'W' where 'O' is representing open space, 'G' is representing guards and 'W' is representing walls in a bank, we have to replace all of the O's in the matrix with respect of their shortest distance from one guard, we cannot go through any walls. In the output matrix guards are replaced with 0 and walls are replaced by -1.So, if the input is likeOOOOGOOOWOOWOOOGWWWOOOOOGthen the output will be33210233-111-14320-1-1-1112210To solve this, we will follow these steps −M := 5N := 5dir_row := [-1, 0, 1, 0]dir_col ... Read More

Find Same Contacts in a List of Contacts in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:16:45

259 Views

Suppose we have a list of contacts holding username, email and phone number in any order, we have to find the same contacts (When same person have many different contacts) and return the same contacts together. We have to keep in mind that −A contact can store username, email and phone fields according to any order.Two contacts are same if they have either same username or same email or same phone number.So, if the input is like Contacts = [{"Amal", "amal@gmail.com", "+915264"}, { "Bimal", "bimal321@yahoo.com", "+1234567"}, { "Amal123", "+1234567", "amal_new@gmail.com"}, { "AmalAnother", "+962547", "amal_new@gmail.com"}], then the output will be [0, ... Read More

Advertisements