Overview The objective is to find the majority element in a given array. A majority element is an element that occurs more than n/2 times in a given array where n is…
Tag: go
Program for Binary Search in a sorted array in Go (Golang)
Overview Idea is to do a binary search of a given target element in an input array. If the target element is present then output the index. If the output element is…
Longest Common Prefix in a set of strings in Go (Golang)
Overview An array of strings is given. The objective is to find the longest common prefix from that array of strings. It should output an empty string if there is no common…
Maximum Length of Contiguous Subarray with an equal number of 0’s and 1’s in Go (Golang)
Overview An array is given that only has 0’s and 1’s. The objective is to find a maximum length subarray with an equal number of 0’s and 1’s. Let’s understand it with…
Maximum Difference between increasing elements in an array in Go (Golang)
Overview An array is given. The objective is to find the maximum difference between values at two indexes i and j such that j > i arr[j] > arr[i] If no such…
Two furthest houses with different colors in Go (Golang)
Overview An array is given which represents the color of houses. So array[i] represents the color of the house at index i. The objective is to find two furthest houses with different…
Non-Overlapping intervals program in Go (Golang)
Overview An array of intervals is given where intervals[i] = [starti, endi]. We have to find out the minimum number of intervals to remove so that the interval in the intervals array…
Kth Distinct String in an Array Program in Go (Golang)
Overview An input string array is given which can have duplicate strings as well. An input number k is also provided. Idea is to find the first kth distinct string in the…
Program for House Robber Problem in Go (Golang)
Overview There are a couple of houses in the neighborhood. Each house has some money in it. The houses are represented as an array which each entry in the array denotes the…
Distinct or Unique Permutations of a string or array in Go (Golang)
Overview Given an array of integers that can contain duplicate elements, find all distinct permutations only. Example Program Here is the program for the same. Output Note: Check out our Golang Advanced…