Programming Articles - Page 1018 of 3363

AngularJS – forEach() function

Mayank Agarwal
Updated on 08-Oct-2021 10:41:45

5K+ Views

The forEach() function in AngularJS uses the Iterator object to iterate over the collection of items or objects or an array. The iterator function is called with the iterator object(value, key, obj) where, value represents the object property or an array element, key specifies the object property key or array element index, andobj represents the whole object.Note that the forEach() function does not iterate over the inherited properties.Syntaxangular.forEach(obj, iterator, [context])Example − Iterate the values using forEach()Create a file "forEach.html" in your Angular project directory and copy-paste the following code snippet.           angular.forEach()     ... Read More

Program to find largest color value in a directed graph in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:46:08

353 Views

Suppose we have a directed graph with n colored nodes and m different edges. And the nodes are numbered from 0 to n-1. We have a string col with lowercase letters, where col[i] represents the color of the ith node in this graph (0-indexed). We also have an edge list where edges[j] = (u, v) represents, there is an edge between u and v.A valid path in the graph is a sequence of nodes xi for all i from 1 to k, such that there is a directed edge from xi to xi+1. The color of the path is the ... Read More

Program to find minimum interval to include each query in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:42:27

411 Views

Suppose we have a list of intervals, where intervals[i] has a pair (left_i, right_i) represents the ith interval starting at left_i and ending at right_i (both inclusive). We also have another array called queries. The answer to the jth query is the size of the smallest interval i such that left_i

Program to find closest room from queries in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:31:02

233 Views

Suppose there is an array called rooms. where rooms[i] contains a pair [roomId_i, size_i] denotes a room whose id is roomId_i and size is size_i. All room numbers are distinct. We also have another array queries, where queries[j] contains a pair [preferred_j, minSize_j]. The answer to the jth query is the room number id of a room such that −The room has size of at least minSize_j, and|id - preferred_j| is minimized.Now, if there is a tie in the absolute difference, then use the room with the smallest id. If there is no such room, return -1. So we have ... Read More

Program to find maximum building height in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:27:50

886 Views

Suppose we have a value n and another list of pairs called restrictions. We want to build n new buildings in a city. But there are few restrictions. We can built in a line and buildings are labeled from 1 to n. The restrictions has two parameters, so restrictions[i] = (id_i, max_height_i) indicates id_i must have height less than or equal to max_height_i. The city restrictions on the heights of the new buildings are as follows −The height of each building must be 0 or positive values.First building height must be 0.The difference between any two adjacent buildings height cannot ... Read More

Program to find XOR sum of all pairs bitwise AND in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:24:37

1K+ Views

Suppose we have two arrays arr1 and arr2. The XOR sum of a list is the bitwise XOR of all of its elements. If the list has only one element, then its XOR sum will be the element itself. Now, consider the list has the result of arr1[i] AND arr2[j] (bitwise AND) for every index pair (i, j) where 0

Program to find minimum number of operations to make string sorted in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:19:25

395 Views

Suppose we have a string s. We have to perform the following operation on s until we get a sorted string −Select largest index i such that 1

Program to find number of different subsequences GCDs in Python

Arnab Chakraborty
Updated on 08-Oct-2021 08:08:56

228 Views

Suppose we have an array nums with positive values. We have to find the number of different GCDs among all non-empty subsequences of nums. As we know the GCD of a sequence of numbers is the greatest value that divides all the numbers in the sequence evenly.So, if the input is like nums = [4, 6, 18], then the output will be 4 because gcd([4]) = 4, gcd([6]) = 6, gcd([18]) = 18 gcd([4, 6]) = 2, gcd([4, 18]) = 2, gcd([6, 18]) = 6, gcd([4, 6, 18]) = 2 so all numbers are [4, 6, 18, 2], there are ... Read More

Program to find maximum number of groups getting fresh donuts in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:58:58

181 Views

Suppose we have a value batchSize and an array group where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. So there is a donuts shop that bakes donuts in batches of given batchSize. But they have one rule, they must serve all of the donuts of a batch before serving any donuts of the next batch. And each customer will get exactly one donut. When a group enters the shop, all customers of that group must be served before addressing any next groups. One group may happy if they all get fresh donuts. ... Read More

Program to maximize number of nice divisors in Python

Arnab Chakraborty
Updated on 08-Oct-2021 07:55:56

213 Views

Suppose we have a number pf represents number of prime factors. We have to make a positive number n that satisfies the following conditions −The number of prime factors of n (may or may not be distinct) is at most pf.The number of nice divisors of n is maximized. As we know a divisor of n is nice when it is divisible by every prime factor of n.We have to find the number of nice divisors of n. If the answer is too large then return result modulo 10^9 + 7.So, if the input is like pf = 5, then ... Read More

Advertisements