Found 7346 Articles for C++

Find first undeleted integer from K to N in given unconnected Graph after Performing Q queries

Pranavnath
Updated on 25-Aug-2023 11:06:44

37 Views

Introduction Finding the primary undeleted integer from a given extend in a detached graph after performing multiple queries may be a challenging issue in graph theory. In this article, we investigate the errand of distinguishing the primary undeleted numbers and give two approaches to fathom it utilizing C++. Each approach offers a diverse point of view and utilizes distinctive calculations and data structures. The problem includes developing a graph, checking certain nodes as deleted, and after that deciding the primary undeleted numbers inside an indicated extend. The graph represents associations between nodes, and the deleted nodes are those that have ... Read More

Calculate server loads using Round Robin Scheduling

Prabhdeep Singh
Updated on 24-Aug-2023 15:57:59

452 Views

Round robins scheduling is used in CPU scheduling, we are given some M number of servers and N number of requests. Each request has some arrival time and processing time. We have to find the load on each server using the Round-Robin Scheduling for which we are going to implement a program in C++ programming language using the priority queue and sets. Example Let's understand the problem with the help of an input-output example − Input int arrival_time[] = { 1, 2, 4, 6 }; int process_time[] = { 6, 1, 2, 2 }; int servers = 2; Output ... Read More

Generate Linked List consisting of maximum difference of squares of pairs of nodes from given Linked List

Prabhdeep Singh
Updated on 24-Aug-2023 15:56:44

37 Views

A linked list is a linear data structure that consists of nodes and each node is not present in the contiguous form in the main memory, instead, each node contains the address of the next node. We are given a linked list of even length, we have to create a new linked list that contains half number of nodes as the given node, and the value of each node contains the difference between the square of the nodes of the given linked list in decreasing order. Example Let's understand the problem with the help of an input-output example − ... Read More

K-th Smallest Element in an Unsorted Array using Priority Queue

Prabhdeep Singh
Updated on 24-Aug-2023 15:53:20

250 Views

A priority queue is a heap-based data structure, stores elements in such a way that the greatest or smallest element always be present on the top. We are given an array that is unsorted and we have to find the Kth smallest element from it using the Priority Queue. Here, the element k will be given and it must be in the range from 1 to the size of the given array. Example Let's understand the problem with the help of an input-output example − Input int arr[] = {1, 5, 6, 2, 3, 6, 7, 9, 12, 15, 0, ... Read More

Find the winner of game of repeatedly removing the first character to empty given string

Prabhdeep Singh
Updated on 24-Aug-2023 15:51:29

56 Views

In this game, we are given an array of strings of length N. Each string consists of the digits 1 to N only. The game starts with the first person and removes the first character of the 0th index, then the removed character from the string digit number player will go for the next move. Each player with index y will remove the digit from the string from index y-1 and then the remove digit number player will move next. When any player is not able to remove the character will win the game. Example Let's understand the problem with ... Read More

Encode given String by inserting in Matrix column-wise and printing it row-wise

Shubham Vora
Updated on 24-Aug-2023 16:42:49

84 Views

In this problem, we will encode the string by inserting it in the matrix in a column-wise manner and printing the string in a row-wise manner. The naïve approach to solve the problem is to create a matrix, fill the matrix top-bottom manner, and print the string row-wise. The second solution is to use the vector to store the string and print each vector value individually. Here, we will learn both approaches to solve the problem. Problem statement – We have given string str of length N. Also, we have given the positive integer rows. The task is to encode ... Read More

Difference between concatenation of strings using (str += s) and (str = str + s)

Shubham Vora
Updated on 24-Aug-2023 16:40:30

77 Views

In this tutorial, we will learn the difference between the concatenation of string using the ‘+=’ or ‘+’ operator. Both operators are used to merge strings, but we learn some differences below with examples. What is Addition Assignment (+=) operator? The addition assignment (+=) operator concatenates the two strings. It takes two operands. The left operand is the original string, and the right operand is a string we need to concatenate with the original string. Generally, we use the ‘+=’ operator when we require to concatenate only two strings. Syntax Users can follow the syntax below to use the addition ... Read More

Decrypt the encoded string with help of Matrix as per given encryption decryption technique

Shubham Vora
Updated on 24-Aug-2023 16:35:44

97 Views

In this problem, we need to decrypt the given ciphertext by traversing the matrix diagonally. We can solve the problem by traversing the matrix diagonally. Also, we require to traverse only the upper part of the matrix diagonally to get the decrypted string. Problem statement – We have given an encrypted string of length N and row counts. We need to put the string in the matrix in a row-wise manner. After that, we need to traverse the matrix diagonally, starting from the [0, 0] index to decrypt the string. Sample examples Input str = "TRSI_ _ _UIPN _ ... Read More

Count levels in a Binary Tree consisting of nodes valued 1 grouped together

Prabhdeep Singh
Updated on 24-Aug-2023 15:47:42

102 Views

A binary tree is a tree where each node has a maximum of two children. We are given a binary tree that consists of only 0 and 1 as the node values. We have to find the number of levels of the binary tree that consists of at least one 1 and all the ones of that level must be present consecutively. Example Let's understand with the help of an example − Input 0 / \ 1 0 / ... Read More

Minimize cost to convert all characters of a binary string to 0s

Prabhdeep Singh
Updated on 24-Aug-2023 14:29:16

72 Views

A binary string is a string that only contains the binary numbers in it. In this problem, we are given a binary string, an array that represents the last index up to which we can flip the ones after starting from the ith index which will cost and cost for each index is given in another cost array. We have to perform some number of operations on the string to make the string completely zero. Example Let's understand the problem with the help of an example − Input string str = "101011" int arr[] = {1, 2, 2, 4, 5, ... Read More

Advertisements