Maximum Profit by Selling Diminishing Valued Colored Balls in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:18:13

291 Views

Suppose we have an array called, inventory, where inventory[i] represents the number of balls of the ith color we have initially. We also have a value called orders, which represents the total number of balls that the customer wants. we can sell the balls in any order. In our inventory there are different colored balls, customers want balls of any color. Now the values of the balls are special in nature. Each colored ball's value is the number of balls of that color we have in our inventory. So if we currently have 6 blue balls, the customer would pay ... Read More

Farthest Building a Parkour Artist Can Reach in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:13:44

201 Views

Suppose, there are n number of houses of different heights and a parkour artist wants to go from one house to another with help of some bricks and ladders. The heights of the houses are given to us as an array. Each brick is a unit length tall and we are given a handful of those. We can use the ladders and the bricks only once. We have to find out the furthest building the parkour artist can go to.So, if the input is like heights = [5, 8, 7, 6, 2, 3, 1, 4], bricks = 3, ladders = ... Read More

Check if Subarrays can be Rearranged from Arithmetic Sequence in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:09:18

205 Views

Suppose we have sequence of numbers nums, and another two arrays l and r of size m, these l and r are representing range queries like [l[i], r[i]]. We have to find a Boolean sequence ans, where ans[i] is true when the subarray nums[l[i]], nums[l[i] + 1], ... nums[r[i] - 1], nums[r[i]] can be arranged to generate an arithmetic sequence, otherwise false.A sequence is said to be arithmetic, if it consists of at least two elements, and the difference between every two consecutive elements is the same. For example, some arithmetic sequences are: [2, 4, 6, 8, 10], [5, 5, ... Read More

AngularJS isArray Function

Mayank Agarwal
Updated on 06-Oct-2021 07:06:57

2K+ Views

The angular.isArray() function in AngularJS basically checks if a reference is an Array or not. This method will return True if the reference passed inside the function is an Array type, else it will return False.Syntaxangular.isArray(value)Example − Check if the reference is an Array or notCreate a file "isArray.html" in your Angular project directory and copy-paste the following code snippet.           angular.isArray()                              Welcome to Tutorials Point             AngularJS | angular.isArray()       ... Read More

Split Two Strings to Make Palindrome Using Python

Arnab Chakraborty
Updated on 05-Oct-2021 14:24:40

829 Views

Suppose we have two strings a and b whose length are same. We have to select an index and split both strings at that selected index, splitting a into two strings: a_pref and a_suff where a = a_pref | a_suff, and splitting b into two strings: b_pref | b_suff (| is concatenation operator) where b = b_pref + b_suff. Check if a_pref + b_suff or b_pref + a_suff forms a palindrome or not. (Any split may be an empty string)So, if the input is like a = "pqrst" b = "turqp", then the output will be True because we can ... Read More

Find Number of People Receiving Food Packets Using Python

Arnab Chakraborty
Updated on 05-Oct-2021 14:09:05

462 Views

Suppose in a conference, there are two types of people. The first type of people prefers a vegetarian lunch, and the other type prefers a non-vegetarian lunch. But there are a limited number of packets, and if the vegetarians receive a non-vegetarian packet or vice versa; they will not take that packet and wait until they get their preferred one. So, the two different types of packets and people are denoted as 0 for vegetarian and 1 for non-vegetarian. Now we are given two arrays, one containing n number of food packets denoted by 0 and 1 and another array ... Read More

Maximize Minimum Force Between Balls in a Bucket Using Python

Arnab Chakraborty
Updated on 05-Oct-2021 13:38:36

286 Views

Suppose we are given several buckets and x number of balls. If the balls are put into the bucket, a special force acts within them and we have to find out a way to maximize the minimum force between two balls. The force between two balls in a bucket of position p and q is |p - q|. The input given to us is the array containing the bucket positions and the number of balls x. We have to find out the minimum force between them.So, if the input is like pos = [2, 4, 6, 8, 10, 12], x ... Read More

Find Array of Doubled Pairs Using Python

Arnab Chakraborty
Updated on 05-Oct-2021 13:28:52

162 Views

Suppose we have an array of called nums whose length is even, we have to check whether it is possible to reorder it in such a way that nums[2*i + 1] = 2*nums[2*i] for every 0 cnt[2 * x], thenreturn Falsecnt[2 * x] := cnt[2 * x] - cnt[x]return TrueExampleLet us see the following implementation to get better understanding −from collections import Counter def solve(nums):    cnt = Counter(nums)    for x in sorted(cnt, key=abs):       if cnt[x] > cnt[2 * x]:       return False cnt[2 * x] -= cnt[x] return True nums = [4,-2,2,-4] print(solve(nums))Input[6,0,8,2,1,5]OutputTrue

Find Minimum Moves to Make Array Complementary in Python

Arnab Chakraborty
Updated on 05-Oct-2021 13:26:17

374 Views

Suppose we have an array nums of even length another value limit. In one move, we can replace any value from nums with another value between 1 and limit, inclusive. The array is said to be complementary if for all indices i, nums[i] + nums[n-1-i] equals the same number. So we have to find the minimum number of moves required to make nums complementary.So, if the input is like nums = [1, 4, 2, 3] limit = 4, then the output will be 1 because in one move we can make element at index 1 to 2, so array will ... Read More

Find the Most Competitive Subsequence in Python

Arnab Chakraborty
Updated on 05-Oct-2021 13:20:01

243 Views

Suppose we have an array nums and another value k, we have to find the most competitive subsequence of nums of size k. Here a subsequence s1 is more competitive than a subsequence s2 (of equal size) if in the first position where s1 and s2 differ, subsequence s1 has a number less than the corresponding number in s2.So, if the input is like nums = [4, 6, 3, 7] k = 2, then the output will be [3, 7] because among all subsequences of size 2, {[4, 6], [4, 3], [4, 7], [6, 3], [6, 7], [3, 7]}, the ... Read More

Advertisements