Subsets

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given an integer array nums of unique elements, return all possible subsets(the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
LeetCode Problem - 78
class Solution {
public List<List<Integer>> subsets(int[] nums) {
// Initialize a list to store all subsets.
List<List<Integer>> resultList = new ArrayList<>();
// Initialize a temporary list to store subsets during backtracking.
List<Integer> tempList = new ArrayList<>();
// Perform backtracking to generate subsets.
backTrack(resultList, tempList, nums, 0);
// Return the list of subsets.
return resultList;
}
// This method performs backtracking to generate subsets recursively.
public void backTrack(List<List<Integer>> resultList, List<Integer> tempSet, int[] nums, int start){
// Add the current subset to the result list.
resultList.add(new ArrayList<>(tempSet));
// Iterate through the remaining elements in the array.
for(int i=start; i<nums.length; i++){
// Include the current element in the subset.
tempSet.add(nums[i]);
// Recursively call backTrack to generate subsets with the current element included.
backTrack(resultList, tempSet, nums, i+1);
// Remove the current element from the subset to backtrack and try other possibilities.
tempSet.remove(tempSet.size()-1);
}
}
}




