Programming Articles - Page 1981 of 3366

Most Profit Assigning Work in C++

Arnab Chakraborty
Updated on 30-Apr-2020 06:04:56

375 Views

Suppose we have jobs difficulty[i] and this array indicates the difficulty of the ith job, and profit[i] is the profit of the ith job. Now consider we have some workers. worker[i] is the ability of the ith worker, this means that this worker can only complete a job with difficulty at most worker[i]. Every worker can do at most one job, but one job can be completed multiple times. We have to find what is the most profit we can make?For example, if the input is like difficulty = [2, 4, 6, 8, 10] and profit = [10, 20, 30, ... Read More

Number of Matching Subsequences in C++

Arnab Chakraborty
Updated on 30-Apr-2020 06:00:45

341 Views

Suppose we have a string S and a dictionary of words words, find the number of words[i] that is a subsequence of S. So if the input is S= “abcde” and dictionary is [“a”, “bb”, “acd”, “ace”], then output will be 3. Because there are three sequence of words in the dictionary, that are a subsequence of S: “a” “acd” and “ace”To solve this, we will follow these steps −n := size of words arraycreate one map mfor i in range 0 to size of wordsinsert words[i] into the map m[words[i, 0]] positionans := 0for i in range 0 to ... Read More

Reorganize String in C++

Arnab Chakraborty
Updated on 30-Apr-2020 05:57:20

662 Views

Suppose we have a string S, check whether the letters can be rearranged so that two characters that are adjacent to each other are not the same. If that is possible, output any possible result. If that is not possible, return the empty string. So if the input is like “AAB”, then the output will be “ABA”.To solve this, we will follow these steps −Make a priority queue of integer character pairs called pq, define one map mn := size of the stringstore the character frequency in map mfor each key-value pair p in minsert (integer part of p, character ... Read More

Kth Smallest Element in a Sorted Matrix in Python

Arnab Chakraborty
Updated on 30-Apr-2020 05:54:09

460 Views

Suppose we have a n x n matrix where each of the rows and columns are sorted in increasing order, we have to find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth unique element. So if the input is like [[1, 5, 9], [10, 11, 13], [12, 13, 15]], if k = 8, then the output will be 13.To solve this, we will follow these steps −define one method called checkVal() and the arguments are matrix and valuei := 0, j := length of matrix[0] – ... Read More

Guess Number Higher or Lower II in C++

Arnab Chakraborty
Updated on 29-Apr-2020 14:25:59

318 Views

Suppose we are playing the Guess Game. The rules of the game is as follows −Player1 pick a number from 1 to n. player2 have to guess which number is picked by player1.Every time player2 guess wrong, player1 will tell whether the number that is picked is higher or lower.However, when a player guess a particular number x, and another player guess wrong, another player has to pay $x. The game will end, when player2 got the correct answer.For example if n = 10, and the player1 has taken 8In the first round, player2 tells the number is 5, that ... Read More

Find K Pairs with Smallest Sums in C++

Arnab Chakraborty
Updated on 29-Apr-2020 14:15:57

214 Views

Suppose we have two sorted arrays A1 and A2, and another value k. We have to define a pair (u, v) which is consists of one element from A1 and another element from A2. We have to find the k pairs like [(u1, v1), (u2, v2), …, (uk, vk)]. So if A1 = [1, 7, 11] and A2 = [2, 4, 6], and k = 3, then output will be [(1, 2), (1, 4), (1, 6)]To solve this, we will follow these steps −Define one data type, that will take two values a and b, and index.create one priority queue, ... Read More

Populating Next Right Pointers in Each Node II in C++

Arnab Chakraborty
Updated on 29-Apr-2020 14:04:39

155 Views

Suppose we have a binary tree, where each node has following fields: (data, left, right, next), the left will point to left subtree, right will point to right subtree, and the next pointer will point to the next node. If there is no node in the right hand side, then that will be null. So initially each next pointer is set to null, we have to make the links. Suppose the tree is like the first one, it will be converted to the next node −To solve this, we will follow these steps −set pre := root, nextPre := null ... Read More

What is the importance of the jcmd tool in Java 9?

raja
Updated on 29-Apr-2020 14:18:03

168 Views

The "jcmd" is JVM diagnostic tool, which is a command-line tool to run diagnostic commands against given JVM on the local machine. This tool has been included in the JDK installation since Java 7 version, and it can be represented by the "%java_home%\bin\jcmd.exe" program file. If we have "%java_home%\bin" directory included in "path" the environment variable, we can run "jcmd -h" command to see a complete list of all options as belowC:\Users\User>jcmd -h Usage: jcmd    or: jcmd -l    or: jcmd -h    command must be a valid jcmd command for the selected jvm.    Use the command "help" to ... Read More

Populating Next Right Pointers in Each Node in C++

Arnab Chakraborty
Updated on 29-Apr-2020 14:10:34

284 Views

Suppose we have a complete binary tree, where each node has following fields: (data, left, right, next), the left will point to left subtree, right will point to right subtree, and the next pointer will point to the next node. If there is no node in the right hand side, then that will be null. So initially each next pointer is set to null, we have to make the links. Suppose the tree is like the first one, it will be converted to the next node −To solve this, we will follow these steps −set pre := root, nextPre := ... Read More

What are the changes of class loaders in Java 9?

raja
Updated on 29-Apr-2020 10:49:22

942 Views

All java programs run on Java Virtual Machine (JVM). After compilation, a java class gets transformed into a platform and machine-independent bytecode, and compiled classes are stored as .class files. Whenever we try to use it, ClassLoader loads that class into memory. The classes get introduced into the Java environment when they are referenced by name. The loading of classes has been done by the class loader, once the class starts running, and the main() method is a way to start that class.There are few minor changes of class loaders in Java 9:The system class loader is no more in Java 9, ... Read More

Advertisements