Or is it better to define separate method? I find that the separate method can require lots of variables to be passed in to the method, polluting the interface. To deal with that, one might need to define the variables within the class to be shared across methods. This takes extra time. However, it does show knowledge of better coding practices, mostly through usage of objects of the given language.
For instance, in python, I could do the following func within a func. This is quicker.
class Solution(object):
def searchMatrix(self, matrix, target): <...>
return bisectRow(row, start, end)
def bisectRow(self, row, start, end): <...>However, the following might show more OO knowledge:
class Solution(object):
def __init__(self, matrix, target, result) # granted, adding this won't make it used in leetcode, it's still useful in the real world.
self.matrix = []
self.target = []
def searchMatrix(self, matrix, target): <...>
return self.bisectRow(result, matrix, target, row, start, end)
def bisectRow(self, result, matrix, target, row, start, end): <...>Is one preferred over the other during an interview? Or does it not matter b/c the focus isn't about OO.