21. Optimal Binary Search Tree
Required Input:
34 8 50
Expected Output:
142
Code In Python
def optimal_bst(freq):
# Write your logic here
pass
# Predefined input
freq = [34, 8, 50]
print(optimal_bst(freq))
Run Code?
Click Run Button to view compiled output
22. Painting Houses
Required Input:
17 2 17
16 16 5
14 3 19
Expected Output:
10
Code In Python
def min_paint_cost(costs):
# Write your logic here
pass
costs = [
[17, 2, 17],
[16, 16, 5],
[14, 3, 19]
]
print(min_paint_cost(costs))
Run Code?
Click Run Button to view compiled output
23. Max Product Subarray
Required Input:
2 3 -2 4
Expected Output:
6
Code In Python
def max_product(nums):
# Write your logic here
pass
nums = [2, 3, -2, 4]
print(max_product(nums))
Run Code?
Click Run Button to view compiled output
24. Boolean Parenthesization
Required Input:
T|F&TExpected Output:
2
Code In Python
def count_true(expr):
# Write your logic here
pass
expr = "T|F&T"
print(count_true(expr))
Run Code?
Click Run Button to view compiled output
25. Matrix Chain Multiplication
Required Input:
1 2 3 4Expected Output:
18
Code In Python
def matrix_chain(arr):
# Write your logic here
pass
arr = [1, 2, 3, 4]
print(matrix_chain(arr))
Run Code?
Click Run Button to view compiled output
26. Count Palindromic Subsequences
Required Input:
aaaExpected Output:
7
Code In Python
def count_palindromic_subsequences(s):
# Write your logic here
pass
s = "aaa"
print(count_palindromic_subsequences(s))
Run Code?
Click Run Button to view compiled output
27. Target Sum Ways
Required Input:
1 1 1 1 1
3
Expected Output:
5
Code In Python
def target_sum_ways(nums, target):
# Write your logic here
pass
nums = [1, 1, 1, 1, 1]
target = 3
print(target_sum_ways(nums, target))
Run Code?
Click Run Button to view compiled output
28. Min Deletions for Palindrome
Required Input:
aebcbda
Expected Output:
2
Code In Python
def min_deletions_palindrome(s):
# Write your logic here
pass
s = "aebcbda"
print(min_deletions_palindrome(s))
Run Code?
Click Run Button to view compiled output
29. Subset Sum Equals K
Required Input:
3 34 4 12 5 2
9
Expected Output:
True
Code In Python
def subset_sum_k(nums, k):
# Write your logic here
pass
nums = [3, 34, 4, 12, 5, 2]
k = 9
print(subset_sum_k(nums, k))
Run Code?
Click Run Button to view compiled output
30. Count Subsets with Sum
Required Input:
1 2 3 3
6
Expected Output:
3
Code In Python
def count_subsets_sum(nums, target):
# Write your logic here
pass
nums = [1, 2, 3, 3]
target = 6
print(count_subsets_sum(nums, target))
Run Code?
Click Run Button to view compiled output


