Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,037,301 members, 7,449,659 topics. Date: Saturday, 03 June 2023 at 07:49 PM

I Just Bombed A Technical Interview - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / I Just Bombed A Technical Interview (18928 Views)

I Just Quit ALX Programme / Pls I Am A Teen But Need A Technical Co Founder And Investor / Need A Technical Partner (web & App Developer) (2) (3) (4)

(1) (2) (3) (Reply) (Go Down)

Re: I Just Bombed A Technical Interview by Silentgroper(m): 3:05pm On Feb 23
Deicide:
The almighty Rust
Seemed like pascal..
Re: I Just Bombed A Technical Interview by Emekuss(m): 3:11pm On Feb 23
Temmylee01:
What language is this

This should be Golang
Re: I Just Bombed A Technical Interview by Dujardin(m): 3:13pm On Feb 23
Why do I feel you could get all the keys into an array and get random key, then use that to access your map? I understand it would add additional iteration, which you already made up for in the remove function.
Re: I Just Bombed A Technical Interview by li2pac1717: 3:22pm On Feb 23
I think you are overthinking it bro. I believe what the interviewer is testing here is how to deal with real life problem like this. HashMap would be fine. You can create a class Lottery and explain to them that a user have to have a unique ID. So store data of the class, such as id, name, and others. That way you can use random module to pick a random id number in the range of the id and get name from the hashmap of users using the randomly picked id. I think this will be enough.

To do extra, you can think OOP. Create two class, one for lottery and Person. So the Lottery class will inherit from person methods add, and remove user. You can then put only the random method in Lottery. I wouldn't code this in interview but just explain to them that if we have a bigger system, this is help in scaling and code maintenance.

Deicide:
grin Too much pressure that i couldn't even think straight. The question is not even that hard simple data structure question that i can't even believe i bombed it. Chai.

I was asked to implement a Lottery system. that has the following functionality.


1. add_user(string: user)
2. remove_user(string: user)
3. pick_random_winner() -> string


Yes that was how easy it was but i bombed. Immediately i saw add and remove my mind immediately went to the king of all data structure HashMap grin but boy i was wrong a vector would do just fine, the problem here is the functionality to pick_random_user and the function signature. how do you do that with a HashMap if data are stored anywhere in memory? meanwhile in Array everything stored contiguously. But i was busy thinking of speed embarassed

In as much as hash map would be good for add and removal in 0(1) time. it's bad for random access.

could use HashSet but random would still Bleep you up.

My bad implementation.


struct Lottery {
map: HashMap<i32, String>,
}

impl Lottery {
// first problem realized here, what would be the key? and i don already talk say na hash map go good for this things o chai grin

fn add_user(&mut self, string: user){
// But this would not work it doesn't work that way. it would have made sense if the function has a signature for key.
self.map.insert(user); error, where is the key ? cry
}

fn remove_user(&mut self, string: user){
//no key can't remove anything tongue
}

fn pick_random_user(&self){
// impossible!!! no key no random - even if there was a key it doesn't reorder it self unlike Vector. This might be possible in language like python grin
}
}



Now for a better implementation, that only came to my head as i was not overthinking immediately after the interview.


struct Lottery {
user: Vec<String>,
}

impl Lottery {
fn add_user(&mut self, string: user){
// we just insert
self.user.push(user);
}

fn remove_user(&mut self, string: user){
// linear search and then remove
if self.participant.contains(&participant) {
self.participant.retain(|x| x != &participant);
}
}

fn pick_random_user(&self){
let random_gen = // algorithm that generate random number
let random = random_gen % self.user.len();
self.user[random]
}
}


Anyways we move!!. Best advice? CALM DOWN! Technical interview are fun but trust 9ja network to Bleep you up.

3 Likes

Re: I Just Bombed A Technical Interview by Harnny(m): 3:24pm On Feb 23
I will still use my hashmap but use interger as the key... that value will be helpful when select a random
Re: I Just Bombed A Technical Interview by Paracetamol01: 3:31pm On Feb 23
Thanks.... but how am I supposed to understand this

1 Like

Re: I Just Bombed A Technical Interview by correctguy101(m): 3:32pm On Feb 23
satandeterrible:
Shame on you.

Chef why na na?

All he typed there seems like abracadabra to this ancestor grin grin

1 Like

Re: I Just Bombed A Technical Interview by li2pac1717: 3:34pm On Feb 23
That is my thought too. HashMap inform of JSON is widely use in the industry for user informations and other. They deal with Api a lot of time and most of the time JSON object is returned in form of HashMap. Even in big companies like Google and others.

Harnny:
I will still use my hashmap but use interger as the key... that value will be helpful when select a random
Re: I Just Bombed A Technical Interview by ShadowCracker(m): 3:37pm On Feb 23
Deicide:
grin Too much pressure that i couldn't even think straight. The question is not even that hard simple data structure question that i can't even believe i bombed it. Chai.

I was asked to implement a Lottery system. that has the following functionality.


1. add_user(string: user)
2. remove_user(string: user)
3. pick_random_winner() -> string


