| I should like to see some of the problems that take you 2-5 hours to solve. Show your solution, and text about the way you tackle the problem. Perhaps you need a mentor, someone that can give you some tips about your coding abilities and what you should do to improve. If you need more than 10 minutes to sum the cubes of numbers from 1 to n in python, then I think you have a problem as a programmer. Can you point to a leetcode problem that takes you 2-5 hours to solve? Edited: Two weeks ago you submitted a similar post and in the comments you give this example: >> To give a concrete example of some of the above, just this morning I tried to code the brute force solution following problem: Give two sorted arrays return the median. I spent over an hour trying to implement the brute force solution involving linearly going through each array and couldn’t code it in Python. As a hobby programmer, my ten minutes approach: def median(a,b):
...: ab = len(a)+len(b)
...: pos = ab/2
...: ia = 0
...: ib = 0
...: for ic in range(pos):
...: if a[ia] <= b[ib]:
...: x = a[ia]
...: ia = ia + 1
...: else:
...: x = b[ib]
...: ib = ib + 1
...: if ab % 2 == 1 :
...: return x
...: else:
...: return (x + max(a[ia],b[ib]))/2
...:
But it is not correct
|
class Solution: def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float """
Here's what I wrote for your sum the cubes. Took me 1 minute. I hope I didn't misunderstand the question.def sumCubes(n): sumC = 0 for i in range(n+1): sumC += i 3 return sumC
I'll give you 2 more leetcode examples. Neither passed all test cases. The first is 2-3 hours. The latter 3. I didn't post the last submission for the latter one because I believe the one I posted is more telling of my thought process and coding ability imo so that solution is between 1 and 2 hours of work, but I wasn't able to get it in the end.
I honestly don't recall my idea here. I think it was to see if the start and end of the array had the same letter and if it didn't cut off the first and last letter and continue analyzing the array until the center is reached.
https://leetcode.com/problems/longest-palindromic-substring/...
class Solution: def longestPalindrome(self, s): """ :type s: str :rtype: str """ curr = "" big = ""
I thought there were 3 cases in this problem. You hit a character, you hit a ? or you hit . The first one meant an exact match had to be made. The second that there only had to be some character in the string to take a position (the string couldn't end if there was a ?). The last could mean 0 to n matches so there had to be a lot of checks in my mind. I also thought about what happens if there's "?" which I wrote as a case inside the "" if case. When test cases didn't work I would try and code for that test case and it kept going wrong so I eventually gave up and looked at the solution. My main flaw is that it didn't occur to me that backtracking was the way to go or a way to check all the potential combinations. I thought you just had to keep moving forward.https://leetcode.com/problems/wildcard-matching/description/
class Solution: def isMatch(self, s, p): """ :type s: str :type p: str :rtype: bool """ if len(p) == 0 and len(s) == 0: return True if len(p) == 0: return False