Avoid using global variables on InterviwBit


#1

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


#2

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


#3

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

#4

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


#5

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.