Programming Articles - Page 2163 of 3366

Maximum length of a sub-array with ugly numbers in C++

Narendra Kumar
Updated on 10-Jan-2020 07:31:31

130 Views

Problem statementGiven an array arr[] of N elements (0 ≤ arr[i] ≤ 1000). The task is to find the maximum length of the sub-array that contains only ugly numbers.Ugly numbers are numbers whose only prime factors are 2, 3 or 5.For Example below are the few number from series: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …ExampleIf input array is {1, 2, 7, 9, 120, 810, 374} then answer is 3 as −Longest possible sub-array of ugly number sis {9, 120, 810}AlgorithmTake a unordered_set, and insert all the ugly numbers which are less than 1000 in ... Read More

Maximum height of triangular arrangement of array values in C++

Narendra Kumar
Updated on 10-Jan-2020 07:21:57

148 Views

Problem statementGiven an array, we need to find the maximum height of the triangle which we can form, from the array values such that every (i+1)th level contain more elements with the larger sum from the previous level.ExampleIf input array is {40, 100, 20, 30 } then answer is 2 as −We can have 100 and 20 at the bottom level and either 40 or 30 at the upper level of the pyramidAlgorithmOur solution just lies on the logic that if we have maximum height h possible for our pyramid then ( h * (h + 1) ) / 2 ... Read More

Difference between grep and fgrep command

Mahesh Parahar
Updated on 25-Feb-2020 06:05:24

808 Views

In any language or framework one of the most important and main feature is of searching the data. It not only denotes the performance of language but also represents in what manner the data is being stored. So specifically if we take an example of LINUX operating system there comes two of the important commands namely grep and fgrep.Both of these commands are used to search any string or regular expression in file, directory or even in multiple folders. Both these commands executes in such a way that processor starts analysing the target folder or destination and search for the ... Read More

Maximum games played by winner in C++

Narendra Kumar
Updated on 10-Jan-2020 07:19:37

505 Views

Problem statementThere are N players which are playing a tournament. We need to find the maximum number of games the winner can play. In this tournament, two players are allowed to play against each other only if the difference between games played by them is not more than oneExampleIf There are 3 players then 2 games are required to decide the winner as follows −Game – 1: player 1 vs player 2Game - 2: player 2 vs winner from Game - 1AlgorithmWe can solve this problem by first computing minimum number of players required such that the winner will play ... Read More

Maximum even length sub-string that is permutation of a palindrome in C++

Narendra Kumar
Updated on 10-Jan-2020 07:16:22

185 Views

Problem statementGiven a string the task is to find the maximum length of the sub-string of that can be arranged into a Palindrome.ExampleIf input string = “5432112356” then answer is 6 as maximum palindrome substring is “321123” and its length is 6AlgorithmIf the length of the sub-string is odd, then it cannot be considered in the final solutions.If the length of the sub-string is even, then it can be a possible solution only if each character in that sub-string occurs even number of times which can be done using the dictionary count. We check if each character occurs even number ... Read More

Difference between fundamental data types and derived data types in C++

Mahesh Parahar
Updated on 25-Feb-2020 06:00:18

445 Views

In programming data type denotes the type and nature of data which is intended to be use by the user. It is the data type which compiler or interpreter going to deal with and provides corresponding storing location in main memory.Now on the basis of nature of data Data type is mainly of two types one is Fundamental Data type and other is Derived Data type. Both these data types are used in programming and are equally important when need to implement the business logic over the data.Following are the important differences between Fundamental data types and Derived data typesSr. ... Read More

Maximum equlibrium sum in an array in C++

Narendra Kumar
Updated on 10-Jan-2020 07:10:53

462 Views

Problem statementGiven an array arr[]. Find maximum value of prefix sum which is also suffix sum for index i in arr[].ExampleIf input array is −Arr[] = {1, 2, 3, 5, 3, 2, 1} then output is 11 as −Prefix sum = arr[0..3] = 1 + 2 + 3 + 5 = 11 andSuffix sum = arr[3..6] = 5 + 3 + 2 + 1 = 11AlgorithmTraverse the array and store prefix sum for each index in array presum[], in which presum[i] stores sum of subarray arr[0..i]Traverse array again and store suffix sum in another array suffsum[], in which suffsum[i] stores ... Read More

Maximum element in a very large array using pthreads in C++

Narendra Kumar
Updated on 10-Jan-2020 07:07:59

505 Views

Problem statementGiven a very large array of integers, find maximum within the array using multithreadingExampleIf input array is {10, 14, -10, 8, 25, 46, 85, 1673, 63, 65, 93, 101, 125, 50, 73, 548} thenmaximum element in this array is 1673AlgorithmLet us call array size as total_elementsCreate N threadsEach thread will process (total_elementes/N) array elements and will find maximum element from it.Finally compute the maximum from the maximum value reported by each thread.Example#include #include #include #include #define MAX 10 #define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) typedef struct struct_max {    int start;    int end;    int ... Read More

Maximum element in a sorted and rotated array in C++

Ravi Ranjan
Updated on 09-Jun-2025 19:15:30

605 Views

A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. In this article, our task is to find the maximum element in the given sorted and rotated array. We will use the following two approaches mentioned below: Using Linear Search Using Binary Search Example Here is an example of ... Read More

Difference between Abstract Class and Interface in C# Program

Mahesh Parahar
Updated on 24-Feb-2020 11:51:10

3K+ Views

As we all know that C# is an object oriented programming just like Java and provides full support for object-oriented concepts that are Encapsulation, Abstraction, Inheritance, and Polymorphism. In contrast to Abstraction both Abstract class and Interface are coming out in picture as both of these provides abstraction in C# program.In an abstract class, we can create the functionality and that needs to be implemented by the derived class. The interface allows us to define the functionality or functions but cannot implement that. The derived class extend the interface and implement those functions.Following are the important differences between Abstract Class ... Read More

Advertisements