Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 228 of 377

String Transforms Into Another String in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 1K+ Views

Suppose we have two strings str1 and str2. And their lengths are same, we have to check whether we can transform str1 into str2 by doing zero or more conversions.In one conversion we can convert all occurrences of one character in str1 to any other lowercase English character. We have to check whether we can transform str1 into str2 or not.So, if the input is like str1 = "aabcc", str2 = "ccdee", then the output will be true, as Convert 'c' to 'e' then 'b' to 'd' then 'a' to 'c'. Here we have to keep in mind that the ...

Read More

Parallel Courses in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 284 Views

Suppose there are N courses, and these are labelled from 1 to N. We also gave a relation array, where relations[i] = [X, Y], is representing a prerequisite relationship between course X and course Y. So, this means course X has to be studied before course Y.In one semester we can study any number of courses as long as we have studied all the prerequisites for the course we are studying. We have to find the minimum number of semesters needed to study all courses. And if there is no way to study all the courses, then return -1.So, if ...

Read More

Divide Array Into Increasing Sequences in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 286 Views

Suppose we have a non-decreasing array of positive integers called nums and an integer K, we have to find out if this array can be divided into one or more number of disjoint increasing subsequences of length at least K.So, if the input is like nums = [1, 2, 2, 3, 3, 4, 4], K = 3, then the output will be true, as this array can be divided into the two subsequences like [1, 2, 3, 4] and [2, 3, 4] with lengths at least 3 each.To solve this, we will follow these steps −d := a new mapreq ...

Read More

Confusing Number II in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 927 Views

Suppose we have a digit, now if we rotate that digit by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. But when 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid.A confusing number is a number that when rotated 180 degrees becomes a new number. So, if we have a positive integer N, we have to find the number of confusing numbers between 1 and N inclusive.So, if the input is like 20, then the output will be 6To solve ...

Read More

Digit Count in Range

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 1K+ Views

Suppose we have an integer d between 0 and 9, we also have two positive integers low and high as lower and upper bounds, respectively. We have to find the number of times that d occurs as a digit in all integers between low and high, including the bounds low and high.So, if the input is like d = 1, low = 1, high = 13, then the output will be 6, as digit d=1 occurs 6 times like 1, 10, 11, 12, 13.To solve this, we will follow these steps −Define a function zero(), this will take n, ret ...

Read More

Number of Valid Subarrays in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 502 Views

Suppose we have an array A of integers, we have to find the number of non-empty continuous subarrays that satisfy this condition: The leftmost element of the subarray is not larger than other elements in the subarray.So, if the input is like [1, 4, 2, 5, 3], then the output will be 11, as there are 11 valid subarrays, they are like [1], [4], [2], [5], [3], [1, 4], [2, 5], [1, 4, 2], [2, 5, 3], [1, 4, 2, 5], [1, 4, 2, 5, 3].To solve this, we will follow these steps −ret := 0n := size of numsDefine ...

Read More

Minimize Max Distance to Gas Station in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 1K+ Views

Suppose we have one horizontal number line. On that number line, we have gas stations at positions stations[0], stations[1], ..., stations[N-1], where N = size of the stations array. Now, we add K more gas stations so that D, the maximum distance between adjacent gas stations, is minimized. We have to find the smallest possible value of D.So, if the input is like stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], K = 9, then the output will be 0.5To solve this, we will follow these steps −Define a function ok(), this will take x, array ...

Read More

Basic Calculator III in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 888 Views

Suppose we have a simple expression string and we have to Implement a basic calculator to evaluate that expression. The expression string may contain opening and closing parentheses, the plus + or minus sign -, non-negative integers and empty spaces. The expression string contains only non-negative integers, +, -, *, / operators, opening and closing parentheses and empty spaces. The integer division should truncate toward zero.So, if the input is like "6-4 / 2", then the output will be 4To solve this, we will follow these steps −l1 := 0, l2 := 1o1 := 1, o2 := 1Define one stack ...

Read More

Employee Free Time in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 604 Views

Suppose we have given a list of schedules of employees; this represents the working time for each employee. Now suppose each employee has a list of non-overlapping Intervals, these intervals are sorted. We have to find the list of finite intervals representing the common, positive-length free time for all employees, and that will also be in sorted order. We are representing Intervals in the form [x, y], For example, schedule [0][0].start = 1, schedule[0][0].end = 2.So, if the input is like schedule = [[[1, 2], [5, 6]], [[1, 3]], [[4, 10]]], then one of the output will be [[3, 4]].To ...

Read More

K Empty Slots in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Jul-2020 450 Views

Suppose we have N bulbs in a row and they are numbered from 1 to N. At first, all the bulbs are off. We can turn on exactly one bulb everyday until all bulbs are on after N days. If we have an array bulbs of length N where bulbs[i] = x this indicates that on the (i+1)th day, we will turn on the bulb at position x. If we have another integer K, such that out the minimum day number such that there exists two turned on bulbs that have exactly K bulbs between them that are all off. ...

Read More
Showing 2271–2280 of 3,768 articles
« Prev 1 226 227 228 229 230 377 Next »
Advertisements