Programming Articles

Page 1346 of 2547

Minimum Cost to Hire K Workers in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 631 Views

Suppose there are N workers. Each worker has the quality parameter. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire K workers to form a paid group. When we are hiring a group of K workers, we must pay them according to the following rules −Each worker in the paid group should be paid in the ratio of their quality by comparing with others in the paid group.Every worker in the paid group must be paid at least their minimum wage expectation.We have to find the least amount of money needed to ...

Read More

Longest Palindrome in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a string which consists of lowercase or uppercase letters, we have to find the length of the longest palindromes that can be built with those letters. Now the string is case sensitive, so "Aa" is not considered a palindrome here.So, if the input is like "abccccdd", then the output will be 7, as one longest palindrome that can be built is "dccaccd", whose length is 7.To solve this, we will follow these steps −Define one map mpfor each character i in s(increase mp[i] by 1)ma := 0, c := 0, ans := 0for each key-value pair i ...

Read More

Implementing Checksum Using Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

Following is the code to implement Checksum using Java −Exampleimport java.util.*; public class Demo{    public static void main(String args[]){       Scanner my_scan = new Scanner(System.in);       System.out.println("Enter the input string ");       String my_in = my_scan.next();       int my_checksum = generate_checksum(my_in);       System.out.println("The checksum that has been generated is " + Integer.toHexString(my_checksum));       System.out.println("Enter the data that needs to be sent to the receiver ");       my_in = my_scan.next();       System.out.println("Enter the checksum that needs to be sent to the receiver ");   ...

Read More

Shortest Subarray with Sum at Least K in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 506 Views

Suppose we have an array A. We have to find the length of the shortest, non-empty, contiguous subarray of A whose sum is at least K. If there is no such subarray, then return -1.So, if the input is like [5, 3, -2, 2, 1] and k = 6, then the output will be 2, as we can see (5+3) >= 6To solve this, we will follow these steps −n := size of Aans := n + 1, j := 0, sum := 0Define one deque dqfor initialize i := 0, when i < n, update (increase i by 1), ...

Read More

Minimum Number of Refueling Stops in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 625 Views

Suppose there is a car, that travels from a starting position to a destination which is t miles east of the starting position.Now along the way, there are many gas stations. So each station[i] represents a gas station that is station[i][0] miles east of the starting position, and that station has station[i][1] liters of gas.If the car starts with an infinite size of gas tank, which initially has startFuel liters of fuel in it. It uses 1 liter of gas per 1 mile that it drives.When the car reaches one gas station, it may stop and refuel, so now it ...

Read More

Third Maximum Number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 501 Views

Suppose we have a non-empty array of integers; we have to find the third maximum number in this array. If there is no 3rd max number, then return the maximum one. The challenge is, we have to solve this using linear time complexity.So, if the input is like [5, 3, 8, 9, 1, 4, 6, 2], then the output will be 6.To solve this, we will follow these steps −initialize a, b, c with NULLfor initialize i := 0, when i < size of nums, update (increase i by 1), do −if a is null or nums[i] >= value of ...

Read More

Initialization of local variable in a conditional block in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 437 Views

Java compiler doesn’t allow abandoning an uninitialized local variable. When a local variable is initialized inside a conditional block, there are 3 possibilities that could potentially occur −Code compiles successfully if values are provided in the conditional block and the given condition is true.Code gives a compilation error if variables are provided (instead of values) in the conditional block and the condition is true.Code gives compilation error if the condition that needs to be checked is false.If the local variable is initialized to a default value outside of the conditional block in the code, it won’t give any error and ...

Read More

Interesting facts about Array assignment in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 249 Views

There are many facts with respect to array assignment, and we will discuss a few of them with working examples here −While creating array object type, the element that would be present inside the array can be declared as type objects or as child class’s object.Examplepublic class Demo{    public static void main(String[] args){       Number[] my_val = new Number[3];       my_val[0] = new Integer(91);       my_val[1] = new Double(65.963);       my_val[2] = new Double(45.7965);       System.out.println(my_val[0]);       System.out.println(my_val[1]);       System.out.println(my_val[2]);    } }Output91 65.963 45.7965A ...

Read More

Profitable Schemes in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 281 Views

Suppose there is a gang with G people and a list of various crimes they could commit. The i-th crime generates a profit value profit[i] and requires group[i] gang members to participate.If a gang member is participating in one crime, that he can't participate in another crime. Now let us define profitable scheme any subset of these crimes that generates at least P profit, and total number of members participating in that subset of crimes is at most G.We have to find how many schemes can be chosen? The answer may be very large, So return it modulo 10^9 + ...

Read More

Number of Segments in a String in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 654 Views

Suppose we have a string s. We have to count the number of segments in a string, where a segment is defined to be a contiguous sequence of characters (no whitespace).So, if the input is like "Hello, I love programming", then the output will be 4, as there are 4 segments.To solve this, we will follow these steps −n := 0for initialize i := 0, when i < size of s, update (increase i by 1), do −if s[i] is not equal to white space, then −(increase n by 1)while (i < size of s and s[i] is not equal ...

Read More
Showing 13451–13460 of 25,466 articles
Advertisements