Posts

Showing posts from October, 2018

Development Interview Questions (Python)

Dynamic Programming Check if any valid sequence is divisible by M Given an array of N integers, using ‘+’ and ‘-‘ between the elements check if there is a  way to form a sequence of numbers which evaluate to a number divisible by M  Examples:  Input : arr = {1, 2, 3, 4, 6}        M = 4 Output : True,  There is a valid sequence i. e., (1 - 2  + 3 + 4 + 6), which evaluates to 12 that  is divisible by 4    Input : arr = {1, 3, 9}        M = 2 Output : False There is no sequence which evaluates to  a number divisible by M. Answer (in Python): def check_if_any_valid_sequence_is_divisible(my_list, my_num): if len (my_list) == 0 : return print ( "False" ) elif len (my_list) == 1 : #print(my_list[0] // my_num) #print(my_list[0] % my_num) if my_list[ 0 ] == 0 : return print ( "False" ) else : if ((my_list[ 0 ] % my_num) == 0...