Skip to content

Instantly share code, notes, and snippets.

@jboursiquot
Created February 6, 2019 01:00
Show Gist options
  • Select an option

  • Save jboursiquot/a66237985bf7a30eae378cb17f17f953 to your computer and use it in GitHub Desktop.

Select an option

Save jboursiquot/a66237985bf7a30eae378cb17f17f953 to your computer and use it in GitHub Desktop.

Find the common elements given two sorted lists

Write a function that returns a list of common elements between two sorted lists.

Example:

commonElements([]int{1, 2, 3}, []int{2, 3, 4}) // should return []int{2, 3}

Problem Set

[]int{1, 3, 4, 6, 7, 9}
[]int{1, 2, 4, 5, 9, 10}
// should return []int{1, 4, 9}

[]int{1, 2, 9, 10, 11, 12}
[]int{0, 1, 2, 3, 4, 5, 8, 9, 10, 12, 14, 15}
// should return []int{1, 2, 9, 10, 12}

[]int{0, 1, 2, 3, 4, 5}
[]int{6, 7, 8, 9, 10, 11}
// should return nil

Questions

What is the time complexity of your solution and why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment