Skip to content

Instantly share code, notes, and snippets.

@johntran
Last active February 20, 2019 03:27
Show Gist options
  • Save johntran/74e4a5b8679b6539f27121cb411e144d to your computer and use it in GitHub Desktop.
Save johntran/74e4a5b8679b6539f27121cb411e144d to your computer and use it in GitHub Desktop.

https://gist.github.com/johntran - > big2019Feb19.md

Algorithms 2019 02 19

systems

Problem Set

SumZero

Given an array of positive and negative numbers, find if there is a subarray (of size at-least one) with 0 sum and return the subarray.

Input: {4, 2, -3, 1, 6}
Output: [2, -3, 1] 
There is a subarray with zero sum from index 1 to 3.

Input: {4, 2, 0, 1, 6}
Output: [0] 
There is a subarray with zero sum from index 2 to 2.

Input: {-3, 2, 3, 1, 6}
Output: []
There is no subarray with zero sum.

Find the number of islands

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands

Input : mat[][] = {{1, 1, 0, 0, 0},
                   {0, 1, 0, 0, 1},
                   {1, 0, 0, 1, 1},
                   {0, 0, 0, 0, 0},
                   {1, 0, 1, 0, 1} 
Output : 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment