Programming Articles - Page 1724 of 3366

Maximum points collected by two persons allowed to meet once in C++

Ayush Gupta
Updated on 09-Sep-2020 12:06:27

117 Views

In this tutorial, we will be discussing a program to find maximum points collected by two persons allowed to meet onceFor this we will be provided with a matrix with cells containing points. Our task is to find the path when two people starting from two corners meet such that they are having maximum points collected.Example Live Demo#include #define M 3 #define N 3 using namespace std; int findMaxPoints(int A[][M]) {    //storing points    int P1S[M+1][N+1], P1E[M+1][N+1];    memset(P1S, 0, sizeof(P1S));    memset(P1E, 0, sizeof(P1E));    int P2S[M+1][N+1], P2E[M+1][N+1];    memset(P2S, 0, sizeof(P2S));    memset(P2E, 0, sizeof(P2E));    for (int ... Read More

Differences between String and StringBuffer

Himanshu shriv
Updated on 09-Sep-2020 12:05:04

14K+ Views

String is an immutable class and its object can’t be modified after it is created but definitely reference other objects. They are very useful in multithreading environment because multiple threads can’t change the state of the object so immutable objects are thread safe.String buffer is mutable classes which can be used to do operation on string object such as reverse of string, concating string and etc. We can modify string without creating new object of the string. String buffer is also thread safe.Also, string concat + operator internally uses StringBuffer or StringBuilder class. Below are the differences.Sr. No.KeyStringStringBuffer1BasicString is an ... Read More

Maximum path sum that starting with any cell of 0-th row and ending with any cell of (N-1)-th row in C++

Ayush Gupta
Updated on 09-Sep-2020 12:02:53

178 Views

In this tutorial, we will be discussing a program to find maximum path sum that starting with any cell of 0-th row and ending with any cell of (N-1)-th rowFor this we will be provided with a matrix with possible moves of (i+1, j), (i+1, j-1), (i+1, j+1). Our task is to start from zeroth position and move to last row finding out the maximum sum path.Example Live Demo#include using namespace std; #define N 4 //finding maximum sum path int MaximumPath(int Mat[][N]) {    int result = 0 ;    int dp[N][N+2];    memset(dp, 0, sizeof(dp));    for (int i = ... Read More

Difference between compile-time polymorphism and runtime polymorphism

Himanshu shriv
Updated on 12-Sep-2023 09:54:51

36K+ Views

Polymorphism is one of the most important OOPs concepts. Its is a concept by which we can perform single task in multiple ways. There are two types of polymorphism one is Compile-time polymorphism and another is run-time polymorphism.Method overloading is the example of compile time polymorphism and  method overriding is the example of run-time polymorphism.Sr. No.KeyCompile-time polymorphismRuntime polymorphism1BasicCompile time polymorphism means binding is occuring at compile timeR un time polymorphism where at run time we came to know which method is going to invoke2Static/DynamicBindingIt can be achieved through static bindingIt can be achieved through dynamic binding4.InheritanceInheritance is not involvedInheritance is ... Read More

Maximum path sum for each position with jumps under divisibility condition in C++

Ayush Gupta
Updated on 09-Sep-2020 11:57:56

123 Views

In this tutorial, we will be discussing a program to find maximum path sum for each position with jumps under divisibility conditionFor this we will be provided with an array of n random integers. Our task is to jump from one position to another if it divides it and finally provide the maximum sum path for every given position.Example Live Demo#include using namespace std; //finding maximum sum path void printMaxSum(int arr[], int n) {    int dp[n];    memset(dp, 0, sizeof dp);    for (int i = 0; i < n; i++) {       dp[i] = arr[i];   ... Read More

Difference between mutable and immutable object

Aishwarya Naglot
Updated on 10-Oct-2024 14:18:27

4K+ Views

In Java, state of the immutable object can’t be modified after it is created but definitely reference other objects. They are very useful in multi-threading environment because multiple threads can’t change the state of the object so immutable objects are thread-safe. Immutable objects are very helpful to avoid temporal coupling and always have failure atomicity and also helpful in multiple threading. Why though? because no one can change the object right? So, it becomes thread-safe, it means it will not cause any unexpected issues when different parts of the program are trying to access that particular object. On the other ... Read More

Maximum parent children sum in Binary tree in C++

Ayush Gupta
Updated on 09-Sep-2020 11:55:49

248 Views

In this tutorial, we will be discussing a program to find maximum parent children sum in Binary treeFor this we will be provided with a binary tree. Our task is to add up the parent node with its children nodes and finally find the maximum of all of that and print it out.Example Live Demo#include using namespace std; struct Node {    int data;    struct Node *left, *right; }; //inserting nodes struct Node* newNode(int n) {    struct Node* root = new Node();    root->data = n;    root->left = root->right = NULL;    return root; } int maxSum(struct ... Read More

Maximum of sum and product of digits until number is reduced to a single digit in C++

Ayush Gupta
Updated on 09-Sep-2020 11:52:37

262 Views

In this tutorial, we will be discussing a program to find maximum of sum and product of digits until number is reduced to a single digitFor this we will be provided with a random number. Our task is to find and print out the maximum of sum and product of the digits of the given number until it coverts to a single digitExample Live Demo#include using namespace std; //converting number to single digit by adding long repeatedSum(long n) {    if (n == 0)       return 0;    return (n % 9 == 0) ? 9 : (n % ... Read More

Maximum of smallest possible area that can get with exactly k cut of given rectangular in C++

Ayush Gupta
Updated on 09-Sep-2020 11:49:21

144 Views

In this tutorial, we will be discussing a program to find the maximum of smallest possible area that can get with exactly k cut of given rectangular.For this we will be provided with the sides of the rectangle and the number of cuts that can be made. Our task is to calculate the smallest area that can be achieved by making the given number of cuts.Example Live Demo#include using namespace std; void max_area(int n, int m, int k) {    if (k > (n + m - 2))       cout

Difference between CountDownLatch and CyclicBarrier in Java Concurrency

Himanshu shriv
Updated on 09-Sep-2020 11:55:46

1K+ Views

CountDownLatch and CyclicBarrier both used in multithreading environment and they both are part of.As per Java Doc −CountDownLatch − A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes.CyclicBarrier − A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.Sr. No.KeyCyclicBarrierCountDownLatch1BasicA synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.A synchronization aid that allows one or more threads to wait until a set of operations being ... Read More

Advertisements