Convert Figma logo to code with AI

hoanhan101 logoalgo

101+ coding interview problems in Go

3,537
374
3,537
1

Top Related Projects

183,979

All Algorithms implemented in Python

Minimal examples of data structures and algorithms in Python

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

🌍 针对小白的算法训练 | 包括四部分:①.大厂面经 ②.力扣图解 ③.千本开源电子书 ④.百张技术思维导图(项目花了上百小时,希望可以点 star 支持,🌹感谢~)推荐免费ChatGPT使用网站

A collection of algorithms and data structures

Quick Overview

The "algo" repository by Hoanhan101 is a collection of algorithms and data structures implemented in Go. It serves as a learning resource and reference for common computer science concepts, providing clear implementations and explanations for various algorithms and data structures.

Pros

  • Comprehensive coverage of fundamental algorithms and data structures
  • Clear, well-commented Go implementations
  • Includes explanations and complexity analysis for each algorithm
  • Organized structure with separate directories for different categories

Cons

  • Limited to Go language implementations
  • Some advanced algorithms or data structures may be missing
  • Not actively maintained (last commit over 2 years ago)
  • Lacks extensive documentation or tutorials for beginners

Code Examples

  1. Binary Search implementation:
func BinarySearch(arr []int, target int) int {
    left, right := 0, len(arr)-1

    for left <= right {
        mid := left + (right-left)/2
        if arr[mid] == target {
            return mid
        } else if arr[mid] < target {
            left = mid + 1
        } else {
            right = mid - 1
        }
    }

    return -1
}
  1. Quick Sort implementation:
func QuickSort(arr []int) []int {
    if len(arr) <= 1 {
        return arr
    }

    pivot := arr[len(arr)/2]
    left := make([]int, 0)
    right := make([]int, 0)
    equal := make([]int, 0)

    for _, num := range arr {
        if num < pivot {
            left = append(left, num)
        } else if num > pivot {
            right = append(right, num)
        } else {
            equal = append(equal, num)
        }
    }

    return append(append(QuickSort(left), equal...), QuickSort(right)...)
}
  1. Linked List implementation:
type Node struct {
    Value int
    Next  *Node
}

type LinkedList struct {
    Head *Node
}

func (l *LinkedList) Append(value int) {
    newNode := &Node{Value: value}
    if l.Head == nil {
        l.Head = newNode
        return
    }

    current := l.Head
    for current.Next != nil {
        current = current.Next
    }
    current.Next = newNode
}

Getting Started

To use the algorithms and data structures in your Go project:

  1. Clone the repository:

    git clone https://github.com/hoanhan101/algo.git
    
  2. Import the desired package in your Go file:

    import "github.com/hoanhan101/algo/search"
    
  3. Use the implemented functions:

    arr := []int{1, 3, 5, 7, 9}
    target := 5
    index := search.BinarySearch(arr, target)
    fmt.Printf("Found %d at index %d\n", target, index)
    

Competitor Comparisons

183,979

All Algorithms implemented in Python

Pros of Python

  • Larger collection of algorithms covering a wider range of topics
  • More active community with frequent contributions and updates
  • Better organization with algorithms categorized by type (e.g., sorting, searching, machine learning)

Cons of Python

  • Less focus on detailed explanations and comments within the code
  • May be overwhelming for beginners due to the large number of algorithms
  • Some implementations may prioritize completeness over simplicity

Code Comparison

algo:

def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

Python:

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    return None

Both implementations are similar, with Python using slightly different variable names and returning None instead of -1 when the item is not found.

Minimal examples of data structures and algorithms in Python

Pros of algorithms

  • Larger collection of algorithms and data structures
  • More comprehensive documentation and explanations
  • Higher number of contributors and community engagement

Cons of algorithms

  • Less focused on specific problem-solving techniques
  • May be overwhelming for beginners due to its extensive content

Code Comparison

algorithms:

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    return None

algo:

def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = left + (right - left) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

Both implementations are similar, with algorithms using more descriptive variable names and algo using a slightly different method to calculate the midpoint.

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

Pros of javascript-algorithms

  • More comprehensive coverage of algorithms and data structures
  • Includes explanations and complexity analysis for each implementation
  • Supports multiple programming languages (JavaScript, TypeScript, Python)

Cons of javascript-algorithms

  • Larger codebase, potentially more overwhelming for beginners
  • Less focus on practical applications and real-world examples
  • May require more time to navigate and understand the entire repository

Code Comparison

algo:

func BinarySearch(arr []int, target int) int {
    left, right := 0, len(arr)-1
    for left <= right {
        mid := left + (right-left)/2
        if arr[mid] == target {
            return mid
        } else if arr[mid] < target {
            left = mid + 1
        } else {
            right = mid - 1
        }
    }
    return -1
}

javascript-algorithms:

