an HCL GUVI product

11. Problem 11 - Check if Strings Are Permutations

Required Input:

"listen", "silent"

Expected Output:

True

Code In Python

def are_permutations(s1, s2): # Write your logic here pass # Prefilled input s1 = "listen" s2 = "silent" print(are_permutations(s1, s2))

Run Code?

Click Run Button to view compiled output

12. Problem 12 - Subarray with Given Sum

Required Input:

[1, 4, 20, 3, 10, 5]
33

Expected Output:

[2, 4]

Code In Python

def find_subarray_sum(nums, target): # Write your logic here pass # Prefilled input nums = [1, 4, 20, 3, 10, 5] target = 33 print(find_subarray_sum(nums, target))

Run Code?

Click Run Button to view compiled output

13. Problem 13 - Longest Substring Without Repeating Characters

Required Input:

"abcabcbb"

Expected Output:

3

Code In Python

def longest_unique_substring(s): # Write your logic here pass # Prefilled input s = "abcabcbb" print(longest_unique_substring(s))

Run Code?

Click Run Button to view compiled output

14. Problem 14 - Count Subarrays with Zero Sum

Required Input:

[6, 3, -1, -3, 4, -2, 2, 4, 6, -12, -7]

Expected Output:

5

Code In Python

def count_zero_sum_subarrays(nums): # Write your logic here pass # Prefilled input nums = [6, 3, -1, -3, 4, -2, 2, 4, 6, -12, -7] print(count_zero_sum_subarrays(nums))

Run Code?

Click Run Button to view compiled output

15. Problem 15 - Smallest Window Containing All Characters

Required Input:

"ADOBECODEBANC" 
"ABC"

Expected Output:

BANC

Code In Python

def min_window(s1, s2): # Write your logic here pass # Prefilled input s1 = "ADOBECODEBANC" s2 = "ABC" print(min_window(s1, s2))

Run Code?

Click Run Button to view compiled output

16. Problem 16 - Count Pairs with Given XOR

Required Input:

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

Expected Output:

2

Code In Python

def count_xor_pairs(nums, target): # Write your logic here pass # Prefilled input nums = [1, 2, 3, 4, 5] target = 6 print(count_xor_pairs(nums, target))

Run Code?

Click Run Button to view compiled output

17. Problem 17 - Max Length Subarray with Equal 0s and 1s

Required Input:

[0, 1, 0, 1, 1, 0, 0]

Expected Output:

6

Code In Python

def max_length_equal_zeros_ones(nums): # Write your logic here pass # Prefilled input nums = [0, 1, 0, 1, 1, 0, 0] print(max_length_equal_zeros_ones(nums))

Run Code?

Click Run Button to view compiled output

18. Problem 18 - Max Length Subarray with Sum k

Required Input:

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

Expected Output:

4

Code In Python

def max_length_subarray_sum_k(nums, k): # Write your logic here pass # Prefilled input nums = [1, -1, 5, -2, 3] k = 3 print(max_length_subarray_sum_k(nums, k))

Run Code?

Click Run Button to view compiled output

19. Problem 19 - Count Distinct Islands

Required Input:

 [1, 1, 0, 0, 0],
  [1, 1, 0, 0, 1],
  [0, 0, 0, 1, 1],
  [0, 1, 1, 1, 0]

Expected Output:

2

Code In Python

def count_distinct_islands(grid): # Write your logic here pass # Prefilled input grid = [ [1, 1, 0, 0, 0], [1, 1, 0, 0, 1], [0, 0, 0, 1, 1], [0, 1, 1, 1, 0] ] print(count_distinct_islands(grid))

Run Code?

Click Run Button to view compiled output

20. Problem 20 - O(1) Insert/Delete/GetRandom

Required Input:

Insert(1,2), Remove(1), GetRandom()

Expected Output:

2

Code In Python

import random class RandomizedSet: def __init__(self): # Write your logic here pass def insert(self, val): # Write your logic here pass def remove(self, val): # Write your logic here pass def getRandom(self): # Write your logic here pass # Prefilled input ds = RandomizedSet() ds.insert(1) ds.insert(2) ds.remove(1) print(ds.getRandom()) # Should return 2

Run Code?

Click Run Button to view compiled output

2 of 3