Count Number of Homogenous Substrings in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:32:27

436 Views

Suppose we have a string s, we have to find the number of homogenous substrings of s. The answer may be very large, so return answer modulo 10^9+7. A string is said to be homogenous when all the characters of the string are the same.So, if the input is like s = "xyyzzzxx", then the output will be 13 because the homogenous substrings are listed like1."x" appears thrice."xx" appears once.3. "y" appears twice."yy" appears once.5. "z" appears thrice."zz" appears twice."zzz" appears once.so , (3 + 1 + 2 + 1 + 3 + 2 + 1) = 13.To solve this, ... Read More

AngularJS ng-blur Directive

Mayank Agarwal
Updated on 06-Oct-2021 08:31:33

654 Views

The ng-blur Directive in AngularJS is fired when an element loses focus from that element. The blur event is executed synchronously along with the DOM manipulations (like removing from the focus point).AngularJS also executes the expression using scope.$evalAsync if the event is fired during an $apply to ensure the consistent application state.Syntax..Content..Example 1 − ng-blur DirectiveCreate a file "ngBlur.html" in your Angular project directory and copy-paste the following code snippet.           ngBlur Directive                              Welcome to Tutorials Point ... Read More

Count Minimum Semesters to Cover All Different Courses in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:27:17

412 Views

Suppose we have a number n, indicates that there are n different courses labeled from 1 to n. We also have an array called relations where relations[i] contains a pair (prevCourse_i, nextCourse_i), representing a prerequisite relationship between the course prevCourse_i and the course nextCourse_i: so course prevCourse_i has to be taken before the course nextCourse_i. And the last parameter we have that is k. In one semester, we can take at most k number of courses as long as we have taken all the prerequisites in the previous semester for the courses we are taking. We have to find the ... Read More

Find Critical and Pseudo-Critical Edges in a Graph Using Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:23:47

758 Views

Suppose, we are given a graph that contains n vertices numbered 0 to n -1. The graph is undirected and each edge has a weight. So given the graph, we have to find out the critical and the pseudo-critical edges in the graphs MST. An edge is called a critical edge if deletion of that edge causes the MST weight to increase. A pseudo-critical edge is an edge that can appear in all the graphs MSTs, but not all. We find out the index of the edges given the graph as input.So, if the input is likeand number of vertices ... Read More

Find Maximum Score from Removing Stones in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:22:38

480 Views

Suppose we have three values a, b and c. We are playing a solitaire game with three piles of stones whose sizes are a, b, and c respectively. Each turn the player selects two different non-empty piles, take one stone from each, and add 1 point to his score. The game ends when there are fewer than two non-empty piles. So we have to find the maximum score you can get.So, if the input is like a = 4, b = 4, c = 6, then the output will be 7 because the initial state is (4, 4, 6), then ... Read More

Find Minimum Length of String After Deleting Similar Ends in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:17:25

375 Views

Suppose we have a string s with only three characters 'a', 'b', and 'c'. We shall apply the following algorithm on the string any number of times −Select a non-empty prefix from the s where all the characters in the prefix are same.Select a non-empty suffix from the s where all the characters in the suffix are same.The prefix and the suffix are disjoint.The characters from the prefix and suffix must be the same.Remove both the prefix and the suffix from s.Finally, we have to find the minimum length of s after performing the above operation any number of times ... Read More

Find Maximum Absolute Sum of Any Subarray in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:12:13

451 Views

Suppose we have an array called nums. We have to find the absolute sum of a subarray [nums_l, nums_l+1, ..., nums_r-1, nums_r] is |nums_l + nums_l+1 + ... + nums_r-1 + nums_r|. We have to find the maximum absolute sum of any subarray of nums (that subarray can possibly be empty).So, if the input is like nums = [2, -4, -3, 2, -6], then the output will be 11 because the subarray [2, -4, -3, 2] has maximum absolute subarray sum |2 + (-4) + (-3) + 2| = 11.To solve this, we will follow these steps −n:= size of ... Read More

Find Kth Ancestor of a Tree Node in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:06:53

389 Views

Suppose we have a tree with n nodes that are numbered from 0 to n-1. The tree is given by a parent array, where parent[i] is the parent of node i. The root of the tree is node 0. We have to find the kth ancestor of a given node, if the ancestor is not present, then return -1So, if the input is likethen the output will be 2 because the first ancestor of node 6 is 5 and the second is 2.To solve this, we will follow these steps −Define a function solve() . This will take parent, node, ... Read More

Check If We Can Eat Favorite Candy on Our Favorite Day in Python

Arnab Chakraborty
Updated on 06-Oct-2021 08:06:51

250 Views

Suppose we have an array of positive calues candiesCount where candiesCount[i] denotes the number of candies of the ith type we have. We also have another another array called queries where queries[i] has three parameters [favoriteType_i, favoriteDay_i, dailyCap_i]. We have some rules:We start eating candies on day 0.We cannot eat any candy of type i unless we have eaten all candies of previous i-1 types.We must eat at least one candy per day until we have eaten all of them.Maintaining these rules, we have to make an array of Boolean values for each query results and i-th entry is true ... Read More

Convert String to Uppercase in AngularJS

Mayank Agarwal
Updated on 06-Oct-2021 08:04:23

1K+ Views

Sometimes we may need to represent a name or a string in capital letters. To convert a string into uppercase in AngularJS, we can use the uppercase filter to change its case to uppercase.SyntaxIn HTML Template Binding{{uppercase_expression | uppercase}}In JavaScript$filter('uppercase')()Example − Conversion to Upper CaseCreate a file "uppercase.html" in your Angular project directory and copy-paste the following code snippet.    uppercase Filter               Welcome to Tutorials Point               AngularJS | UpperCase Filter                 ... Read More

Advertisements