Hello everyone, I recently started leetcoding seriously. I have done say around 20 or so easy problems before but I was not really prepping for interviewsa back then it was mostly to practice an algorithm or data structure. However since starting I find that I am having trouble even solving the simplest problems somtimes.(mind you I am doing easy problems). Many times it might not even be because I cannot workout an algorithm to solve a problem because when I check the discussion for that problem often times it is the same general algorithm over approach. The problem often comes from the actual code for instance this is my solution for question #141
class Solution:
def hasCycle(self, head: ListNode) -> bool:
if head is None or head.next is None:
return False
slow_ptr = head
fast_ptr = head
while fast_ptr != slow_ptr:
if not fast_ptr.next or not fast_ptr.next.next:
return False
slow_ptr = slow_ptr.next
fast_ptr = fast_ptr.next.next
return TrueThere is a possibility that the algorithm may be wrong (I am not claiming this doesn't happen its a conclusion I drew from comparing results with freinds who solved the same problems and got it right. Often our approaches are nearly identical other times very similar). Can someone please guide me on how to improve. I understand that doing more questions is the key to getting better but if someone can detail how much time they allocated to the easier problems at the very start of their preperation espiccally if they were unable to easily solve them. Do you think it is wise to spend hours on one problem that you think you understand how to solve but are getting it wrong until you get it right or do you feel is a gross misuse of time espicially for interview prep?