Skip to main content

Command Palette

Search for a command to run...

Subsets

Published
1 min read
Subsets
G

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 {
    // Method to generate all possible subsets of a given set of integers
    public List<List<Integer>> subsets(int[] nums) {
        // Initialize the result list to store all subsets
        List<List<Integer>> resultList = new ArrayList<>();
        // Initialize a temporary list to store the current subset
        List<Integer> tempList = new ArrayList<>();

        // Call the backtrack method to generate subsets
        backTrack(resultList, tempList, nums, 0);
        // Return the list of all subsets
        return resultList;
    }

    // Helper method to perform backtracking to generate subsets
    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 over the elements starting from 'start' to the end of the array
        for(int i = start; i < nums.length; i++) {
            // Include nums[i] in the current subset
            tempSet.add(nums[i]);
            // Recursively generate subsets including the current element
            backTrack(resultList, tempSet, nums, i + 1);
            // Remove the last element to backtrack and generate other subsets
            tempSet.remove(tempSet.size() - 1);
        }
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.