function binarySearch(array, item) {
  let start = 0;
  let end = array.length - 1;
  while (start <= end) {
    const middle = Math.floor((start + end) / 2);
    if (array[middle] === item) {
      return middle;
    }
    if (item < array[middle]) {
      end = middle - 1;
    } else {
      start = middle + 1;
    }
  }
  return -1;
}

Both implementations showcase a similar approach to binary search, with algo using Go and javascript-algorithms using JavaScript. The core logic remains consistent, demonstrating the algorithm's language-agnostic nature.

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

Pros of interactive-coding-challenges

  • More comprehensive coverage of topics, including system design and object-oriented design
  • Includes Jupyter notebooks for interactive learning and experimentation
  • Provides test cases and solutions for each challenge

Cons of interactive-coding-challenges

  • Less focused on specific algorithms and data structures
  • May be overwhelming for beginners due to its extensive content
  • Requires additional setup for Jupyter notebooks

Code Comparison

algo:

def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

interactive-coding-challenges:

class BinarySearch(object):
    def search(self, nums, target):
        left, right = 0, len(nums) - 1
        while left <= right:
            mid = (left + right) // 2
            if nums[mid] == target:
                return mid
            elif nums[mid] < target:
                left = mid + 1
            else:
                right = mid - 1
        return -1

Both repositories offer valuable resources for learning algorithms and data structures. algo focuses on implementing specific algorithms with clear explanations, while interactive-coding-challenges provides a broader range of topics and interactive learning experiences. The code comparison shows similar implementations of binary search, with interactive-coding-challenges using a class-based approach.

🌍 针对小白的算法训练 | 包括四部分:①.大厂面经 ②.力扣图解 ③.千本开源电子书 ④.百张技术思维导图(项目花了上百小时,希望可以点 star 支持,🌹感谢~)推荐免费ChatGPT使用网站

Pros of hello-algorithm

  • More comprehensive coverage of algorithms and data structures
  • Includes visual explanations and diagrams for better understanding
  • Offers content in multiple languages (Chinese and English)

Cons of hello-algorithm

  • Less focused on practical implementation and coding exercises
  • May be overwhelming for beginners due to the vast amount of content
  • Code examples are not as well-organized or consistently formatted

Code Comparison

algo:

def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

hello-algorithm:

public static int binarySearch(int[] arr, int target) {
    int left = 0, right = arr.length - 1;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (arr[mid] == target) return mid;
        if (arr[mid] < target) left = mid + 1;
        else right = mid - 1;
    }
    return -1;
}

Both repositories provide implementations of common algorithms, but algo focuses more on clean, readable code with explanations, while hello-algorithm offers a broader range of topics and visual aids. The code comparison shows similar implementations of binary search, with algo using Python and hello-algorithm using Java.

A collection of algorithms and data structures

Pros of Algorithms

  • More comprehensive coverage of algorithms and data structures
  • Includes implementations in multiple programming languages (Java, Python, C++)
  • Better documentation and explanations for each algorithm

Cons of Algorithms

  • Larger codebase may be overwhelming for beginners
  • Less focus on practical problem-solving examples
  • May require more time to navigate and understand the repository structure

Code Comparison

algo (Go):

func BinarySearch(arr []int, target int) int {
    left, right := 0, len(arr)-1
    for left <= right {
        mid := left + (right-left)/2
        if arr[mid] == target {
            return mid
        } else if arr[mid] < target {
            left = mid + 1
        } else {
            right = mid - 1
        }
    }
    return -1
}

Algorithms (Java):

public static int binarySearch(int[] arr, int target) {
    int left = 0, right = arr.length - 1;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (arr[mid] == target) return mid;
        if (arr[mid] < target) left = mid + 1;
        else right = mid - 1;
    }
    return -1;
}

Both implementations are similar in logic, but Algorithms uses Java while algo uses Go. The Algorithms repository offers implementations in multiple languages, providing more flexibility for users working with different programming environments.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

116+ Coding Interview Problems with Detailed Solutions

Build Status Go Report Card hackernews r/golang

The Ultimate Go Study Guide eBook version →

Join my mailing list to get the latest updates here →

Motivation

I am building a database of most frequently appeared coding interview problems that I think are the most valuable and productive to spend time on. For each one, I am including my thoughts of process on how to approach and solve it, adding well-documented solutions with test cases, time and space complexity analysis. My goal is to help you get good algorithms and data structures so that you can prepare better for your next coding interviews.

These resources that I am looking at are:

If you’re interested in getting updates for this, feel free to join my mailing list here →

Table of Contents

Developing

Count the number of questions:

make count

Clean up, lint source files, run tests and be ready for a push:

make ready

Test only:

make test

Test and report:

make cover

Test verbose:

make test-verbose

Lint:

make lint

Clean up:

make clean

For more information:

make help

Stargazers over time

Stargazers over time