<file_sep>def partition(nums, k):
    """
    Given an integer array nums and an integer k, return true if it is possible
    to divide this array into k non-empty subsets whose sums are all equal.
    >>> partition([4,3,2,3,5,2,1], 4)
    True
    >>> partition([1,2,3,4], 3)
    False
    """
    pass
<file_sep>def crackingTheSafe(n, k):
    """
    There is a box protected by a password. The password is a sequence of n digits where each digit can be 
    one of the first k digits 0, 1, ..., k-1. While entering a password, the last n digits entered will 
    automatically be matched against the correct password. For example, assuming the correct password is 
    "345", if you type "<PASSWORD>", the box will open because the correct password matches the suffix of the 
    entered password. Return any password of minimum length that is guaranteed to open the box at some point 
    of entering it.
    >>> crackingTheSafe(1, 2):
    10
    """
    pass

<file_sep>def replaceSpace(string):
    """
    Replace a space in a string with "%20.
    >>> replaceSpace("A B")
    'A%20B'
    """
    return string.replace(" ", "%20")
<file_sep>def firstCharacterOnlyOnce(string):
    """
    Find the first character in a string that appears only once and return its
    position. Strings contain only ASCII code characters.
    >>> firstCharacterOnlyOnce("abacc")
    'b'
    """
    from collections import Counter
    dic = Counter(string)
    for d in dic:
        if dic[d] == 1:
            return d
    return -1
<file_sep>def repeatedNumbers(list):
    """
    All numbers in an array of n lengths are in the range of 0 to n-1. Some
    numbers in the array are duplicates, but it is not known how many numbers
    are duplicates, or how many times each number is repeated. Find any
    duplicate number in the array.
    >>> repeatedNumbers([2,3,1,0,2,5])
    2
    """
    for i in range(len(list)):
        while list[i] != i:
            if list[i] == list[list[i]]:
                return list[i]
            swap(list, i, list[i])
        swap(list, i, list[i])
    return -1


def swap(list, i, j):
    temp = list[i]
    list[i] = list[j]
    list[j] = temp
<file_sep>def printClockwise(matrix):
    """
    Print the value of the matrix from outside to inside in a clockwise
    direction.
    >>> A = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
    >>> printClockwise(A)
    '1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10'
    """
    strings = []
    r1, r2, c1, c2 = 0, len(matrix) - 1, 0, len(matrix[0]) - 1
    while r1 <= r2 and c1 <= c2:
        for i in range(c1, c2+1):
            strings.append(matrix[r1][i])
        for i in range(r1+1, r2+1):
            strings.append(matrix[i][c2])
        if r1 != r2:
            for i in range(c2-1, c1-1, -1):
                strings.append(matrix[r2][i])
        if c1 != c2:
            for i in range(r2-1, r1, -1):
                strings.append(matrix[i][c1])
        r1, r2, c1, c2 = r1 + 1, r2 - 1, c1 + 1, c2 - 1
    return ", ".join([str(s) for s in strings])
<file_sep>def twoSum(nums: list, target: int):
    """
    Given an array of integers nums and an integer target, return indices of
    the two numbers such that they add up to target.You may assume that each
    input would have exactly one solution,and you may not use the same element
    twice. You can return the answer in any order.

    >>> twoSum([3, 2, 1, 4], 6)
    [1, 3]
    """
    dic = {i: target - nums[i] for i in range(len(nums))}
    for i in dic:
        if dic[i] in nums and nums.index(dic[i]) != i:
            return [i, nums.index(dic[i])]

    """
    for i in range(len(nums)):
            diff = target - nums[i]
            if diff in nums:
                if nums.index(diff) != i:
                    return [i, nums.index(target - nums[i])]
    """
<file_sep>def lookup(matrix, num):
    """
    Given a two-dimensional array, each row is sorted incrementally from left
    to right, and from top to bottom is also incremental. Given a number,
    determine whether the number is in the two-dimensional array.
    >>> A = [[1, 4, 7, 11, 15],[2, 5, 8, 12, 19],[3, 6, 9, 16, 22]]
    >>> lookup(A, 5)
    True
    >>> lookup(A, 20)
    False
    """
    if matrix is None or len(matrix) == 0 or len(matrix[0]) == 0:
        return False
    rows, cols = len(matrix), len(matrix[0])
    r, c = 0, cols - 1
    while r <= rows - 1 and c >= 0:
        if num == matrix[r][c]:
            return True
        elif num > matrix[r][c]:
            r += 1
        else:
            c -= 1
    return False
<file_sep># leetcode

run scripts using command
> python -m doctest file.py -v


## things to consider

* this does not work
  ```python
  >>> A = [2,3,1,0,2,5]
  >>> A[0], A[A[0]] = A[A[0]], A[0]  #error
  >>> A
  [1, 2, 1, 0, 2, 5]
  >>> A[0], A[1] = A[1], A[0] #This works
  ```