Yes that was how easy it was but i bombed. Immediately i saw add and remove my mind immediately went to the king of all data structure HashMap grin but boy i was wrong a vector would do just fine, the problem here is the functionality to pick_random_user and the function signature. how do you do that with a HashMap if data are stored anywhere in memory? meanwhile in Array everything stored contiguously. But i was busy thinking of speed embarassed

In as much as hash map would be good for add and removal in 0(1) time. it's bad for random access.

could use HashSet but random would still Bleep you up.

My bad implementation.


struct Lottery {
map: HashMap<i32, String>,
}

impl Lottery {
// first problem realized here, what would be the key? and i don already talk say na hash map go good for this things o chai grin

fn add_user(&mut self, string: user){
// But this would not work it doesn't work that way. it would have made sense if the function has a signature for key.
self.map.insert(user); error, where is the key ? cry
}

fn remove_user(&mut self, string: user){
//no key can't remove anything tongue
}

fn pick_random_user(&self){
// impossible!!! no key no random - even if there was a key it doesn't reorder it self unlike Vector. This might be possible in language like python grin
}
}



Now for a better implementation, that only came to my head as i was not overthinking immediately after the interview.


struct Lottery {
user: Vec<String>,
}

impl Lottery {
fn add_user(&mut self, string: user){
// we just insert
self.user.push(user);
}

fn remove_user(&mut self, string: user){
// linear search and then remove
if self.participant.contains(&participant) {
self.participant.retain(|x| x != &participant);
}
}

fn pick_random_user(&self){
let random_gen = // algorithm that generate random number
let random = random_gen % self.user.len();
self.user[random] kiss
}
}


Anyways we move!!. Best advice? CALM DOWN! Technical interview are fun but trust 9ja network to Bleep you up.
What language is this, also which book can you recommend to learn DSA.
Re: I Just Bombed A Technical Interview by Realiskit(m): 3:59pm On Feb 23
Hmm, how would this benefit you? Remember that what goes around comes around too.
[quote author=Meadew post=121162105][/quote]
Re: I Just Bombed A Technical Interview by CSTRR: 4:04pm On Feb 23
Ulunne777:
Let us pretend we understand.
Goodluck
It's for the initiated.

Initiated into programming.
Re: I Just Bombed A Technical Interview by Belkid01(m): 4:22pm On Feb 23
If I was to implement a lottery with that functionality, I would have used a linked list...
Re: I Just Bombed A Technical Interview by ThrustReverser(m): 4:48pm On Feb 23
Op which language are you coding in? undecided
Because I'm sure that exercise would be a cakewalk if implemented in python.
Meanwhile your codes don override flexwrap for nairaland cheesy

3 Likes

Re: I Just Bombed A Technical Interview by morakakin(m): 4:49pm On Feb 23
I was one of the best Java and C# programmers in Aptech back in 2003 to 2006, 1yr not practicing I forgot it all,I had to change to hardware and networking,cctv and biometrics installation. Programming needs constant practice.

1 Like

Re: I Just Bombed A Technical Interview by MT: 4:57pm On Feb 23
I dont understand the language you are using but I am not bothered about that.

What you considered a better implementation was lacking interface. You are not building a loosely coupled application this way. Where is that contract in your implementation?
Re: I Just Bombed A Technical Interview by Deicide: 5:06pm On Feb 23
li2pac1717:
I think you are overthinking it bro. I believe what the interviewer is testing here is how to deal with real life problem like this. HashMap would be fine. You can create a class Lottery and explain to them that a user have to have a unique ID. So store data of the class, such as id, name, and others. That way you can use random module to pick a random id number in the range of the id and get name from the hashmap of users using the randomly picked id. I think this will be enough.
I actually explained this to them.
Re: I Just Bombed A Technical Interview by Gohs: 5:11pm On Feb 23
Please look for this logo on your ballot papers — that is Labour Party (LP)!
Incase you don't see "LP" written on it, don't worry.

Just vote for Peter Obi grin

Nigeria must move forward by fire by force !!!

Re: I Just Bombed A Technical Interview by Deicide: 5:16pm On Feb 23
Harnny:
I will still use my hashmap but use interger as the key... that value will be helpful when select a random
except the language support auto generated int for value this solution wouldn't work.
Re: I Just Bombed A Technical Interview by Deicide: 5:21pm On Feb 23
MT:
I dont understand the language you are using but I am not bothered about that.

What you considered a better implementation was lacking interface. You are not building a loosely coupled application this way. Where is that contract in your implementation?
What do you mean.

