Overview The objective is to add two given binary numbers. Binary numbers are only composed of digits 0 and 1. Below is the binary addition logic for individual digits 0+0 = Sum…
Tag: go
Jump Game Program in Go (Golang)
Overview There is an input array provided. Each entry in the array represents the maximum jump length from that position. One is supposed to start from the first index and return true…
Convert a sorted linked list to balanced BST
Overview The objective is to convert a sorted linked list to a balanced BST. A balanced BST is a BST in which the depth of the two subtrees of every node never…
Construct a binary tree from preorder and inorder in Go (Golang)
Overview Two arrays are given which represent the preorder and inorder traversal of a binary tree. The objective is to construct a binary tree from them Example: Consider below tree Preorder traversal…
Height or maximum depth of a binary tree in Go (Golang)
Overview The objective is to get the height of a binary tree. For example, if let’s say we have below binary tree Then the height of the binary tree is 3 here….
Level Order Traversal of a binary tree in Go (Golang)
Overview The objective is to print the binary tree level by level. For example, if let’s say we have below binary tree Here we have Node 1 on level 1 Node 2…
Check if a given tree is a Binary Search Tree in Go (Golang)
Overview We can use the below strategy to know if a given tree is a BST. For a given current node, if the left and right subtree are BST The maximum value…
Interleaving String Program in Go (Golang)
Overview Three strings are given s1, s2, s3. Find if string s3 is interleaving of string. s3 will be an interleaving of string s1 and s2 if the below condition is satisfied…
Sort an array of 0, 1, and 2 in Go (Golang)
Overview The objective is to sort an array of 0,1 and 2 with all 0’s at the start, all 1’s in the middle, and all 2’s in the end. The Space Complexity…
Merge overlapping intervals in Go (Golang)
Overview Given an array of intervals where each interval has a start time and end time, merge the overlapping intervals. Two intervals are said to be overlapping if the end time of…