Articles on Trending Technologies

Technical articles with clear explanations and examples

Shortest Subarray with Sum at Least K in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 511 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 627 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 504 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 440 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

Nth Magical Number in C++

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

A number is said to be a magical number, if that number is divisible by A or B. We have to find the Nth magical number. As the answer may very large, we will return it modulo 10^9 + 7.So, if the input is like N = 4, A = 4, B = 3, then the output will be 8To solve this, we will follow these steps −Define a function cnt(), this will take x, A, B,return (x / A) + (x / B) - (x / lcm of A and B)From the main method, do the following −l := 2, r := 1^14, ret := 0while l

Read More

Interesting facts about Array assignment in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 253 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 282 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 663 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

Interesting facts about Increment and Decrement operators in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 283 Views

There are many interesting facts with respect to increment and decrement operators in Java. We will discuss a few of them with examples −The increment and decrement operators can’t be used with the ‘final’ variables. This is due to the fact that variables associated with ‘final’ keyword can’t be changed −Examplepublic class Demo{    public static void main(String[] args){       final int my_val = 34;       int my_val_2 = ++my_val;       System.out.println("The value is :");       System.out.println(my_val_2);    } }Output/Demo.java:6: error: cannot assign a value to final variable my_val int my_val_2 = ...

Read More

Super Egg Drop in C++

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

Suppose we have given K eggs, and we have a building with N floors from 1 to N. Now each egg is identical in function, and if an egg breaks, we cannot drop it again.There exists a floor F with between 0 and N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floor F will not break. In each move, we may take an egg and drop it from any floor X. The X is in range 1 to N.Our goal is to know with certainty what the ...

Read More
Showing 27351–27360 of 61,297 articles
Advertisements