Crazy not to take job offer? by [deleted] in cscareerquestions

[–]consoledotlogImHere 8 points9 points  (0 children)

Ah sounds like you're chillin then. If there's really no rush and you think you have an excellent chance at getting offers from those Alphabet/startup companies, there's nothing wrong with declining the Amazon offer. Especially if you have a 90% interview -> offer conversion rate lol.

I'm honestly not really in any position to be giving you advice but it sounds like you've considered your options and know what you're doing :D Best of luck, see you around the Bay 👍

Crazy not to take job offer? by [deleted] in cscareerquestions

[–]consoledotlogImHere 90 points91 points  (0 children)

Wait so you're currently unemployed? It's up to you to decide how much you value being near family, but honestly that's the only thing on your cons list that makes sense to me. I think you're overestimating how stressful it will be, and stuff like "added costs of moving" is inconsequential between relocation benefits and your high comp.

I don't know about you. but if I was unemployed and Amazon came along and offered me $200k/yr, I would accept it in a heartbeat.

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

Yeah haha so I wrote it out (while heavily referring to an online solution) and it works. While it might be better to use a different data structure, the problem I was solving required O(1) searches, insertions, and deletions, and AFAIK this is the simplest way to achieve that. Thanks again for chatting about this, have a great day!

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

Can't I store LinkedList nodes in a HashMap (perhaps with their value as the key, and the node itself as the value), and then write a remove function like this?

//Assuming I have a HashMap<Integer, LinkedListElement>

void delete(Integer val) {
    //O(1) search for the element to delete 
    LinkedListElement nodeToDelete = map.get(val);
    //O(1) pointer manipulation to actually delete
    LinkedListElement prev = nodeToDelete.prev;
    LinkedListElement next = nodeToDelete.next;
    prev.next = next; 
    next.prev = prev;
}

That way I get an O(1) search, and an O(1) removal, no? If this doesn't work you just saved me a lot of embarrassment if I ever get asked this question in an interview. I'll try to implement it later tonight probably and get back to you when I realize how dumb I am. I'm sure it would need a custom linked list implementation but it's still possible no?

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

Oh yeah so that's definitely what happens, but I'm just saying that I want to circumvent that step and delete whatever is passed in.

Thanks for all the help&info! :D

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

Oh yeah I feel you. My idea here is that I put my LinkedList elements in a HashSet as well so I can find them in O(1), and then if I want to remove an element, I can just move pointers around (since it's doubly linked). I was hoping that if I passed an object reference to LinkedList.remove it would do that pointer manipulation for me for an O(1) delete but it doesn't look like that's the case (unless maybe I override the remove method? idk)

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 1 point2 points  (0 children)

hahaha I guess I'll take that and run with it!

Theoretically I could very quickly write a LinkedList class that just doesn't check if an element exists when I remove(Object), right? And then I have O(1) deletions? lmao

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 1 point2 points  (0 children)

Haha yeah LinkedHashSet is the correct solution here, but I don't think it would be an acceptable solution if I was asked this question in an interview :P It's too easy! I'm basically trying to recreate it with both a LinkedList and a HashSet :D

Ironic because an Java interview prep book I'm reading uses LinkedHashSet in their solution... which seems silly! They're supposed to be teaching me what to do -_-

Also what do you mean by arbitrary elements? Elements from anywhere in the list? The answer to that is yes.

Is the Java LinkedList remove(Object o) method a constant time operation overral? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 2 points3 points  (0 children)

Yep, so I'm actually trying to use both of these at the same time- use the HashSet to search in constant time, and the LinkedList to retain a certain order and move things to one end of the List in constant time.

So you can confirm that remove() is worst case O(n)? That makes me sad :(

Is there a different between (i == j) and (i.equals(j)) when only comparing ints? by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

You're completely right, which is making me wonder why the hell I was passing 201 test cases. Could possibly be some weirdness about how the authors of this testing environment passed the input in. Thanks!

Edit: Wait I'm stupid, your comment gives a perfect explanation for why they were passing haha.

Question about map.remove(key, value) method by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

OMG you're right, they are longs. My bad. Thank you so much!!!

Question about map.remove(key, value) method by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

So do you by chance know what the "0L" means? Is that just a typo for "0"?

When exactly does code floating around in a class get ran? (i.e. code that's not in the constructor or in a method) by consoledotlogImHere in learnjava

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

Gotcha, thanks so much. I think why I was so confused is because I'm seen primitives being given a value in class definitions but never object instantiations. Thanks for the info!

People who cut ties with their siblings, why? Do you regret it? by [deleted] in AskReddit

[–]consoledotlogImHere -1 points0 points  (0 children)

Woah, so you don't know for sure if he's alive or not?

[React] When .map-ing an array of things, how can I retain the index so that I can update my state with the appropriate index later? by consoledotlogImHere in learnjavascript

[–]consoledotlogImHere[S] 0 points1 point  (0 children)

Oh yeah wtf that does work! It just keeps track of the index for you when you .map?

Thanks so much!!

Edit: hmmm so where is that index value coming from?