Graph

Graph Undirected Unweighted Graph Graph Representation & usageAdjecancy List map[int][]edgeAdvantagesDisadvantagesAdjecancy Matrix[][]int{}AdvantagesDisadvantagesConclusionGraph using Adjacency ListGolang SolutionOutputBFS + Disconnected ComponentsBFS Important LogicFull CodeOutputDFS (Depth First Search Traversal)DFS Important LogicFull CodeOutputALL PATH from…

Maximum Product Subarray

LeetCode#152 Maximum Product SubarrayProblem StatementLogic / TrickGolang Solution 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…

Best Time to Buy and Sell Stock

LeetCode#121. Best Time to Buy and Sell Stock Problem StatementGolang SolutionTime ComplexitySpace Complexity Problem Statement You are given an array prices where prices[i] is the price of a given stock on the ith day. You want…

Increasing Triplet Subsequence

LeetCode#334. Increasing Triplet SubsequenceProblem StatementExample 1Example 2Example 3ConstraintsFollow upGolang Solution Increasing Triplet SubsequenceExplanationTime ComplexitySpace Complexity Increasing Triplet Subsequence Problem Statement Given an integer array nums, return true if there exists a triple of…

Stack using Array

Stack using ArrayGolang code for Stack using ArrayVariations of usage of type structWhen to Use Value Receiver (Pass-by-Value)When to Use Pointer Receiver (Pass-by-Pointer)General GuidelinesPass-by-value (value receiver)Pass-by-pointer (pointer receiver)Example: When to…

Missing Number

Leetcode#268 Problem StatementExample 1Example 2Example 3ConstraintsGolang Solution 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…

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,…

Trapping Rain Water

Leetcode#42 Problem StatementTrapping Rain Water LogicO(n) Solution With Extra spaceGolang solution for Trapping Rain WaterUpdated VersionO(n) solution WITHOUT Extra spaceVersion-1Version-2Key Explanations Problem Statement Given n non-negative integers representing an elevation map where…

Rotate Array

Problem StatementExample 1Example 2ConstraintsSolutionUsing an Auxiliary Array (O(n) Extra Space)StepsGolang Code Rotate ArrayCyclic Replacements (O(1) Extra Space)StepsOptimised Golang Code for Rotate ArrayFollow upIn-Place Reversal Algorithm (O(1) Extra Space)StepsSummary Problem Statement…