Found 7347 Articles for C++

deque_crend in C++ in STL

Sunidhi Bansal
Updated on 28-Feb-2020 05:29:25

79 Views

Given is the task to show the functionality of Deque crend( ) function in C++ STLWhat is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in Double ended queue the ... Read More

deque_emplace in C++ in STL

Sunidhi Bansal
Updated on 28-Feb-2020 05:23:51

102 Views

Given is the task to show the functionality of Deque emplace( ) function in C++ STLWhat is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in Double ended queue the ... Read More

Max Chunks To Make Sorted in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:26:16

375 Views

Suppose we gave an array arr that is a permutation of [0, 1, ..., arr.length - 1], we have to split the array into some number of "chunks" or partitions, and individually sort each partition. So after concatenating them, the result will be the sorted array. So if the array is like [1, 0, 2, 3, 4], then the output will be 4, as we can split into two partitions like [1, 0] and [2, 3, 4], but this can also be true that [1, 0], [2], [3], [4]. So this is the highest number of chunks possible, so output ... Read More

Partition Labels in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:23:37

284 Views

Suppose we have a string S of lowercase letters is given. We will partition this string into as many parts as possible so that each letter appears in at most one part, finally return a list of integers representing the size of these parts. So if the string is like “ababcbacadefegdehijhklij”, output is [9, 7, 8], because the partitions are “ababcbaca”, “defegde”, “hijhklij”. So this is a partition so that each letter occurs in at most one part. A partition like "ababcbacadefegde", "hijhklij" is not correct, because it splits S into less parts.To solve this, we will follow these steps ... Read More

Daily Temperatures in Python

Arnab Chakraborty
Updated on 29-Apr-2020 08:20:55

773 Views

Suppose we have a list of daily temperatures T, we have to return a list such that, for each day in the input, shows how many days we would have to wait until a warmer temperature. If there is no future day for which this is possible, store 0 instead. For example, if T = [73, 74, 75, 71, 69, 72, 76, 73], output will be [1, 1, 4, 2, 1, 1, 0, 0].To solve this, we will follow these steps −ans := an array of size same as T, and fill this with 0define one stack, and insert 0 ... Read More

Subarray Product Less Than K in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:17:39

279 Views

Suppose we have given an array of positive integers nums. We have to count and print the number of (contiguous) subarrays where the product of each the elements in the subarray is less than k. So if the input is like [10,5,2,6] and k := 100, then the output will be 8. So the subarrays will be [[10], [5], [2], [6], [10, 5], [5, 2], [2, 6] and [5, 2, 6]]To solve this, we will follow these steps −temp := 1, j := 0 and ans := 0for i in range 0 to size of the arraytemp := temp * nums[i]while temp >= k and j = k && j

Minimum ASCII Delete Sum for Two Strings in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:12:07

386 Views

Suppose we have two words w1 and w2, we have to find the lowest ASCII sum of deleted characters to make w1 and w2 the same, where in each step we can delete one character in either string. So if the input is like “sea” and “eat”, then the output will be 231, because we need to delete ‘s’ from w1, this will be “ea” and delete “t” from “eat” from w2. Then they are same. Deleting ‘t’ from “eat” adds 116 to the sum, and at the end, both strings are the same and 115 + 116 = 231 ... Read More

Insert into a Binary Search Tree in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:08:57

7K+ Views

Suppose we have a binary search tree. we have to write only one method, that performs the insertion operation with a node given as a parameter. We have to keep in mind that after the operation, the tree will remain BST also. So if the tree is like −if we insert 5, then the tree will be −To solve this, we will follow these steps −This method is recursive. this is called insert(), this takes a value v.if root is null, then create a node with given value v and make that as rootif value of root > v, thenleft ... Read More

Partition to K Equal Sum Subsets in C++

Arnab Chakraborty
Updated on 29-Apr-2020 07:59:22

330 Views

Suppose we have an array of integers called nums and a positive integer k, check whether it's possible to divide this array into k non-empty subsets whose sums are all same. So if the array is like [4, 3, 2, 3, 5, 2, 1] and k = 4, then the result will be True, as the given array can be divided into four subarray like [[5], [1, 4], [2, 3], [2, 3]] with equal sums.To solve this, we will follow these steps −define two table called dp and total of size 2^n, sort the given array nums, set sum := ... Read More

Top K Frequent Words in C++

Arnab Chakraborty
Updated on 29-Apr-2020 07:52:40

468 Views

Suppose we have a non-empty list of words; we have to find the k most frequent elements. our answer should be sorted by frequency from highest to lowest. When two words have the same frequency, then the word with the lower alphabetical order will be placed at first. So if the array is like [‘the’, ‘sky’, ‘is’, ‘blue’, ‘the’, ‘weather’, ‘is’, ‘comfortable’], so most frequent words are ["is", "the", "blue"]To solve this, we will follow these steps −Define one map called mcreate one priority queue vfor i := 0 to n, where n is the size of the word array, ... Read More

Advertisements