Server Side Programming Articles - Page 1866 of 2650

list_empty( ) and list_size( )in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 09:37:38

233 Views

In this article we will be discussing the working, syntax and examples of list::empty() and list::size() function in C++ STL.What is List in STL?List are containers that allow constant time insertion and deletion anywhere in sequence. List are implemented as doubly linked lists. List allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is list::empty( ... Read More

deque_max_size( ) in C++ in STL

Sunidhi Bansal
Updated on 05-Mar-2020 09:34:01

291 Views

Given is the task to show the functionality of deque max_size( ) function in C++ STL.What 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

list swap( ) in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 09:31:30

613 Views

Given is the task to show the functionality list swap( ) function in C++ in STL.What is List in STL?List are containers that allow constant time insertion and deletion anywhere in sequence. List are implemented as doubly linked lists. List allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is swap( )?This function is used ... Read More

Search Suggestions System in C++

Arnab Chakraborty
Updated on 02-May-2020 11:12:02

399 Views

Suppose we have an array of strings products and a string called searchWord. We want to design a module that suggests at most three product names from products list after each character of searchWord is typed. The suggested products should have common prefix with the searchWord. When there are more than three products with a common prefix return the three lexicographically minimums products. So we have to find the lists of the suggested products after each character of searchWord is typed.If the input is like: [ "mobile", "mouse", "moneypot", "monitor", "mousepad"], and the searchWord is “mouse”, then the output will ... Read More

Find Elements in a Contaminated Binary Tree in C++

Arnab Chakraborty
Updated on 02-May-2020 11:10:42

217 Views

Suppose we have a binary tree. The rules of that tree is as follows −root.val == 0If treeNode.val is x and treeNode.left is not null, then treeNode.left.val = 2 * x + 1If treeNode.val is x and treeNode.right is not null, then treeNode.right.val = 2 * x + 2Now as the binary tree is contaminated. This indicates all val of the tree node have been changed to -1. We have to first recover the binary tree and then implement the FindElements class as follows −FindElements(TreeNode* root) Initializes the object with a contamined binary tree, we have to recover it first.bool ... Read More

Number of Closed Islands in C++

Arnab Chakraborty
Updated on 02-May-2020 11:05:44

300 Views

Suppose we have a 2D grid consists of 0s (as land) and 1s (as water). An island is a maximal 4- directionally connected group of 0s. A closed island is an island totally surrounded by 1s. We have to find the number of closed islands. So if the grid is like1111111010000110101011101000010111111110So the output will be 2. There are two islands, that are completely surrounded by water.To solve this, we will follow these steps −Define a variable flagDefine a method called dfs, this will take the grid, i, j, n and mif i and j are not inside the range of ... Read More

Minimum Remove to Make Valid Parentheses in C++

Arnab Chakraborty
Updated on 02-May-2020 11:07:25

455 Views

Suppose we have a string s of '(' , ')' and lowercase English characters. We have to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parenthese string is valid and return any valid string. A parentheses string is valid when all of these criteria are fulfilled −It is the empty string, contains lowercase characters only, orIt can be written as the form of AB (A concatenated with B), where A and B are valid strings, orIt can be written as the form of (A), where A is a valid string.So ... Read More

Minimum Cost Tree From Leaf Values in Python

Arnab Chakraborty
Updated on 05-Mar-2020 07:33:55

449 Views

Suppose we have an array arr of positive integers, consider all binary trees such that −Each node has either 0 or 2 children;The values of arr array correspond to the values of each leaf in an inorder traversal of the tree.The value of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree respectively.Among all possible binary trees considered, we have to find the smallest possible sum of the values of each non-leaf node. So if the input arr is [6, 2, 4], then the output will be 32, as there ... Read More

Maximum Nesting Depth of Two Valid Parentheses Strings in Python

Arnab Chakraborty
Updated on 02-May-2020 11:03:09

333 Views

Suppose we have a string, that string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and it satisfies these properties −It is the empty string, orIt can be written as AB, where A and B are VPS's, orIt can be written as (A), where A is a VPS.We can also define the nesting depth depth(S) of any VPS S like below −depth("") = 0depth(A + B) = max of depth(A), depth(B), where A and B are VPS'sdepth("(" + A + ")") = 1 + depth(A), where A is a ... Read More

Delete Nodes And Return Forest in Python

Arnab Chakraborty
Updated on 05-Mar-2020 07:26:02

275 Views

Suppose we have the root of a binary tree, each node in the tree has a unique value. After removing all nodes with a value in to_delete, we are left with a forest. We have to find the roots of the trees in the remaining forest. So if the input is likeif the to_delete array is like [3, 5], then the output will beTo solve this, we will follow these steps −Define an array resDefine a method solve(), this will take node, to_delete array and a Boolean type info to which is telling that the node is root or not. ... Read More

Advertisements