Skip to content

Instantly share code, notes, and snippets.

@vndeguzman
Last active August 29, 2017 13:39
Show Gist options
  • Select an option

  • Save vndeguzman/f73c3d7f2af6fc521d8ea2643b35336f to your computer and use it in GitHub Desktop.

Select an option

Save vndeguzman/f73c3d7f2af6fc521d8ea2643b35336f to your computer and use it in GitHub Desktop.
Problem: Subset/Containment

Write an O(N) running function that returns true if:

  • Every element of string A are all elements of string B
  • Every element of string B are all elements of string A

truth condition venn diagram

Expected Output:

  • contains(‘abcd’, ‘abcd’); // true
  • contains(‘abcd’, ‘abcdd’); // true
  • contains(‘abcdd’, ‘abcd’); // true
  • contains(‘abcd’, ‘cdab’); // true
  • contains(‘abcd’, ‘jkslsd’); // false
  • contains(‘decbae’, ‘abcd’); // true
  • contains(‘ccccbaaad’, ‘accee’); // false

Guaranteed Inputs:

  • { a, ..., z, A, ..., Z }

Proposed Solution: https://repl.it/KZ3i/1

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