Found 26504 Articles for Server Side Programming

Golang program to find if there exists a pair of numbers in an array that add up to a given target sum using two pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:12:40

513 Views

In this Golang article, we are going to find if there exists a pair of numbers in an array that add up to a given target sum using two pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Using Two Pointer Approach With Iterative Method In this method, we will define a pairWithGivenSum() function using iterative approach that is used to find if there exists a pair of numbers in an array that add up ... Read More

Golang program to find longest subarray with a given sum using two-pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:12:02

332 Views

In this Golang article, we are going to find longest subarray with a given sum using two-pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Using Two-Pointer Approach With Iterative Method In this method, we will define a longestSubarray() function using iterative approach that is used to find longest subarray with a given sum using two-pointer approach. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Start the ... Read More

Golang program to remove duplicates from a sorted array using two-pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:11:30

824 Views

In this Golang article, we are going to remove duplicates from a sorted array using two-pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. A sorted array is an array in which the elements are arranged in a particular order, such as ascending or descending order. Using Two-Pointer Approach With Iterative Method In this method, we will define a duplicatesRemove() function using iterative approach that is used to remove duplicates from a sorted array using ... Read More

Golang program to find the maximum product of two numbers in an array using two pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:10:58

506 Views

In this Golang article, we are going to find the maximum product of two numbers in an array using two pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Using Two Pointer Approach With Iterative Method In this method, we will define a productMax() function using iterative approach that is used to find the maximum product of two numbers in an array using two pointer approach. Algorithm Step 1 − First, we need to ... Read More

Golang program to find if a given subarray exists in a given array using two pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:10:09

497 Views

In this Golang article, we are going to find if a given subarray exists in a given array using two pointer approach with iterative and optimized-iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Syntax func isSubarrayPresent(arr []int, sub []int) bool {…} The isSubarrayPresent() function is used to find if a given subarray exists in a given array using two pointer approach. It takes array and sub-array as its argument. Algorithm Step 1 − First, we need to ... Read More

Golang program to find the depth of a node in a binary search tree

Akhil Sharma
Updated on 03-Apr-2023 13:09:43

618 Views

In this Golang article, we are going to find the depth of a node in a 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. 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. Syntax func (n *Node) Depth(value int) int {…} The Depth() function is used to find the depth of a node in a binary search tree. It takes an ... Read More

Golang program to find intersection of two sorted arrays using two pointer approach

Akhil Sharma
Updated on 03-Apr-2023 13:08:56

492 Views

In this Go language article, we will write programs to find intersection of two arrays using two pointer approach. Intersection means similarity or most common and intersection of two arrays refers to the similar elements between two arrays. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument ... Read More

Golang program to implement depth first search

Akhil Sharma
Updated on 03-Apr-2023 13:07:14

5K+ Views

In this article, we are going to learn how to use internal Golang functions like make, append, and range to implement depth first search. Depth first search is a traversal algorithm used for graph and tree data structures. It explores all the nodes of the graph recursively. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array ... Read More

Golang program to get the individual components of the current date-time

Akhil Sharma
Updated on 03-Apr-2023 13:05:21

233 Views

In this article, we are going to learn how to use various internal time function in Golang that will get the individual components of the current date-time. Now function from the time package will be used to get the current date-time and the individual components of date-time are calculated using the individual components as methods. Syntax func Now() Time The Now() function is defined in time package. This function generates the current local time. To use this function, we have to first import the time package in our program. time.Month() This method belongs to the time package. It ... Read More

Golang program to display time in different country’s format

Akhil Sharma
Updated on 03-Apr-2023 13:01:42

444 Views

In Golang we can use the functions like time.Format() and Now() Time to display the time in different country’s format. Now function from the time package is used to get the current local time and the format function is used to format the time string using different format strings. Syntax time.Format() This function is present in the time package. It takes a layout input string that depicts how the Output string will be formatted. func Now() Time The Now() function is defined in time package. This function generates the current local time. To use this function, we have ... Read More

Advertisements