public int solution( int[] input ) {
      final int N = input.length;
      final BitSet counter = new BitSet( N );

      boolean isPermutation = true;
      for ( int element : input ) {
        if ( element == 0 || element > N ) {
          isPermutation = false;
          break;
        }

        final int index = element - 1;
        final boolean hasOccurred = counter.get( index );

        if ( hasOccurred ) {
          isPermutation = false;
          break;
        }
        else {
          counter.set( index );
        }
      }

      for ( int i = 0; i < N; i++ ) {
        if ( !counter.get( i ) ) {
          isPermutation = false;
          break;
        }
      }

      return isPermutation ? 1 : 0;
    }