Barely made it through first year of shitty cs course

>barely made it through first year of shitty cs course
>brain is smoking trying to solve the first problem on leetcode
fuuuuuck, how can I fix my brain to stop being retarded? Is there a limitless style drug or a technique I can use? Help a retard out

Attached: 1561103736233.png (628x719, 347K)

Study and practice.

Find out how others have solved the problem. It will become either obvious once you get your brain into the rhythm or remain difficult forever because you're a brainlet.

>leetcode
practice makes perfect
learn new tricks when solving each problems

disable your internet for a week
remove all the games from your PC and other distraction
focus on one thing

Bruteforcing is stupid.
You're either born a programmer, or not.

T. Virgin Web Developer

I can only study in very small chunks, (likely due to constant stimulation from my 24/7 internet use), which might be negatively ipacting my brain.
How can I cure this without going completely internet free?

what are you struggling with, user?

you can learn from others

Is that what you tell yourself?

I just feel incredibly retarded. I need to be able to work with java by september but I can't even complete the easiest task on leetcode
(Two Sum) - Given an int array find two elements that add up to a given target

Attached: 1558033473171.jpg (680x638, 90K)

If you don't get it right away (~30 mins, since thats roughly how long you get per question at an interview) take a break from the problem and try again tomorrow. If that fails, just look at the solution posted and try to understand it (not memorize it). Then try coding it yourself.

Questions on there have a similar nature, especially ones that involve dynamic programming.

Meditate

The real question is: why are you studying CS if you're obviously not cut out for it?

Thanks friend, its late where I am so ill try again tomorrow lunch
Before or after working on solutions?

do you actually understand java and struggle with implementation or do you have an issue with java as a programming language?

>You're either born a programmer, or not.
False. Being good at anything takes a lot of work.

I found the concepts easy enough to understand in high school and generally did well in that area but never dedicated time to learning to program beyond a few hours in python. Plus the career potentially is better than other stem fields

Both, I’ve only ever programmed in python so moving to java is a bit weird to me plus I think my general lack of experience is holding me back

Which is why you will never be good at sex; it requires lots of practice!

True.

Whenever. It's like exercising but for attention. The key is to do it frequently enough for it to have an effect.

Study and practice and stop smoking weed

Pages like leetcode/codewars make me feel dumb too but for a different reason.
I can solve the problems, but my code always look uglier and more verbose than other users code.

are you able to solve the problem in python?

are you having problems with syntax? Ive never used leetcode so I dont know if they highlight syntax errors.

that strongly depends on how familiar you're with the language you're using.

function twosum (arr, target)
{
for (let i = 0; i < arr.length; i++)
{
if (arr[i] > target)
{
continue
}

for (let j = i + 1; j < arr.length; j++)
{
if (arr[i] + arr[j] === target)
{
return [arr[i], arr[j]]
}
}
}
}


roast my java script plz senpais

Attached: 1547817670767.gif (287x713, 320K)

I haven’t tried but I imagine I could solve it much faster in python
Kind of. I have the concept in my head but my unfamiliarity with java syntax makes it difficult

from itertools import permutations

def solve(lst, target):
for comb in permutations(lst,2):
if sum(comb) == target:
return comb

if __name__ == '__main__':
l = [2,7,11,15]
target = 9
print (solve(l, target))

def find(arr, s):
for v1 in arr:
for v2 in arr:
if v1 + v2 == s:
return v1, v2

what if arr has 100000 elements?

dgaf

Just solving it should be very easy.
Solving it so that it's as efficient as possible is the hard part.
Requiring rote knowledge of both algorithms and the standard library of the language.

But, leetcode doesn't care how efficient it is.

Retarted

> keep a hashmap of compliments you need to add up to the target number
> for example if the target is 18, and the first array element is 8, then store the number 10 in your compliments hashmap
> every time you see a number check if it is one of the numbers in your compliments map, if it is in then you are done.

Does that make sense? This is O(n), which is way better than the garbage posted here
If you're first year you may or may not know what a hashmap is. Also, as other people have said this shit just takes practice. I didn't even know what leetcode was my first year. I'm interning at a big tech company now. I remember feeling retarded because it took me ages to figure out how to print an arbitrary sized triangle made of asterisks for a homework assignment my first year, you will get better.

Ok nerd

how is this is it a good solution?

just to add, always write down your steps on a sheet of paper when you code, especially as a beginner. It goes a long way trust me!

It's just as slow as those other two solutions I linked, the problem with permutation is you are checking the first number against all other numbers and seeing if they add to the target, so you add the first and second number and check, then the first and third and check, then the first and third and check and so on which is just about as slow and you can get in terms of complexity, the way I posted only looks at each number once.

Yours works and it is compact, but if you answered that in an interview the interviewer would probably ask you to optimize it, but don't get me wrong coming up with something that works is far better than nothing.

How the fuck does hashmapping make the solution faster?

O(1) lookup in a hashmap ;)

I should clarify I'm assuming you knew that if you know what a hashmap is and aren't completely retarded, the reason its faster is because at each index, you are seeing if that number is in the hashmap which is O(1) right? If it isn't, you insert it into the hashmap and move on. Thus it's an O(n) operation.

The other solutions here compare the first index to every other index, then the second index to every other index and so on, which is O(n!)

in a hashmap, for example to get the number 5
you do hasmap[5] and get the value immediately . that's why its O(1)

Right, so its O(1) at each index and O(n) for the whole array.

Most people require more than a thousand years of work to be a half-competent programmer.

Cannot be the same number, retard

develop into an adult and learn discipline, accountability, and self control.

try timeboxing if you need help structuring.

all else fails, become a web developer.

like this?
function twosum (arr, target)
{
const hashmap = {}

for (let i = 0; i < arr.length; i++)
{
if (arr[i]

Attached: 1558861738547.png (355x330, 125K)

tfw not

Attached: 1563044306728.png (645x773, 43K)

like this?
function twosum (arr, target)
{
const hashmap = {}

for (let i = 0; i < arr.length; i++)
{
if (arr[i]

Attached: 1556465531767.jpg (700x700, 209K)

single pass hashmap in python 3 @ 35ms

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:

h = {}

for i in range(len(nums)):
if target - nums[i] not in h:
h[ nums[i] ] = i
else:
return [ h[ target - nums[i] ], i ]

literally wrong. you don't have to be as intelligent as the person who invented hashing (a very intelligent person with decades of experience) in order to implement one.

go into help desk with the rest of your standard deviation

I want to learn how to code. The thing is I'm a bluepilled normie who doesn't know anything. What's a good place to start? I was looking at a "boot camp" Berkeley has but I don't know if it's for beginners or not.

function twosum (arr, target) {
const set = new Set()

for (let val of arr)
if (set.has(target - val)) return [target - val, val]
else set.add(val)
}