daily log 12.07.20

less than 1 minute read

MOCK REVIEW:

How do you find the missing number in a given integer array of 0 to 100?

def find_missing_number(array):
    start = 0
    end = len(array)
    
    
    while (end - start) > 2:
        midpoint = int((start+end/2)) if (len(array)%2!=0) else int(((start+end+1)/2))
        if midpoint == array[midpoint]:
            start = midpoint
            print('START', start)

        if midpoint < array[midpoint]:
            end = midpoint
            print('END', end)
            
    if end == len(array):
        return start + 1
    
    return end


# test_array = [0,1,3,4,5,6,7,8,9,10]
test_array = [0,1,2,3,4,5,6,7,8,10]
# test_array = [0,1,3,4,5]
find_missing_number(test_array)

PE #6

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

  1. sum of squares
  2. sum, squared
  3. 1-2

  4. list all the numbers
  5. add number to TOTAL
  6. square them
  7. Add squared number to TOTAL_SUM_OF_SQUARES
  8. When done, TOTAL_SUM_OF_SQUARES - TOTAL
num = 1
total = 0
total_sum_of_squares = 0
while num <= 100:
    total += num
    total_sum_of_squares += num*num
    num +=1
    
(total*total) - total_sum_of_squares