Found 33676 Articles for Programming

Sum of Indices of Characters Removed to Obtain an Empty String Based On Given Conditions

Sakshi Koshta
Updated on 10-May-2023 16:16:46

165 Views

String manipulation-related concepts like The Sum of indices of Characters deleted to obtain an Empty String are frequently utilized in programming challenges and competitions. The result is then computed using the sum of the eliminated characters' indexes. The Sum of indices of Characters deleted to obtain an Empty String is a practical idea in string manipulation that may be used to solve a variety of programming difficulties and challenges. Problem Approach We must first comprehend the problem statement and given criteria to find total of character indices eliminated to produce empty string. Given string S, the objective is to determine ... Read More

Queries to find Kth Greatest Character In A Range [L,R] From A String With Updates

Sakshi Koshta
Updated on 10-May-2023 16:13:37

348 Views

The Fenwick Tree is a type of data structure, which enables range updates and range searches with O(log n) time complexity, also called as binary indexed tree (BIT) The fundamental concept is to keep frequency array for every letter in string, with frequency of i-th character being recorded at index i in frequency array. The frequency array can then allow range updates and range queries using Fenwick Tree. Problem Approach You can use following queries to extract Kth biggest character from string with updates in range [L, R] − Build segment tree − Create segment tree first, in which ... Read More

Queries to count array elements greater than or equal to given number with updates

Sakshi Koshta
Updated on 10-May-2023 16:09:32

744 Views

An array can be successfully updated and put through to range queries thanks to segment trees. With updates, we can use data structure known segment tree to count no. of elements in Array which are larger than or same as no. Query − Find out how many items exist in [l, r] range that are larger than or similar to x. Give 0 if range [l, r] lies entirely beyond segment that current node of segment tree represents. Count no. of elements in range [l, r] which is larger than or similar to x if interval [l, r] ... Read More

Golang program to find minimum value in a stack

Akhil Sharma
Updated on 10-May-2023 12:46:25

312 Views

In Golang, we can find minimum value in a stack by using iterative method and optimized iterative method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Syntax func (s *Stack) getMin() int {…} The getMin() function is used to find the minimum value in a stack. It takes a address pointer to the stack as its argument. Algorithm Step 1 − First, we need to import the fmtpackage. Step 2 − Create a stack structure with an item slice to store the stack elements and a min slice to store the minimum ... Read More

Golang program to find floor and ceil in binary search tree

Akhil Sharma
Updated on 10-May-2023 12:44:21

241 Views

A binary search tree (BST) is a type of binary tree where every node has at most two children, commonly referred to as the left child and the right child. In this Golang article, we will learn how to find floor and ceil in binary search tree using recursion and iterative method. The binary search tree is a useful data structure for efficient searching, insertion, and deletion of elements. Syntax func ceil(root *Node, val int) int {…} The ceil() function is used to find the ceil value in the binary search tree. func floor(root *Node, val int) int {…} ... Read More

Golang program to reorder list using recursion

Akhil Sharma
Updated on 10-May-2023 12:43:12

207 Views

A linked list is a data structure consisting of a collection of nodes, where each node contains a value and a pointer to the next node in the list. In this Golang article, we will learn how to reorder list using recursion along with some helper functions. Syntax func reorderList(head *Node) {…} The reorderList() function is used to reorder list using recursion. It takes pointer to the head node as its argument. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, create a struct of a single node of the ... Read More

Golang program to find the diameter of a tree

Akhil Sharma
Updated on 10-May-2023 12:41:07

315 Views

In this Golang article, we are going to find the diameter of a tree by using recursion and iterative method. The diameter of a tree is the number of nodes on the longest path between any two leaves in the tree. Syntax func diameter(root *node) int{…} The diameter() function is used to find the diameter of a tree. It takes pointer to the root node as its argument. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, create a struct of a single node of the tree named, node. It contains ... Read More

Golang program to delete duplicate value nodes from a sorted linked list

Akhil Sharma
Updated on 10-May-2023 12:39:48

392 Views

In this Golang article, we are going to delete duplicate value nodes from a sorted linked list by using recursion and iterative method. A linked list is a data structure consisting of a collection of nodes, where each node contains a value and a pointer to the next node in the list. Syntax func deleteDuplicates(head *Node) *Node{…} The deleteDuplicates() function is used to delete duplicate value nodes from a sorted linked list. It takes pointer to the head node as its argument. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, ... Read More

Golang program to print left pascals triangle

Akhil Sharma
Updated on 10-May-2023 12:36:56

269 Views

In this Golang article, we will learn how to print left Pascal’s triangle by using recursion and iterative method. Pascal's triangle is a triangular array of binomial coefficients. The left pascal's triangle is a variant of Pascal's triangle that is obtained by reflecting Pascal's triangle along a vertical axis. Syntax func leftPascal(n, k int) int{…} The leftPascal() function is used to print left Pascal’s triangle. It takes two arguments as input. func leftPascal(n int){…} The leftPascal() function is used to print left Pascal’s triangle. It takes one argument, number of rows as input. Algorithm Step 1 − ... Read More

Golang program to find maximum element in array using linear search

Akhil Sharma
Updated on 10-May-2023 12:17:27

2K+ Views

In this Golang article, we will learn how to find maximum element in array using linear search by using recursion and iterative method. Syntax func findMax(arr []int) int {…} The findMax() function is used to find maximum element in array using linear search iteratively. It takes an integer array as argument to it. func findMax(arr []int, n int) int {…} The findMax() function is used to find maximum element in array using linear search recursively. It takes an integer array and the size of the array as arguments to it. Algorithm Step 1 − First, ... Read More

Advertisements