Prabhdeep Singh

Prabhdeep Singh

161 Articles Published

Articles by Prabhdeep Singh

Page 11 of 17

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 191 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
Prabhdeep Singh
Updated on 24-Aug-2023 727 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 192 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 396 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 239 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 386 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

Distance of each node of a Binary Tree from the root node using BFS

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

Binary Tree is a non-linear data structure. It has a maximum of two children and each node contain three things that are data value, left and right pointer. The top node is called the root node and the last node which does contain any children is called the leave node. In this problem, we have given a binary tree. It has N nodes in the range from 1 to N (both inclusive) and our task is to find the distance of each node of a binary tree from the root node using BFS. Examples Let's see examples with explanations below ...

Read More

Find the Largest and smallest number in an Array containing small as well as large numbers

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

We are given an array of strings and each string represents a number that could be more than the range of the maximum integer limit. We have to find the largest and the smallest element from the given array. We cannot use the simple less than or greater than operators to check which string is greater as it won't works find with the string so we will make our own comparison function. Example Let's understand the problem with the help of an example − Input string arr[] = {"2", "3", "12", "23", "22", "0", "7"} Output The smallest element ...

Read More

Longest Substring containing C2, starting with C1 and ending with C3

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

A substring is a string that can be achieved from the given string by removing some characters from the beginning and end of the string (possibly none or all). We are given a string and three characters and have to find the longest substring that contains all the three given characters in the sequence of c1, c2, and c3 starting with c1 and ending with c3. Also, the given characters may be the same but we string must contain different characters for each of them. Input string str = "abacdeab" char c1 = a char c2 = b char ...

Read More
Showing 101–110 of 161 articles
« Prev 1 9 10 11 12 13 17 Next »
Advertisements