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
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
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
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
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
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
Suppose we have an array called houses and have another value k. Here houses[i] represents the location of the ith house along a street, we have to allocate k mailboxes in the street, and find the minimum total distance between each house and its nearest mailbox.So, if the input is like houses = [6, 7, 9, 16, 22] k = 2, then the output will be 9 because if we place mailbox at 7 and 18, then minimum total distance from each house is |6-7|+|7-7|+|9-7|+|16- 18|+|22-18| = 1+0+2+2+4 = 9.To solve this, we will follow these steps −sort the list ... Read More
Suppose there is an array of size m, represents m houses in a small city, each house must be painted with one of the n colors (the colors are labeled from 1 to n), And some houses are already painted, so no need to paint again. Those houses which are colored with same color are called neighborhood. We have the array houses, where houses[i] represents the color of the house, if the color value is 0, then it represents the house is not colored yet. We have another array called costs, this is a 2D array where costs[i, j] represents ... Read More
Suppose, we are given a m x n grid box, where each cell has a board that is positioned either from the top-right to bottom-left, or from the top-left to the bottom-right. Now from the top cells, a ball is put into the box and we have to check if that ball reaches the bottom of the box. The grid is given as a matrix. If a cell is marked 1 the diagonal board spans from the top-left to the bottom-right; if it is marked -1 it spans from the top-right to the bottom-left corner. If n balls are put ... Read More
Suppose we have two strings, s and t, we have to check whether s and t are close or not. We can say two strings are close if we can attain one from the other using the following operations −Exchange any two existing characters. (like abcde to aecdb)Change every occurrence of one existing character into another existing character, and do the same with the other characters also. (like aacabb -> bbcbaa (here all a's are converted to b's, and vice versa))We can use the operations on either string as many times as we want.So, if the input is like s ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP