Find Missing Element in a Sorted Array of Consecutive Numbers in C++

Arnab Chakraborty
Updated on 25-Jul-2020 09:38:44

458 Views

ConceptWith respect of a given array array[] of n distinct integers, elements are placed sequentially in ascending order with one missing element. Our task is to determine the missing element.Inputarray[] = {1, 2, 3, 4, 5, 6, 7, 9}Output8Inputarray[] = {-4, -2, -1, 0, 1, 2}Output-3Inputarray[] = {1, 2, 3, 4}Output-1No element is missing.MethodPrinciplesLook for inconsistency: According to this principle, the difference between any element and its index must be array[0] for every element.Example, A[] = {1, 2, 3, 4, 5} -> ConsistentB[] = {201, 202, 203, 204} -> ConsistentC[] = {1, 2, 3, 5, 6} -> Inconsistent as C[3] ... Read More

Find Minimum Time to Finish All Jobs with Given Constraints in C++

Arnab Chakraborty
Updated on 25-Jul-2020 09:34:02

427 Views

ConceptWith respect of a given array of jobs with different time requirements, there exists k identical assignees available and we are also provided how much time an assignee consumesto do one unit of the job. Our task is to determine the minimum time to complete all jobs with following constraints.The first constraint is that an assignee can be assigned only contiguous jobs.Here, for example, an assignee can be assigned jobs at position 1 and 2, but not at position 3, in an array.The second constraint is that two assignees cannot share (or co-assigned) a job, that means, a job cannot ... Read More

Find Minimum Adjustment Cost of an Array in C++

Arnab Chakraborty
Updated on 25-Jul-2020 09:22:58

432 Views

ConceptWith respect of a given array of positive integers, we replace each element in the array so that the difference between adjacent elements in the array is either less than or equal to a given target. Now, our task to minimize the adjustment cost, that is the sum of differences between new and old values. So, we basically need to minimize Σ|A[i] – Anew[i]| where 0 ≤ i ≤ n-1, n is denoted as size of A[] and Anew[] is denoted as the array with adjacent difference less than or equal to target. Let all elements of the array is ... Read More

Find Maximum Points by Deleting Elements from Array in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:52:43

155 Views

ConceptWith respect of a given array A having N elements and two integers l and r where, 1≤ ax ≤ 105 and 1≤ l≤ r≤ N. We can select any element of the array (let’s say ax) and delete it, and also delete all elements equal to ax+1, ax+2 … ax+R and ax-1, ax-2 … ax-L from the array. This step will cost ax points. Our task is to maximize the total cost after deleting all the elements from the array.Input2 1 2 3 2 2 1 l = 1, r = 1Output8Here, we choose 2 to delete, then (2-1)=1 ... Read More

Find Maximum Operations to Reduce N to 1 in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:49:31

138 Views

ConceptWith respect of given two numbers P and Q ( P and Q can be up to 10^6 ) which forms a number N = (P!/Q!). Our task is to reduce N to 1 by performing maximum number of operations possible. Remember, in each operation, one can replace N with N/X if N is divisible by X. Determine the maximum number of operations that can be possible.InputA = 7, B = 4Output4ExplanationN is 210 and the divisors are 2, 3, 5, 7InputA = 3, B = 1Output2ExplanationN is 6 and the divisor are 2, 3.MethodIt has been observed that factorization ... Read More

Find Maximum N for Sum of Squares in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:45:08

480 Views

ConceptWith respect of a given integer X, our task is to determine the maximum value N so that the sum of first N natural numbers should not exceed X.InputX = 7Output22 is the maximum possible value of N because for N = 3, the sum of the series will exceed X i.e. 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14InputX = 27Output33 is the maximum possible value of N because for N = 4, the sum of the series will exceed X i.e. 1^2 + 2^2 + 3^2 + 4^2 = 1 + 4 + ... Read More

Find Maximum Length Snake Sequence in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:42:11

336 Views

ConceptWith respect of a given grid of numbers, determine maximum length Snake sequence and display it. It has been observed that if multiple snake sequences exist with the maximum length, display any one of them.Actually, a snake sequence is made up of adjacent numbers in the grid so that for each number, the number on the right or the number below it is either +1 or -1 its value. Here, for instance, if we are at location (a, b) in the grid, we can either move right i.e. (a, b+1) if that number is ± 1 or move down i.e. ... Read More

Find Maximum Distance Between Any City and Station in C++

Arnab Chakraborty
Updated on 25-Jul-2020 08:36:46

470 Views

ConceptWith respect of the given number of cities N numbered from 0 to N-1 and the cities in which stations are located, our task is to determine the maximum distance between any city and its nearest station. It should be noted that the cities with stations can be given in any order.InputnumOfCities = 6, stations = [2, 4]Output2InputnumOfCities = 6, stations = [4]Output4The following figure indicates the first example containing 6 cities and the cities with stations highlighted with green color. So, in this case, the farthestcities from its nearest stations are 0 at a distance of 2. Hence maximum ... Read More

Distinguish Between EBIT and Net Income

Mandalika
Updated on 25-Jul-2020 07:26:33

333 Views

The major differences between EBIT and net income are as follows −EBIT (Earnings before Interest and Taxes)It evaluates profits earned through an entity.An operating income earned by an entity before adjustments (interests and taxes) is EBIT.The main purpose is to determine profit earning of an entity.EBIT can be defined as difference between revenue and operating expense (or) sum of net income, interest and taxes (or) difference between Earnings Before Interest Tax Depreciation and Amortisation (EBITA) and depreciation, amortisation expensesIt is used by governments, equity holders and debt holders.Interest and expenses incurred are not considered.Cost of operating business is ignored.Operating expenses ... Read More

Compare Joint Venture and Partnership

Mandalika
Updated on 25-Jul-2020 07:25:42

237 Views

The major differences between joint venture and partnership are as follows −Joint VentureIt is a trade formed by two or more individuals.The duration of time is fixed.The parties are called Co-Ventures.The profit/loss are distributed on interim basis.There are no specific governing laws.A specific name is not required.The accounts may/may not be separately maintained.It follows liquidation accounting.It includes profit-seeking ventures.A minor is not accepted as a Co-Venturer.PartnershipIt is an agreement made by two or more individuals having respective proportionate shares to start a business.The duration of time is not fixed.The parties are called partners.The profit is distributed annually.It is regulated by ... Read More

Advertisements