Avoid using global variables on InterviwBit


One thing that I have learnt is that never use global variables on InterviewBit…Else you might end up questioning your existence!!


Just don’t forget to clear them in your given func and your code will work fine.


You can use class-level variable, but you need to remember to clear it every time. Example:

class Solution:
    all_subsets = []  # class level variable
    def subsets(self, Set):
        # do whatever you want
        answer = all_subsets      # assign content to another variable 
        all_subsets = []          # reset the class level variable to []
        return answer


Thanks, I had already started asking my existence until I came across your answer


True brother :joy: , I was literally about to give up on Interview Bit.
I had a hunch about the issue earlier, but now I got sure when I came across this post.