They already gave me the structure of the code. All I just had to do was fill it up. So the functions they gave me I couldn't change it to add more parameters.
Re: I Just Bombed A Technical Interview by Deicide: 5:23pm On Feb 23
ThrustReverser:
Op which language are you coding in? undecided
Because I'm sure that exercise would be a cakewalk if implemented in python.
Meanwhile your codes don override flexwrap for nairaland cheesy
I didn't use python cause I am not conversant with oop in python.
Re: I Just Bombed A Technical Interview by Harnny(m): 5:34pm On Feb 23
Deicide:
except the language support auto generated int for value this solution wouldn't work.
It's interview , simply create a variable to hold the size of your dictionary as you add. Also, in interview, you are allowed to explain the draw back of your implementations and what you will do in ideal situation.
Re: I Just Bombed A Technical Interview by Emma1Oj(m): 5:35pm On Feb 23
satandeterrible:
Shame on you.
Someone like you don't deserve the truth or relate anything serious to.

You have a judgemental mindset.
Re: I Just Bombed A Technical Interview by SonyaSpence: 5:37pm On Feb 23
Deicide:
I didn't use python cause I am not conversant with oop in python.

For me, OOP is sweetest in python.
It is such a fluid language to code in
Re: I Just Bombed A Technical Interview by Deicide: 6:15pm On Feb 23
Harnny:

It's interview , simply create a variable to hold the size of your dictionary as you add. Also, in interview, you are allowed to explain the draw back of your implementations and what you will do in ideal situation.
I was given a prototype.
Re: I Just Bombed A Technical Interview by IamaNigerianGuy(m): 6:17pm On Feb 23
Technical interviews are tough. Don't beat yourself up, there's always another one.
Re: I Just Bombed A Technical Interview by ucheuzor1(m): 7:00pm On Feb 23
Deicide:
The almighty Rust

What is almighty about Rust. All languages has its uniqueness and technicality. So no is easy just in case you have that assumption.
Re: I Just Bombed A Technical Interview by eventainment(m): 7:02pm On Feb 23
Deicide:
grin Too much pressure that i couldn't even think straight. The question is not even that hard simple data structure question that i can't even believe i bombed it. Chai.

I was asked to implement a Lottery system. that has the following functionality.


1. add_user(string: user)
2. remove_user(string: user)
3. pick_random_winner() -> string


Yes that was how easy it was but i bombed. Immediately i saw add and remove my mind immediately went to the king of all data structure HashMap grin but boy i was wrong a vector would do just fine, the problem here is the functionality to pick_random_user and the function signature. how do you do that with a HashMap if data are stored anywhere in memory? meanwhile in Array everything stored contiguously. But i was busy thinking of speed embarassed

In as much as hash map would be good for add and removal in 0(1) time. it's bad for random access.

could use HashSet but random would still Bleep you up.

My bad implementation.


struct Lottery {
map: HashMap<i32, String>,
}

impl Lottery {
// first problem realized here, what would be the key? and i don already talk say na hash map go good for this things o chai grin

fn add_user(&mut self, string: user){
// But this would not work it doesn't work that way. it would have made sense if the function has a signature for key.
self.map.insert(user); error, where is the key ? cry
}

fn remove_user(&mut self, string: user){
//no key can't remove anything tongue
}

fn pick_random_user(&self){
// impossible!!! no key no random - even if there was a key it doesn't reorder it self unlike Vector. This might be possible in language like python grin
}
}



Now for a better implementation, that only came to my head as i was not overthinking immediately after the interview.


struct Lottery {
user: Vec<String>,
}

impl Lottery {
fn add_user(&mut self, string: user){
// we just insert
self.user.push(user);
}

fn remove_user(&mut self, string: user){
// linear search and then remove
if self.participant.contains(&participant) {
self.participant.retain(|x| x != &participant);
}
}

fn pick_random_user(&self){
let random_gen = // algorithm that generate random number
let random = random_gen % self.user.len();
self.user[random]
}
}


Anyways we move!!. Best advice? CALM DOWN! Technical interview are fun but trust 9ja network to Bleep you up.
what lang is this
Re: I Just Bombed A Technical Interview by ElijahIme1992(m): 7:08pm On Feb 23
Ishilove:

Kuku kee person. Mscheeeeeew
looool Oga no be only u o, me wey be IT person I no even know wetin be dat...
Re: I Just Bombed A Technical Interview by texazzpete(m): 8:42pm On Feb 23
Meadew:
Beloved, can any kind hearted person please assist me with little money to get drugs. Am seriously down with malaria and typhoid, and I don't have a dime on me to eat or buy medicine am running temperature please.cant die in silence please help me in any little way. May God meet you at the point of your needs, amen.
Please my name is angela oyom
067801
6041
G.TBank


Nobody should give this scammer any money

2 Likes

Re: I Just Bombed A Technical Interview by bfn1: 9:06pm On Feb 23
9jatriot:
Send them an email with your new solution, you never can tell.

Just tell them that you came up with a much simpler solution after you got off the interview. Nothing to lose here

If they do not have anyone better than you within that interview itself, rather than conduct a new one, they may call you again
OP, please take this advice.

(1) (2) (3) (Reply)

Few Questions About Aptech Computer Institute??? / Pros And Cons Of Dating A Programmer Or Just A Geek / Which Is Better : Laptop Or Desktop For Programming

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2023 Oluwaseun Osewa. All rights reserved. See How To Advertise. 132
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.