Suppose Amal and Bimal are playing a game. They have an array nums which determines n bricks with numbered on top of it. In this game, players can alternatively remove one, two or three bricks from the top, and the numbers marked on the removed bricks are added to the score of that player. If always Amal starts first, we have to find how much score Amal get secure at maximum.So, if the input is like nums = [1, 2, 3, 4, 5], then the output will be 6 because, Amal can remove brick {1}, {1, 2} or {1, 2, ... Read More
Suppose Amal and Bimal are playing a game where they have one array A with some numbers.The game rules are as followsBimal will start alwaysIn each turn one player deletes the maximum element from the array and all other elements present at right of the deleted element will also be deleted.They play alternativelyThe player who removes all remaining elements, he will win the game.So, if the input is like nums = [5, 2, 6, 3, 4], then the output will be Amal because at first Bimal will remove [6, 3, 4] so array will be [5, 2], then Amal will ... Read More
Suppose we have two values n and m. We have to find number of possible arrangements of humble matrices of order n x m. A matrix is said to be humble whenIt contains each element in range 1 to n x m exactly oncefor any two indices pairs (i1, j1) and (i2, j2), if (i1 + j1) < (i2 + j2), then Mat[i1, j1] < Mat[i2, j2] should hold.If the answer is too large then return result mod 10^9 + 7.So, if the input is like n = 2 m = 2, then the output will be 2, because there ... Read More
Suppose, there is n number of cities and m roads connecting the cities. The citizens of the people need markets where they can buy their commodities. Now, there are no markets in the cities, and the roads between the cities are under construction.A two-way road can be built between two cities if (i) The city contains a market; (ii) The cities can be visited by the road where there is a market. The cost of building a road is x, and building a market is y and they are given. We have to find out the minimal cost to provide ... Read More
Suppose, we have a tree that has all of its nodes numbered as 1 to n. Each of the nodes contains an integer value. Now if we remove an edge from the tree, the difference in the sum of the node values of the two sub-trees has to be minimal. We have to find out and return the minimum difference between such sub-trees. The tree is given to us as a collection of edges, and the values of the nodes are also provided.So, if the input is like n = 6, edge_list = [[1, 2], [1, 3], [2, 4], [3, ... Read More
A smart number is a number that contains at least three distinct prime factors. You are given a number N. Find the n-th smart number.The smart number series are30, 42, 60, 66, 70, 78...AlgorithmInitialise the number N.Initialise the count to 0.Write a function that checks whether the given number is prime or not.Write a function that checks whether the number is smart or not.Write a loop that iterates from 30 as first smart number is 30.Check whether the current number is smart number or not using the prime number function.Increment the count by 1 when you find a smart number.Return ... Read More
The Chomsky hierarchy is a collection of various formal grammars. With the use of this formal grammar, it can generate some formal languages. They can be defined by multiple types of devices that can identify these languages such as finite state automata, pushdown automata, linear bounded automata, and Turing machines, respectively.Chomsky has suggested four different classes of phrase structure grammar as follows −Type-0 Grammar (Unrestricted Grammar) − Type-0 grammar is constructed with no restrictions on the replacement rule. A non-terminal must appear in the string on the left side. The language generated is called recursively enumerable language.Thus, type-0 grammar isAn ... Read More
The binding of a program element to a specific characteristic or property is the choice of the property from a set of possible properties. The time during program organization or processing when this choice is made is defined as the binding time of that property for that element. There are multiple varieties of bindings in programming languages, and a variety of binding times. It can also involve within the terms of binding and binding time the properties of program elements that are constant either by the definition of the language or its execution.Types of Binding TimesThere are two types of ... Read More
Programming environments have affected language design generally in two major areas such as features promoting separate compilation and assembly of a program from components, and features aiding program testing and debugging.Separate compilation − In the structure of any huge program it is regularly desirable to have multiple programmers or programming group design, code, and test elements of the program before the last assembly of all the elements into a complete program. This needed the language to be structured so that single subprograms or other elements can be separately compiled and implemented, without the other element, and thus later combined without ... Read More
The type conversion is an operation that takes a data object of one type and creates the equivalent data objects of multiple types. The signature of a type conversion operation is given as conversion_op :type1→type2There are two types of type conversions which are as follows −Implicit type conversion (Coercions) − The programming languages that enable mixed-mode expressions should describe conventions for implicit operand type conversions.Coercion is defined as an automatic conversion between types. For example in Pascal, if the operands for the addition operation are of integer type and other real types, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP