105 karma · joined Jul 8, 2018 (8y ago) · 42 submissions
comment 8y ago · link · parent
comment 8y ago · link · parent
I'm very interested in this divide between people who are for white board interviews and against it and how it correlates with job performance and content. I may make a separate post about it because I'd like to get to the bottom of it.
comment 8y ago · link · parent
class Solution: def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float """
length = len(nums1) + len(nums2)
medianIndex = length // 2
ptr1 = 0
ptr2 = 0
curr = 0
flag = 0
if nums1[ptr1] < nums2[ptr2]:
val = nums1[ptr1]
else:
val = nums2[ptr2]
while curr < medianIndex:
if nums1[ptr1] == val:
if nums2[ptr2] < val:
curr += 1
ptr1 +=1
val = nums1[ptr1]
flag = 0
else:
if ptr1+1 < len(nums1) and abs(nums1[ptr1+1]) - abs(val) < abs(nums2[ptr2]) - abs(val):
curr+=1
ptr1+=1
val = nums1[ptr1]
flag = 0
else:
curr+=1
val = nums2[ptr2]
flag = 1
else:
if nums1[ptr1] < val:
curr += 1
ptr2 +=1
val = nums2[ptr2]
flag = 1
else:
if ptr2+1 < len(nums2) and abs(nums2[ptr2+1]) - abs(val) < abs(nums1[ptr1]) - abs(val):
curr+=1
ptr2+=1
val = nums2[ptr2]
flag = 1
else:
curr+=1
val = nums1[ptr1]
flag = 0
if flag == 1:
med = nums2[ptr2]
else:
med = nums1[ptr2]
if length % 2 == 0:
if med - nums1[ptr1 + 1] < med - nums2[ptr2 +1]:
return (med + nums1[ptr1+1])/2
else:
return (med + nums2[ptr2+1])/2
else:
return med
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 = ""
for c in s:
curr += c
if curr != curr[::-1]:
if len(curr[:len(curr)-1]) >= len(big):
big = curr[:len(curr)-1]
print(big)
while curr != curr[::-1]:
curr = curr[1:]
if len(curr) > len(big):
return curr
else:
return 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
i = 0
j = 0
while i < len(s):
if j >= len(p) and p[len(p) - 1] != '*':
return False
if p[j] == '*':
while j < len(p) and p[j] == '*':
j+=1
if j == len(p):
break
elif p[j] == '?':
x = len(p)- j
while len(s) - i > x:
i+=1
while j < len(p) and p[j] == '?':
i+=1
j+=1
if i > len(s) or j >= len(p) and i < len(s):
print(i)
return False
if i == len(s) and j == len(p):
break
else:
while i < len(s) and p[j] != s[i]:
i+=1
if i == len(s):
return False
elif p[j] == '?':
i+=1
j+=1
else:
if p[j] != s[i]:
print(i, s[i])
print(j, p[j])
return False
i+=1
j+=1
if j < len(p):
while j < len(p) and p[j] =='*':
j+=1
if j == len(p) and p[j-1] == '*':
return True
else:
return False
return Truecomment 8y ago · link · parent
comment 8y ago · link · parent
I wrote a comment that I realize should have been part of the original post on hindsight. It may give you more content if you choose to respond.
comment 8y ago · link · parent
I do have depression. Pretty bad one actually. I am just graduating from college at 31 because of the toll depression took on my life. I have no previous work experience because I spent my 20s just being depressed doing nothing basically. I've talked to therapists for years now and it's helped, but I've basically gone as far as that can go. My therapist and I both agree that basically as much as can be done from me through a psych has been done. My life needs to improve. Programming was supposed to be my ticket to a better life.
Some people have mentioned I should move home- My home environment is extremely toxic. I’ve cut off my mother completely because she has a severe, much worse mental illness and I only talk to my dad when I need something because he has quite the temper. I managed to get out of the house only because I’m on disability for my depression. To make things worse, my dad is past retirement age. Every single day I’m not making money forces my dad to prolong his retirement as he is the only one in the family with the mental faculties to maintain a job. It should be easy to imagine how this makes him more irritable and angry while also making me feel incredibly guilty and parasitic. This fragile economic state + my age is why I don't really have time to take it easy. I was supposed to be making money yesterday.
I’ve been preparing for technical interviews for over a year in reality, but intensely in the last month or 2. I couldn’t do Fibonacci recursively up until a few months ago until I looked it up and studied how the recursion was working. This is just one example. There are so many very basic things I can’t do.
Finally, I can’t depend on a network or friends in any form because I have none. I am a complete pariah in the computer science community I come from and every other community I’ve ever tried to integrate myself into, basically. No one will ever refer me to any job because no one likes me and, in the case of programming, everyone knows I suck.
15.
Ask HN: Got a CS degree, but I’m unable to be programmer. What can I do?
294 points · by Tmp1234 · 8y ago · 315 comments
comment 8y ago · link · parent
>>Personally, I can assure you that it isn't a matter of disliking you. Honestly, if I didn't like you, I wouldn't have posted here at all. I like you and want to help you, just not under the terms that you outlined.
Well, my problem is not being able to determine if I should quit trying to become a programmer specifically because of lack of ability. If you can help me make that decision I welcome it. Probably would make more sense if we PMed about this though.
>>As for the part about the correlation between the role of IQ and satisfaction as a software engineer, I might be hearing you wrong. I think that you're saying that repetitively debating the same subject annoys you. Am I right, or are you saying that you find the particular topic of IQ annoying?
Both are true. I don't like repeat debates that go no where nor do I like the primarily ideologically based stances people have on IQ and natural ability in general.
What I was asking was in relation to you saying- "if having a discussion about IQ's value in software development is that annoying to you, I worry that this field would make you profoundly unhappy." So I don't know why I would be unhappy as a developer because I wouldn't want to argue with people about IQ. It almost seems like you're saying arguing about IQ is a necessary part of the job and one that must be enjoyable in order to find satisfaction as a programmer.
comment 8y ago · link · parent
The questions are just to cast the largest net. Anything someone doesn't want to answer they won't just as no one has responded to the question. I assumed anyone who posted on my thread would share the minimal information. It's not like I have a gun to anyone's head.
I'd view the random stranger thing differently because there's no way anonymous. Here, there is. Plus, a person in your face tends to make people react with more of a sense of obligation than text.
comment 8y ago · link · parent
As for the length and quantity of the questions, I was just trying to help people think through their responses and specify what I'm interested in learning. The "please don't post if..." part is because whenever I've mentioned IQ in this context there's a huge backlash and every rushes to talk about how it's not important. I wanted to avoid that, but I can see how it rubs people the wrong way.
In the end, this seems a lot more like evoking dislike rather than distrust. The two don't correlate in my brain. I've met many charming people who were not trustworthy and plenty of off putting people who are highly moral. Maybe, I'm really not getting something though.
comment 8y ago · link · parent
I'm open to whatever advice you have to offer even if it comes along with "battering." I would posit though, and correct me if I'm wrong, that what maybe you don't like what I've said rather than you not trusting me? I can see how the sort of bluntness I used can be off putting to some and how the nature of the questions are inherently personal and thus uncomfortable, but I struggle to see how anything I wrote makes me seem malicious or untrustworthy. I know people tend to distrust what they dislike and trust what they like which is a huge fallacy, but a heuristic many people feel comfortable acting on or, perhaps, don't even notice they act on. If that's not the case here though, I'm very interested in why you feel distrust.
I don't see any correlation between enjoyment of the discussion about the role of IQ in software development and satisfaction as a software engineer. Can you explain what you mean?
comment 8y ago · link · parent
My experience has been bringing up intelligence or IQ automatically people always bring up a set of counterarguments on why it doesn't matter or shouldn't be focused on and because people sometimes say things like "I took an IQ test on X.com and got 234" cause those are not accurate. I'm trying to prevent those responses.
21.
How did you get where you are?
3 points · by Tmp1234 · 8y ago · 11 comments
22.
1 points · by Tmp1234 · 8y ago · discuss
23.
How to know if you're not smart enough to be a great programmer?
4 points · by Tmp1234 · 8y ago · 5 comments
comment 8y ago · link · parent
And the truth is I've been doing interview prep on and off for at least a year and I'm still at this stage. My goal is to be good enough to get into a Big 4. If I can't do that, I don't want to continue. Given that, do you think I should quit?
comment 8y ago · link · parent
To be concrete, yesterday I tried to solve this question: https://leetcode.com/problems/wildcard-matching/ I spent 45 minutes on the planning phase which would be the entire time I'd have for the problem in an interview. I had some pseudocode, thought through it, tried an example or two and then decided to code it up. As I did I realized a few more examples which I added in. Finally, I had some code that seemed even more correct than the code I thought was already correct. I run it and test cases fail. I spent 2.5 hours in total trying to get them all to pass without realizing the central issue of the question is what to do when you hit a * character. The necessity to try all the combinations of the string after a * doesn't not occur to me in 2.5 hours; I kept tweaking for specific cases I was failing. I ask a friend about the problem and in less than two minutes he realizes you need to try all combinations.
>>What sort of ideas and logic are you specifically having problem with?
It seems everything. Sure, some problems turn out to have an algorithm that I didn't know about it. Like the other day I was trying to do a problem that basically needed topological sort and I never really learned top sort. But then I read in the solution in CTCI that it's reasonable to derive that on one's own in a 45 minute interview so there goes that. More generally, it just seems when a problem reaches a certain level of difficulty my brain simply can't solve it. I suspect it's an intelligence thing. I just don't have a high enough IQ to get passed a certain point.
I will look at the resources you mentioned.