Algorithm for finding if sum of sub array elements can make a desired sum -
i trying implement algorithm tell if the desired sum can make out given array elements.
i have came program
def check_payment(arr, requested_money): arr.sort() arr.reverse() sum = 0 item in arr: sum += item if sum == requested_money: return true elif sum > requested_money: sum -= item return false
i dont know getting wrong. test cases failing. can please provide me scenario fail.
scenario - code fails
run code array:-
[10,16,25] - original array arr arr.sort() - [10,16,25] arr.reverse() - [25,16,10]
now apply loop , search requested_money 26
hope helps you.
Comments
Post a Comment