Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Created May 12, 2020 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/5c2744aa9d50bc46bc622967d32e8f13 to your computer and use it in GitHub Desktop.
Save McLarenCollege/5c2744aa9d50bc46bc622967d32e8f13 to your computer and use it in GitHub Desktop.

The Connell Sequence

Allowed Time: 55 minutes

The Connell sequence can be represented as a growing series of alternating numbered lines:

If the line number is odd, the line contains a quantity of odd numbers equal to the line number, sorted ascendingly. If the line number is even, the line contains a quantity of even numbers equal to the line number, sorted ascendingly. Every number in a line is equal to its next term less 2, and the last number (and highest) number of the sequence has to be the square of the line number. Numbers have to be unique: there are no duplicates in the sequence, and not every number is in the sequence.

Line 1 = 1 // 1 odd number

Line 2 = 2, 4 // 2 even numbers

Line 3 = 5, 7, 9 // 3 odd numbers // Notice how the number 3 is missing. // Highest number in line is 9 (the square of line number)

Line 4 = 10, 12, 14, 16 // 4 even numbers and so on...

Given a start and an end being the initial and ending line of the sequence, you have to implement a function that returns the index of the given n, in a generated array containing the portion of the Connell sequence. If n is not in the array, you have to return a string "Not Found".

Think of this as a real interview problem, write clean code, proper variable and method names. And efficient algorithm.

Examples

connellSequence(1, 3, 4) // 2
// sequence = [1, 2, 4, 5, 7, 9]
// Number 4 is at index 2

connellSequence(2, 3, 4) // 1
// sequence = [2, 4, 5, 7, 9]
// Number 4 is at index 1

connellSequence(4, 5, 22) // "Not Found"
// sequence = [10, 12, 14, 16, 17, 19, 21, 23, 25]
// Number 22 is not in the sequence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment