Author: prakashsinghabody@gmail.com

Interview Questions

Graph

Graph Representation & usage Choosing between map[int][]edge and [][]int{} for representing graph data in Go depends on the specific requirements of your application and the characteristics of the graph you are working with. Here’s a comparison of both approaches: Adjecancy List map[int][]edge Advantages Disadvantages Adjecancy Matrix[][]int{} Advantages Disadvantages Conclusion In many real-world applications, especially with […]

prakashsinghabody@gmail.com 
Interview Questions

Maximum Product Subarray

LeetCode#152 Maximum Product Subarray Problem Statement Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. Example 1: Input: nums = [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2: Input: nums = [-2,0,-1] Output: 0 […]

prakashsinghabody@gmail.com 
Interview Questions

Stack using Array

Stack using Array Golang code for Stack using Array Variations of usage of type struct When to Use Value Receiver (Pass-by-Value) You can and should use pass-by-value in certain cases, especially when: When to Use Pointer Receiver (Pass-by-Pointer) You should use pass-by-pointer when: You need to modify the original struct: If the method changes the […]

prakashsinghabody@gmail.com 
Interview Questions

Missing Number

Leetcode#268 Problem Statement Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1 Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the […]

prakashsinghabody@gmail.com 
Interview Questions

Dynamic Programming (DP)

Dynamic programming (DP) is a popular topic in coding interviews, especially with companies like Google. Here’s a set of 5 dynamic programming questions categorized into easy, medium, and hard levels, tailored for Go programming. 1. Fibonacci Sequence Level: EasyProblem:Write a function to calculate the nth Fibonacci number using dynamic programming. The Fibonacci sequence is defined […]

prakashsinghabody@gmail.com 
Interview Questions

Trapping Rain Water

Leetcode#42 Problem Statement Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) […]

prakashsinghabody@gmail.com 
Interview Questions

Rotate Array

Problem Statement LeetCode#189 Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1 Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2 Input: nums = [-1,-100,3,99], […]

prakashsinghabody@gmail.com 
Interview Questions

Find the Maximum Subarray Sum (Kadane’s Algorithm)

Find the Maximum Subarray Sum LeetCode#54 Given an array of integers, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example Input: [-2,1,-3,4,-1,2,1,-5,4]Output: 6Explanation: The subarray [4,-1,2,1] has the largest sum = 6. Approach Use Kadane’s algorithm, which runs in O(n) time. Golang Code Sample runs Why does the simple check […]

prakashsinghabody@gmail.com