21. Generate Balanced Binary Strings
Required Input:
n = 2Expected Output:
['1100', '1010']
Code In Python
def generate_balanced_binary(n):
# Write your logic here
pass
# Prefilled input
n = 2
print(generate_balanced_binary(n))
Run Code?
Click Run Button to view compiled output
22. Restore IP Addresses
Required Input:
s = '25525511135'Expected Output:
['255.255.11.135', '255.255.111.35']
Code In Python
def restore_ip_addresses(s):
# Write your logic here
pass
# Prefilled input
s = '25525511135'
print(restore_ip_addresses(s))
Run Code?
Click Run Button to view compiled output
23. Combinations of k Numbers
Required Input:
n = 4, k = 2Expected Output:
[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
Code In Python
def combine(n, k):
# Write your logic here
pass
# Prefilled input
n = 4
k = 2
print(combine(n, k))
Run Code?
Click Run Button to view compiled output
24. Partition Array into k Equal Sum Subsets
Required Input:
nums = [4, 3, 2, 3, 5, 2, 1], k = 4Expected Output:
True
Code In Python
def can_partition_k_subsets(nums, k):
# Write your logic here
pass
# Prefilled input
nums = [4, 3, 2, 3, 5, 2, 1]
k = 4
print(can_partition_k_subsets(nums, k))
Run Code?
Click Run Button to view compiled output
25. Distinct Character Substrings
Required Input:
s = 'abc'Expected Output:
['a', 'b', 'c', 'bc', 'ab', 'c', 'abc', 'b', 'c', 'bc', 'c']
Code In Python
def distinct_substrings(s):
# Write your logic here
pass
# Prefilled input
s = 'abc'
print(distinct_substrings(s))
Run Code?
Click Run Button to view compiled output
26. Word Search in Grid
Required Input:
board = [[...]], word = 'ABCCED'Expected Output:
True
Code In Python
def exist(board, word):
# Write your logic here
pass
# Prefilled input
board = [
['A', 'B', 'C', 'E'],
['S', 'F', 'C', 'S'],
['A', 'D', 'E', 'E']
]
word = 'ABCCED'
print(exist(board, word))
Run Code?
Click Run Button to view compiled output
27. Palindrome Partitioning
Required Input:
s = 'aab'Expected Output:
[['a', 'a', 'b'], ['aa', 'b']]
Code In Python
def partition(s):
# Write your logic here
pass
# Prefilled input
s = 'aab'
print(partition(s))
Run Code?
Click Run Button to view compiled output
28. Subsets With Duplicates
Required Input:
nums = [1, 2, 2]Expected Output:
[[], [1], [1, 2], [1, 2, 2], [2], [2, 2]]
Code In Python
def subsets_with_dup(nums):
# Write your logic here
pass
# Prefilled input
nums = [1, 2, 2]
print(subsets_with_dup(nums))
Run Code?
Click Run Button to view compiled output
29. Unique Paths in Grid
Required Input:
m = 3, n = 2Expected Output:
3
Code In Python
def unique_paths(m, n):
# Write your logic here
pass
# Prefilled input
m = 3
n = 2
print(unique_paths(m, n))
Run Code?
Click Run Button to view compiled output
30. Sudoku Solver
Required Input:
board = [[...]]Expected Output:
[
['5', '3', '4', '6', '7', '8', '9', '1', '2'],
['6', '7', '2', '1', '9', '5', '3', '4', '8'],
['1', '9', '8', '3', '4', '2', '5', '6', '7'],
['8', '5', '9', '7', '6', '1', '4', '2', '3'],
['4', '2', '6', '8', '5', '3', '7', '9', '1'],
['7', '1', '3', '9', '2', '4', '8', '5', '6'],
['9', '6', '1', '5', '3', '7', '2', '8', '4'],
['2', '8', '7', '4', '1', '9', '6', '3', '5'],
['3', '4', '5', '2', '8', '6', '1', '7', '9']
]
Code In Python
def solve_sudoku(board):
# Write your logic here
pass
# Prefilled input
board = [
['5','3','.','.','7','.','.','.','.'],
['6','.','.','1','9','5','.','.','.'],
['.','9','8','.','.','.','.','6','.'],
['8','.','.','.','6','.','.','.','3'],
['4','.','.','8','.','3','.','.','1'],
['7','.','.','.','2','.','.','.','6'],
['.','6','.','.','.','.','2','8','.'],
['.','.','.','4','1','9','.','.','5'],
['.','.','.','.','8','.','.','7','9']
]
solve_sudoku(board)
print(board)
Run Code?
Click Run Button to view compiled output


