longest_streak_of_adjacent_ones

package
v0.0.0-...-86b9fec Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 0 Imported by: 0

README

Longest Streak Of Adjacent Ones

Write a function that takes in a non-empty array of only 0s and 1s and returns the index of the 0 that, if replaced by a 1, would form the longest streak of adjacent 1s in the entire array.

If there are no 0s in the array, your function should return -1; if there are multiple possible answers, your function can return any of them.

Sample Input

  array = [1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1]

Sample Output

  8 // Replacing the 0 at index 8 with a 1 forms a streak of 6 adjacent 1s.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LongestStreakOfAdjacentOnes

func LongestStreakOfAdjacentOnes(array []int) int

LongestStreakOfAdjacentOnes How smart it is! O(n) time | O(1) space - where n is the length of the input array

Types

This section is empty.

Jump to

Keyboard shortcuts

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