Found 1919 Articles for Data Structure

Can String be considered as a Keyword?

Shubham Vora
Updated on 05-Oct-2023 12:50:26

70 Views

Keywords are important in any programming language, as they are reserved words with a particular predefined meaning. The keywords are used to define the variables, function, and class, change the program's control flow, traverse the list, etc. When we talk about the 'String', it is a fundamental data type to represent a series of characters. Some programming languages refer to the 'String' as a class, and some programming languages refer to the 'String' as a keyword. In this tutorial, we will explore the use of the 'String' word in the programming language. C/C++ The C or C++ programming languages are ... Read More

Value of k-th index of a series formed by append and insert MEX in middle

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:58:31

32 Views

In this article, we will learn about Mex and will also generate the C++ code that returns the kth index of the series so formed by using append and MEX (>0) operations on the given sequence. The roadmap of the operations to be performed is given below − Start with a sequence containing only the number 1 i.e, [1]. Now, we need to perform (n-1) steps − In each step, we append the current series by itself. For example, if the existing series is [1, 2, 3], after appending, it becomes [1, 2, 3, 1, 2, 3]. Now, find ... Read More

Sum of series (n/1) + (n/2) + (n/3) + (n/4) +……. + (n/n)

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:57:51

97 Views

This this article, we will discuss the different approaches to calculate the sum of the given series. Problem Statement We are given a number and our task is to calculate the sum of the series Σ (n / i) for I =0 to i=n. We are given any given value of n where n can be any number less than 10^12 considering on integer division. For example, if the given input is 10, The sum of given series can be written as (10/1) + (10/2) + (10/3) + (10/4) + (10/5) + (10/6) + (10/7) + (10/8) + ... Read More

Stable sort for descending order

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

93 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

50 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

62 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

66 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

47 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

71 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

44 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

Previous 1 ... 5 6 7 8 9 ... 192 Next
Advertisements