merge-intervals

command module
v0.0.0-...-5c2b7fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

merge-intervals

GitHub Travis (.org) Docker Pulls

Golang application accepting integer intervals and returning a sorted list of merged overlapping intervals.

Overview

The merge function in interval/interval.go accepts a list of intervals (i.e. [25,30] [2,19] [14,23] [4,8]) and will produce a sorted list with merged overlapping intervals ([2,23] [25,30]). If two intervals overlap, a combination of those two is created.

Documentation of the interval package

Time complexity: O(n log n) due to the sorting algorithm

Space complexity: O(1) as sorting is happening in place and only constant additional space is needed.

To visit source and to get more details on the algorithm, click: solution on leetcode.com

How to start?

For instructions how to run the program, have a look at the release notes

Use the Docker container or run the binary.

 docker run -it --rm schneereich/merge-intervals:latest [25,30] [2,19] [14,23] [4,8]
merge-intervals.exe [25,30] [2,19] [14,23] [4,8]

To Do

  • Use a linked list for the intervals instead of the array and slice objects. With very large lists, this should be more efficient. Caution: This seems not to be a standard in Golang.
  • Catch more input errors (e.g. bigger start then end value for one interval)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package interval provides a structure for intervals of integers and merging of overlapping intervals.
Package interval provides a structure for intervals of integers and merging of overlapping intervals.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL