Found 7346 Articles for C++

Queries to find Kth Greatest Character In A Range [L,R] From A String With Updates

Sakshi Koshta
Updated on 10-May-2023 16:13:37

223 Views

The Fenwick Tree is a type of data structure, which enables range updates and range searches with O(log n) time complexity, also called as binary indexed tree (BIT) The fundamental concept is to keep frequency array for every letter in string, with frequency of i-th character being recorded at index i in frequency array. The frequency array can then allow range updates and range queries using Fenwick Tree. Problem Approach You can use following queries to extract Kth biggest character from string with updates in range [L, R] − Build segment tree − Create segment tree first, in which ... Read More

Queries to count array elements greater than or equal to given number with updates

Sakshi Koshta
Updated on 10-May-2023 16:09:32

465 Views

An array can be successfully updated and put through to range queries thanks to segment trees. With updates, we can use data structure known segment tree to count no. of elements in Array which are larger than or same as no. Query − Find out how many items exist in [l, r] range that are larger than or similar to x. Give 0 if range [l, r] lies entirely beyond segment that current node of segment tree represents. Count no. of elements in range [l, r] which is larger than or similar to x if interval [l, r] ... Read More

Array Range Queries to find the Maximum Armstrong number with updates

Tapas Kumar Ghosh
Updated on 10-May-2023 15:11:27

315 Views

The Array range queries are a new interest of data structure. In this query, we have set the random element to the array and given the general query problem to solve the data structure problem efficiently. Armstrong number is the total of its digits' cubes. For example- 0, 1, 153, 370, 371, and 407 are Armstrong numbers. Let’s take an example to understand the Armstrong number Example 1 − The given number is 371 and check whether the number is Armstrong or not. 3*3*3 + 7*7*7 + 1*1*1 = 371 Hence, this is Armstrong number. Example 2 − The given ... Read More

Count of element in an array whose set bits are in a multiple of K

Tapas Kumar Ghosh
Updated on 10-May-2023 15:39:16

262 Views

The set bit is a binary representation form of 0 and 1. This digit 1 is called a set bit in reference to the computer. Let’s take an example to understand the setbit calculation − Let’s take an example to understand the setbit calculation − The set bit calculation of integer 96 is Let’s say we want to set the bit to sum of 96. So as shown in the above representation, we will set bit 1 to those array elements whose total will be 96. This way we will form 2 sets of bit. Therefore, if we take ... Read More

Design a queue data structure to get minimum or maximum in O(1) time

Tapas Kumar Ghosh
Updated on 10-May-2023 14:22:41

594 Views

C++ has a deque header file that handles the properties of stack and queue. In data structure for solving the problem in O(1) time complexity, it requires constant time. By using deque to this program we get the advantage to use both stack and queue. In this article, we are going to solve the queue data structure to get the minimum or maximum of a number in O(1) time. Syntax deque name_of_queue; Parameters deque − This is known for the double-ended queue that ordered a group of items or numbers equivalent to the queue. data_type − The type ... Read More

Check if given words are present in a string

Tapas Kumar Ghosh
Updated on 10-May-2023 14:20:57

698 Views

C++ has a predefined function find() which enables searching from the first element range until the last element. In this article, we are going to understand how we can use this find() function to check if a given word is present in a string or not. Let’s take an example of this. The given string is “John and mark have same color of t-shirt”; For searching the word in a string we will make a variable that is denoted as a search finder. Let’s take two variables and check if the given words are present or not. Var1 = ... Read More

Proof that the Dominant Set of a Graph is NP-Complete

Tapas Kumar Ghosh
Updated on 10-May-2023 14:15:12

349 Views

A Dominant set of a graph is NP-complete is the subset of vertices such that every vertex in the subset or adjacent vertex in the subset. The full form of NP is “Nondeterministic polynomial” which will check the problem in polynomial time and it means that we can check whether the solution is correct or not in polynomial time. The polynomial time has the best complexity to the code like the time complexity of linear search – n, Binary search – logn, Merge sort- n(log)n, etc. The NP-complete graph provides a good solution in a reasonable amount of time. This ... Read More

Find array sum using Bitwise OR after splitting given array in two halves after K circular shift

Tapas Kumar Ghosh
Updated on 10-May-2023 14:06:25

108 Views

In C++ splitting an array mean dividing the array into more than one subarray. The Bitwise OR is used to handle the comparison and calculation between two bits or indexes in C++. In this article, we use k circular shift which means the last index position will be shifted to zero index position i.e, the first array element according to k-th times. Let’s take an example to understand the circular shift into the array. The given array is 1, 2, 3, 4, 5, 6, 7 and has a length of 6. Now we will assign the value 3 to k ... Read More

Check if product of Array elements in given range are M-th root or not

Tapas Kumar Ghosh
Updated on 10-May-2023 13:54:11

121 Views

M-th root is defined as the cube of any number and array ranges mean to count the indexes from first to end. We will take three numbers in the array range as input and see if their product value comes in the form of a cube value then it will be the 'M-th' root of the number. Let’s take an example to understand the product range of an array and calculate the M-th root of the number. Example 1 Given array integer is 9, 8, 3, 1 Now we see the product range of array 9*8*3*1 is 216. Therefore, 216 ... Read More

Check if it is possible to reach the index with value K when start index is given

Tapas Kumar Ghosh
Updated on 10-May-2023 13:32:57

85 Views

C++ has a bitwise operator “||” to check multiple conditions at once and for finding the length of an array we use the size() function. In the given problem statement, we need to reach the K-th value which sets to 0 in the array range, and the starting index is already known. If the given index satisfies to K-th value in the array range then it will print that “We can reach the value k from the given start index”. Let’s take an example of this − Given integer array is 5, 6, 0, 9, 10 having a length of ... Read More

Advertisements