Skip to content

LuaanNguyen/go-leetcode

Repository files navigation

Daily LeetCode Solutions in Go ✏️

This repository contains my solutions to LeetCode problems in Go.

Folder Structure 🗂️

  • easy/: Easy level problems.
  • medium/: Medium level problems.
  • hard/: Hard level problems.

Unit Testing 🧪

In your root direction, run:

go test ./...

If you only want to run tests in a specific problem (e.g., ./easy/0001_two_sum), run:

go test ./easy/0001_two_sum

Clean test cache

go clean -testcache

Solutions (Continue Updating...)

Leetcode ID Title & Solution Coefficient Of Difficulty Remarks Approach
3042 Count Prefix and Suffix Pairs I Easy Array String
2185 Counting Words With a Given Prefix Easy Array String String Matching
1400 Construct K Palindrome Strings Medium HashTable String Greedy Counting
2116 Check if a Parentheses String Can Be Valid Medium Stack String Greedy
3223 Minimum Length of String After Operations Medium HashTable String Counting
2657 Find the Prefix Common Array of Two Arrays Medium HashTable Array
2429 Minimize XOR Medium Bit Manipulation
2425 Bitwise XOR of All Pairings Medium Bit Manipulation Brain Teaser
2683 Neighboring Bitwise XOR Medium Bit Manipulation Array
1368 Minimum Cost to Make at Least One Valid Path in a Grid Hard Breadth First Search Graph Heap(Priority Queue) Matrix Shortest Path Array
407 Trapping Rain Water II Hard Breadth First Search Graph Heap(Priority Queue) Matrix Shortest Path Array
2661 First Completely Painter Row or Column medium Matrix HashTable Array
2017 Grid Game medium Matrix Prefix Sum
1765 Map of Highest Peak medium Graph Breadth-First Search
1267 Count Servers that Communicate medium Counting Array
802 Find Eventual Safe States medium Depth-First Search Adjacency List
75 Sort Colors medium Three Pointers DNF Algortithm Initalize 3 pointers. Left and mid at 0, high at len(nums) - 1. Do a while loop as long as mid <= high and swap elements based on 3 conditions.
229 Sort Colors medium Counter Hashmap There can be at most 2 such elements with floor(n /3). Do a first pass to find all and eliminate all the non-qualify elements, then the second pass check how many time a each candidate appear in the original array.
167 Two Sum II - Input Array Is Sorted medium Two Pointers We know that the array is sorted in asc order. We can track the total sum of 2 pointers left and right and increase or decrease their indices accordingly in a while loop
15 3Sum medium Two Pointers Interate through the array, initialize 2 other pointers j = i + 1 and k = n - 1 and check the sum and adjust j and k accordingly. Make sure to check duplicates
3375 3Sum medium Hashmap There is no solution if a value that smaller than k. If a value is larger than k, we add it to our set and count the length of the set at the end
680 Valid Palindrome II easy Two Pointers Have a helper function which has the same structure as the main function. Use 2 pointers to check the +1 or -1 element whether they are equal or not
344 Reverse String easy Two Pointers
2843 Count Symmetric Integers easy
18 4Sum medium Two pointers Do Two Sum II and 3Sum first since 4Sum is the combination of those problems. There is an extra for loop. Make sure to check duplicates.

Workflow 🌊

  1. go.yml: This workflow runs whenver new code is pushed to main or create a pull request
  • Runs all Go tests
  • Checks code formatting with go fmt
  • Runs go vet for static analysis
  • Runs staticcheck for additional code quality checks
  1. update-stats.yml: This runs whenever you push changes to your solution directory (easy/medium/hard). It:
  • Counts the number of solutions in each level
  • Update README.md with current stats
  • Automaticall commits and pushes the changes

Statistics 📊

  • Easy: 8 solutions
  • Medium: 17 solutions
  • Hard: 2 solutions
  • Total: 27 solutions

License 🪪

MIT License
Copyright (c) 2025 Luan Nguyen