Programming Articles - Page 2082 of 3363

Combination Sum IV in C++

Arnab Chakraborty
Updated on 28-Apr-2020 11:53:24

304 Views

Suppose we have an integer array with all positive numbers and all elements are unique, find the number of possible combinations, so that if we add up, we will get positive integer target.So if the array is [1, 2, 3] and the target is 4, then the possible combinations will be [[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 3], [3, 1], [2, 2]], so output will be 7.To solve this, we will follow these steps −Suppose we have one recursive function called solve(), this is taking array, target and another array for dynamic ... Read More

Coin Change in Python

Arnab Chakraborty
Updated on 28-Apr-2020 11:50:21

5K+ Views

Suppose we have coins of different denominations and a total amount of money amount. We have to define one function to compute the fewest number of coins that we need to make up that amount. When that amount of money cannot be accommodated by any combination of the coins, return -1. So if the input is [1, 2, 5], and the amount is 11, the output is 3. This is formed using 5 + 5 + 1 = 11.To solve this, we will follow these steps −if amount = 0, then return 0if minimum of coins array > amount, then ... Read More

Fixed Point in Python

Arnab Chakraborty
Updated on 28-Apr-2020 08:24:35

1K+ Views

Suppose we have an array A of unique integers sorted in ascending order, we have to return the smallest index i that satisfies A[i] == i. Return -1 if no such i exists. So if the array is like [-10, -5, 0, 3, 7], then the output will be 3, as A[3] = 3 the output will be 3.To solve this, we will follow these steps −For i in range 0 to length of Aif i = A[i], then return ireturn -1Example(Python)Let us see the following implementation to get a better understanding − Live Democlass Solution(object):    def fixedPoint(self, A):   ... Read More

Sum Root to Leaf Numbers in Python

Arnab Chakraborty
Updated on 28-Apr-2020 11:45:08

473 Views

Suppose we have a binary tree containing digits from 0-9 only, here all root-to-leaf path could represent a number.So if the tree is like −This is representing two paths 21 and 23, so the output will be 21 + 23 = 44.To solve this, we will follow these steps −Create one recursive function called dfs(), this will take root, and num. initially num = 0if the node is not nullnum := num * 10 + value of nodeif node right is not null and node left is not null, then’sum := sum + numnum := num / 10return from the ... Read More

What is the JLink tool in Java 9?

Alshifa Hasnain
Updated on 11-Jun-2025 17:27:20

510 Views

What is JLink? Java Linker is a new linker tool that has been used to create our own customized JRE. Usually, we can run our program using default JRE provided by Oracle. If we need to create our own JRE then use this tool. JLink tool can help to create its own JRE with only the required class to run the application. It can reduce the size of the API developed and the dependency of using the full JRE.  In Java 9, we have a new phase between compiling the code and its execution, link time. Link time is an optional phase between the phases of ... Read More

Validate Binary Search Tree in Python

Farhan Muhamed
Updated on 22-Aug-2025 15:53:32

1K+ Views

A binary search tree is a special binary tree in which for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will discuss how to validate whether a given binary tree is a valid binary search tree (BST) in Python. Validate Binary Search Tree Algorithm to Validate Binary Search Tree Python Program to Validate Binary Search Tree Validate Binary Search Tree Given a root node of ... Read More

Unique Binary Search Trees in C++

Farhan Muhamed
Updated on 19-Aug-2025 17:27:24

300 Views

The Unique Binary Search Trees problem is a classic dynamic programming problem that counts the number of unique binary search tree (BSTs) that can be formed with a given number of nodes. In this article, we will explain the problem, testcases, its solution, and provide a C++ implementation. Number of Unique BSTs In this problem, we are given an integer n, which represents the number of nodes in a binary search tree. The task is to find the number of different BSTs that can be formed using these n nodes and return the count. To understand the problem better, ... Read More

Unique Binary Search Trees II in C++

Arnab Chakraborty
Updated on 28-Apr-2020 11:21:10

470 Views

Suppose we have an integer n, we have to generate all structurally unique binary search trees that store values from 1 to n. So if the input is 3, then the trees will be −To solve this, we will follow these steps −Define one recursive function called generate(), this will take low and highdefine one tree node called temp.if low > high, then insert null into the temp, and return tempfor i in range low to highleft_subtree := generate(low, i – 1)right_subtree := generate(i + 1, high)current := ifor j in range 0 to size of the left_subtreefor k in ... Read More

Importance of transferTo() method of InputStream in Java 9?

raja
Updated on 26-Feb-2020 13:20:24

2K+ Views

The transferTo() method has been added to the InputStream class in Java 9. This method has been used to copy data from input streams to output streams in Java. It means it reads all bytes from an input stream and writes the bytes to an output stream in the order in which they are reading.Syntaxpublic long transferTo(OutputStream out) throws IOExceptionExampleimport java.util.Arrays; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class TransferToMethodTest {    public void testTransferTo() throws IOException {       byte[] inBytes = "tutorialspoint".getBytes();       ByteArrayInputStream bis = new ByteArrayInputStream(inBytes);       ByteArrayOutputStream bos = new ... Read More

deque_insert( ) in C++ in STL

Sunidhi Bansal
Updated on 26-Feb-2020 12:24:12

752 Views

Given is the task to show the functionality of Deque insert( ) function in C++ STLWhat is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in Double ended queue the ... Read More

Advertisements