0% found this document useful (0 votes)
8 views4 pages

Assessment For Team Lead - Quality Testing at Emoha

The document outlines an assessment for a Team Lead position in Quality Testing at Emoha, last updated on January 27, 2025. It includes two coding tasks: one for flattening a nested array using recursion and another for finding all subsets of an array, complete with example code and outputs. Both tasks demonstrate the candidate's programming skills and understanding of data structures.

Uploaded by

yadavrajani3396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Assessment For Team Lead - Quality Testing at Emoha

The document outlines an assessment for a Team Lead position in Quality Testing at Emoha, last updated on January 27, 2025. It includes two coding tasks: one for flattening a nested array using recursion and another for finding all subsets of an array, complete with example code and outputs. Both tasks demonstrate the candidate's programming skills and understanding of data structures.

Uploaded by

yadavrajani3396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assessment for Team Lead - Quality Testing at Emoha

Last Updated: 27th Jan 2025

Q1. Write a function to flatten a nested array using a recursive approach.


The function should take an array that may contain nested arrays of
arbitrary depth as input and return a single, flattened array containing all
the elements. ​
Input: [1, [2, [3, [4]], 5], 6] ​
Output: [1, 2, 3, 4, 5, 6]​

Code:
def flatten_array(nested_array):
a = []

for item in nested_array:


if isinstance(item, list):
a.extend(flatten_array(item))

else:
a.append(item)
return a

# Test the function


input_array = [1, [2, [3, [4]], 5], 6]
print(f"The array of arbitrary depth : {input_array} ")

result = flatten_array(input_array)
print (f"The flattened array with all the element are: {result}")
Output:
The array of arbitrary depth : [1, [2, [3, [4]], 5], 6]
The flattened array with all the element are: [1, 2, 3, 4, 5, 6]

Q2. Implement a function to find all subsets of an array.​

Code:
def find_subset(array):
sets = [[]]

for element in array:


new = []

for i in sets:
new.append(i + [element])
sets = new + sets

return sets

# Testing the function


input_array = [1, 2, 3]
print(f'The array entered: {input_array}')

result = find_subset(input_array)
print(f'The subsets of the array : {result}')


Output:
The array entered: [1, 2, 3]
The subsets of the array : [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]

** Process exited - Return Code: 0 **


Press Enter to exit terminal

You might also like