Found 34494 Articles for Programming

Stable sort for descending order

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:55:41

138 Views

In this article, we will discuss what is meant by stable sorting and how can we sort an array in descending order keeping in mind that the sorting algorithm should be stable. Let us first discuss about what are the features of a stable sort algorithm − A sorting algorithm is called stable if it keeps the original order of items with the same value in the input data when they are sorted. So, if there are two or more items with the same value, a stable sorting algorithm will not change their relative positions in the sorted output. Stable ... Read More

Ropes left after every removal of smallest rope

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:49:33

68 Views

In this article, we will discuss two approaches to solve the problem - Ropes left after every removal of smallest rope. Problem Statement We are given an array of elements where array [i] denotes the length of the ith rope in the array. Our task is to cut a length equal to the smallest element of the array from all the elements of the array until we have all the elements length equal to zero. We have to output the number of ropes with non-zero lengths after each cut operation. Let us consider an example for the same − Let ... Read More

Minimum sum of multiplications of n numbers

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:46:23

76 Views

In this article, we will discuss two approaches to generate the desired sum. Both the approaches are dynamic programming-based approaches. In the first approach, we will memorization for dynamic programming and then we will apply the same approach for tabulation in order to avoid the use of extra stack space for recursion. Problem Statement We are given a list of n integers, and our goal is to minimize the sum of multiplications by repeatedly taking two adjacent numbers, summing them modulo 100, and replacing them in the list until only one number remains. Let's consider the input [30, 40, 50] ... Read More

Minimum number of subtract operation to make an array decreasing

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:44:55

101 Views

In this article, we will work upon sorting an array in decreasing order by applying some subtraction operations on it. Problem Statement We are given an array containing a series of n numbers from array[0], array[1], . . . . , array[ n-1 ]. We are also given an integer nums. Our task is to generate a decreasing array by subtracting nums from the array elements in every operation. We need to return the least possible number of such operations required in order to make the array decreasing in order. Let us understand the problem with an example − ... Read More

Maximum in array which is at-least twice of other elements

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:42:11

60 Views

In this article, we will discuss different approaches to point out the greatest element in the array which is at least twice of all the other elements in the same array. Problem Statement An array of n different elements is given to us, we have to find out the maximum element in the given array "nums" such that it is either greater than or equal to twice of all the other elements in that array. In other words, we can also say the we have to find out whether or not all the other elements of the given array are ... Read More

Largest number that is not a perfect square

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:34:32

94 Views

In this article, we will discuss two different approaches to find out the largest number smaller than a given number which is not a perfect square. In the first approach, we will run a loop to check for every number until we find the desired number while in the second approach, we will use the concept of square root to generate the perfect square number just smaller than the given number and based on this, we will find out the largest number smaller than "nums" which is not a perfect square. Let us first understand the problem statement. Problem Statement ... Read More

k smallest elements in same order using O(1) extra space

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:32:10

61 Views

We have an array "nums" consisting of "size" elements and an integer "number" denoting the number of smallest elements we have to return. Our task is to find out the "number" smallest elements from the given array. The order of the elements should be preserved and we are not allowed to use any extra variable space for the solution i.e., the space complexity of the solution should be O(1). Let us understand this using an example, nums = { 4, 2, 6, 5, 1 } The solution should return 4, 2, 5 as they are the smallest 3 ... Read More

Fibonomial coefficient and Fibonomial triangle

Vaishnavi Tripathi
Updated on 09-Feb-2024 17:14:59

63 Views

In this article, we will discuss about a special type of number called fibonomial coefficient and how does a fibonomial triangle looks like. We will also discuss the C++ code approach to print a fibonomial triangle with a given height. Let us first discuss that what is a fibonomial coefficient. Fibonomial Coefficient We can call a fibonomial coefficient a generalisation of well known terms namely , Fibonacci numbers and binomial coefficients. The Fibonacci numbers are a series of numbers in which, each number is the sum of the two preceding numbers (for example − 0, 1, 1, 2, 3, 5, ... Read More

Factorial of each element in Fibonacci series

Vaishnavi Tripathi
Updated on 09-Feb-2024 16:31:32

254 Views

In this article, we will discuss a simple program which calculates the factorial of all the numbers present in the Fibonacci series smaller than a given nums. Problem Statement We are given a number and our task is to generate the factorial of all the numbers present in the Fibonacci series and smaller than the given number. Let us first understand the problem statement and requirements from the code solution with the help of examples. Input nums = 13 Output Fibonacci series up to 13 is 0, 1, 1, 2, 3, 5, So, the factorial ... Read More

Java notify() Method in Threads Synchronization with Examples

Bamdeb Ghosh
Updated on 04-Oct-2023 18:42:37

187 Views

Introduction The Object class contains a definition for the notify () method. Only one thread that is waiting for an item is wakes up by it and that thread then starts to run. A single thread can be awakened using the notify () method of the thread class. When using the notify () method while several threads are waiting for a notice, only one thread will actually get the notification and forces the others to continue waiting. Let us discuss the Java notify () method in Threads Synchronization, along with its usage and programming examples. We will look into how ... Read More

Advertisements