Prabhdeep Singh

Prabhdeep Singh

161 Articles Published

Articles by Prabhdeep Singh

Page 4 of 17

Minimize cost by splitting the given Array into subsets of size K and adding the highest K/2 elements of each subset into the cost

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 281 Views

Splitting the array means we have to divide the array and make subsets. Here in this problem, we have given an array of integers with size n and integer k and our goal is to calculate the lowest cost by splitting the whole given array into the subsets of size k and adding the highest k/2 element of each subset into the cost. NOTE: here we consider a ceiling of k/2. Let’s see examples with explanations below to understand the problem in a better way. Sample Example Input n: 4 array: [ 3, 4, 2, 1 ...

Read More

Calculate server loads using Round Robin Scheduling

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 981 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
Prabhdeep Singh
Updated on 24-Aug-2023 142 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

Dumping queue into list or array in Python

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 583 Views

A queue is a linear data structure that works on the FIFO property where each element is added to the queue from the rear and the elements are extracted from the front and use the principle of first in first out. In the list, we can access every element while in the queue we can only access the first element. In this tutorial, we are going to see two methods of how to convert a queue into the list. Creating a Queue in Python Queue in a linear data structure which works on the first in first out property and ...

Read More

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

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 678 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
Prabhdeep Singh
Updated on 24-Aug-2023 160 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

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

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 339 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
Prabhdeep Singh
Updated on 24-Aug-2023 206 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

Maximize product of array by replacing array elements with its sum or product with element from another array

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 308 Views

We are given two arrays of the same length and we have to apply some operations to get the product of the first array with all elements maximum. The operations are to multiply or add any element of the second array only once to any element of the first array only once. We can add or multiply two different elements from the second array element to a single first array element. After all operations, we have to take the product of all the elements of the first array and return that. Example Let's understand the problem with the help of ...

Read More

Difference between Queue and Deque in C++

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 2K+ Views

Queue and Deque both are linear data structures that are defined in STL of C++ programming language. Queue works on the principle of the first in first out, the element added to the queue first will be removed first, on the other hand, deque has properties to add an element either at the first index or last index, and similarly, any one of them can be removed. We will see the code of both data structures to get the exact differences. Basics of Queue As we have seen above, the queue is based on the concept of the first in ...

Read More
Showing 31–40 of 161 articles
« Prev 1 2 3 4 5 6 17 Next »
Advertisements