11. Write a function to find the longest palindromic substring in a given string

Required Input:

forgeeksskeegfor

Expected Output:

geeksskeeg

Code In Python

def longest_palindromic_substring(): s = "forgeeksskeegfor" # Your code here return

Output

Click Run Button to view compiled output

12. Write a function that computes the sum of the proper divisors of a number

Required Input:

28

Expected Output:

28

Code In Python

def sum_of_proper_divisors(): n = 28 # Your code here return

Output

Click Run Button to view compiled output

13. Write a function to generate all possible subsets (the power set) of a given set

Required Input:

{1, 2, 3}

Expected Output:

[[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]

Code In Python

def generate_power_set(): s = {1, 2, 3} # Your code here return

Output

Click Run Button to view compiled output

14. Write a function to check if a number is perfect. (A number is perfect if the sum of its proper divisors equals the number itself.)

Required Input:

28

Expected Output:

True

Code In Python

def is_perfect_number(): n = 28 # Your code here return

Output

Click Run Button to view compiled output

15. Write a function to find the longest increasing subsequence in a list of numbers

Required Input:

[10, 22, 9, 33, 21, 50, 41, 60, 80]

Expected Output:

6

Code In Python

def longest_increasing_subsequence(): lst = [10, 22, 9, 33, 21, 50, 41, 60, 80] # Your code here return

Output

Click Run Button to view compiled output

16. Write a function to generate all permutations of a string

Required Input:

abc

Expected Output:

['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

Code In Python

def generate_string_permutations(): s = "abc" # Your code here return

Output

Click Run Button to view compiled output

17. Write a function to find the smallest positive integer missing from an unsorted list of numbers

Required Input:

[3, 4, -1, 1]

Expected Output:

2

Code In Python

def smallest_missing_positive(): lst = [3, 4, -1, 1] # Your code here return

Output

Click Run Button to view compiled output

18. Write a function to find the longest common subsequence between two strings

Required Input:

abcde, "ace"

Expected Output:

ace

Code In Python

def longest_common_subsequence(): s1 = "abcde" s2 = "ace" # Your code here return

Output

Click Run Button to view compiled output

19. Write a function to find the maximum sum subarray in a list (Kadane’s Algorithm)

Required Input:

[-2, 1, -3, 4, -1, 2, 1, -5, 4]

Expected Output:

6

Code In Python

def max_sum_subarray(): lst = [-2, 1, -3, 4, -1, 2, 1, -5, 4] # Your code here return

Output

Click Run Button to view compiled output

20. Write a function to generate all combinations of k elements from a given list of n elements

Required Input:

[1, 2, 3, 4], 2

Expected Output:

[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]

Code In Python

def combinations_of_k(): lst = [1, 2, 3, 4] k = 2 # Your code here return

Output

Click Run Button to view compiled output

ad vertical

2 of 3