CRED | Machine Coding Round | Backend Engineer [Reject]
YOE: 2
Current role: Backend Engineer
Interviewing for : CRED Backend engineer role
Round: 1st
Round details: You will be given a problem , you will need to implement complete working code for the problem within 2 hours.
Performace will be judged on :
- Code should be completely working.
- There should be sufficient unit test cases.
- Extensibiilty of code.
- OOPS design principles.
Got interview via referral.
Hi everyone, i would like to share the question that was asked to me in cred machine codine round and would appreciate any suggestion on how to go about it.
You are given 4 registers A, B, C, D. All 4 registers have a `value` associated to them. We are given some functionalities that are need to be implemented for these registers.
1. Set(register(string), value(int)) -> set the value of input register to the new input value.
2. Inc(register(string)) - increment the register value by 1.
3. Move(register1(string), register2(string)) -> copy value of register2 to register1.
4. Dec(register(string)) -> decrement value of register by 1.
5. AddR(register1(string), register2(string), value) -> Add value of register1 and register2 and update register1 value equal to the new value.
Input command:
SET A 25
MOVE A B
Basically the question was to implement a dummy microprocessor with above functionalies.My Approach:
- I made 4 classes for all registers-> RegisterA, RegisterB, RegisterC, RegisterD.
type RegisterA struct { value int32 } func (r *RegisterA) Get() int32{ return r.value } func (r *RegisterA) Set(val int32) { r.value = val } - I had a service class which was having all of the above 4 classes as it s dependencies.
type Microprocessor struct {
register_a *registry.RegisterA
register_b *registry.RegisterB
register_c *registry.RegisterC
register_d *registry.RegisterD
}- That service class was implementing all the funcitonalities required.
- Register object was passed as ann argument to the service class functions.
- I was using factory pattern to find out the type of registery object:
func (m *Microprocessor) AddR(register string, register2 string){
req := m.findInstanceOfRegister(register)
req2 := m.findInstanceOfRegister(register2)
newVal := req.Get() + req2.Get()
req.Set(newVal)
fmt.Println(req.Get())
}
func (m *Microprocessor) findInstanceOfRegister(register string) registry.RegisterAction {
switch register {
case "A":
return m.register_a
case "B":
return m.register_b
case "C":
return m.register_c
case "D":
return m.register_d
}
return nil
}On top of all this, i used command patter for executing commands as input would be taken in the form of commands only.
And i had written the unit test cases too.
I believe that my LLD design lacks a lot of things still. But im unable to figure out how should i model Registers class . Like
- Should i be using a single register class and all the mothods should be implemented by that class only rather than a separate service class and types of registers should be instances of that class only rather than being different classes altogether.
Would really like to hear some suggestion on designing this problem from perspective extensibility and code abstraction.
Thanks!


